Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a TestEngine #889

Closed
6 tasks done
shargon opened this issue Feb 9, 2024 · 21 comments
Closed
6 tasks done

Create a TestEngine #889

shargon opened this issue Feb 9, 2024 · 21 comments
Assignees

Comments

@shargon
Copy link
Member

shargon commented Feb 9, 2024

We have a problem creating unit tests, I'm going to make a testEngine to facilitate the testing of smart contracts.

Doc:

Bugs found with this engine:

@shargon shargon self-assigned this Feb 9, 2024
@cschuchardt88
Copy link
Member

I will be creating an DebugApplicationEngine. After my TraceApplicationEngine. Just keep that in mind.

@shargon
Copy link
Member Author

shargon commented Feb 9, 2024

I will be creating an DebugApplicationEngine. After my TraceApplicationEngine. Just keep that in mind.

The underlying engine could be changed in a future easily in order to be more verbose.

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 10, 2024

I will be creating an DebugApplicationEngine. After my TraceApplicationEngine. Just keep that in mind.

The underlying engine could be changed in a future easily in order to be more verbose.

I already did that. Im not changing ApplicationEngine. I am however replacing it by doing ApplicationEngine.Provider = new TraceApplicationEngine());

All I am saying is, all this work you are doing can be done very easy with current code we have. It already built to handle something like this. I don't know why you reinventing the wheel again. When we have already made it.

image
image

@shargon
Copy link
Member Author

shargon commented Feb 10, 2024

I don't know why you reinventing the wheel again. When we have already made it.

I'm tired of seeing projects in neo without any unit tests, it's not easy to do them, show me a single project that has them, I think this wheel is not even being reinvented, if it is even designed.

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 10, 2024

Your misunderstanding it. I explained it incorrectly.

The TestEngine you are creating. Can be done with ease with IApplicationEngineProvider. All I am saying is build your Engine with that Interface. So you can plugin/hook into the ApplicationEngine protected or virtual methods for getting all the VMs information. I don't think I need to tell you the information you can get from ApplicationEngine. But this would be the real big test. Where you can test on mainnet or testnet without problems. I been working on TraceApplicationEngine for about a day. And was saying no one should reinvent all the functionality that ApplicationEngine has already. We have an Engine Its called ApplicationEngine. You should make TestApplicationEngine or ContractApplicationEngine. If that makes sense.

@roman-khimov
Copy link

IIUC that'd be something similar to https://pkg.go.dev/github.com/nspcc-dev/neo-go/pkg/neotest or https://neow3j.io/#/neo-n3/smart_contract_development/testing. But both have some real or almost real ledger behind, so invocations are real transactions packed into some blocks and processed in a regular way. Can you you provide more details on how DLL-packed contracts will work here?

@shargon
Copy link
Member Author

shargon commented Feb 10, 2024

IIUC that'd be something similar to https://pkg.go.dev/github.com/nspcc-dev/neo-go/pkg/neotest or https://neow3j.io/#/neo-n3/smart_contract_development/testing. But both have some real or almost real ledger behind, so invocations are real transactions packed into some blocks and processed in a regular way. Can you you provide more details on how DLL-packed contracts will work here?

The problem that we have been encountering throughout all the contracts reviewed is mainly the same, the contracts have not been tested, and the lack of unit tests.

What I am doing is the ability to generate some "artifacts" abstract class extracted from NefFile, in this way the testing is not limited to contracts made in C#, these artifacts generate a valid C# code descriptive of the Abi, and through mocks, I intend convert types between VM<>dotnet to facilitate calling and testing contracts.

The initial idea (it may evolve in a future version) is to test without generating a transaction, so if you want to simulate two transactions you would have to do something like this:

var walletA= new UInt160("a");
var walletA= new UInt160("b");
TestEngine engine=new ();

var contract = engine.Deploy<MyContract>();

engine.Signer= walletA;
contract.Mint();

engine.Signer= walletB;
Assert.IsFalse(contract.Transfer(walletA,walletB,1)); // no signed by a

engine.Signer= walletA;
Assert.IsTrue(contract.Transfer(walletA,walletB,1));

@Jim8y
Copy link
Contributor

Jim8y commented Feb 11, 2024

would be much better if you had provided a detailed introduction on what you are trying to do, and how it is supposed to work.

@cschuchardt88
Copy link
Member

would be much better if you had provided a detailed introduction on what you are trying to do, and how it is supposed to work.

@shargon Yes we need more information. So you dont waste everyone's time, including yours.

@shargon
Copy link
Member Author

shargon commented Feb 11, 2024

would be much better if you had provided a detailed introduction on what you are trying to do, and how it is supposed to work.

Got it, next time I will do that. My goal is to make it easy unit tests for any smart contract, because trust me, there's a lack of this everywhere.

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 11, 2024

would be much better if you had provided a detailed introduction on what you are trying to do, and how it is supposed to work.

Got it, next time I will do that. My goal is to make it easy unit tests for any smart contract, because trust me, there's a lack of this everywhere.

That is fine. How are we to use it? How do we build tests now? How do we setup the environment? What is required of a test? Whats the convention of the API? How are files and configuration laid out?

@shargon
Copy link
Member Author

shargon commented Feb 11, 2024

That is fine. How are we to use it? How do we build tests now? How do we setup the environment? What is required of a test? Whats the convention of the API? How are files and configuration laid out?

I will write a Readme.md explaining the new testing environment

@shargon
Copy link
Member Author

shargon commented Feb 11, 2024

https://github.com/neo-project/neo-devpack-dotnet/blob/master/src%2FNeo.SmartContract.Testing%2FREADME.md please tell me if you need more information

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 14, 2024

@shargon can you add checkpoints to your engine?

@Jim8y
Copy link
Contributor

Jim8y commented Feb 14, 2024

@shargon can you add checkpoints to your engine?

BreakPoint? VM.Tests's engine can do that. Can be added in another pr if not added.

@shargon
Copy link
Member Author

shargon commented Feb 14, 2024

@shargon can you add checkpoints to your engine?

Only snapshots now, commit and rollback, but if you consider dump the storage to a json, and load from it a checkpoint, yes, it's possible to do that

@cschuchardt88
Copy link
Member

Also can we have in binary file format? If not already.

@shargon
Copy link
Member Author

shargon commented Feb 15, 2024

Also can we have in binary file format? If not already.

Of course, it could be faster

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 16, 2024

Also can we have in binary file format? If not already.

Of course, it could be faster

I mean log file in binary format also.

@shargon
Copy link
Member Author

shargon commented Feb 24, 2024

I think that the testEngine is finished, let's move to the next step #949

@shargon shargon closed this as completed Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants