Replies: 2 comments
-
Not sure if its relevant to ask here but since we are talking about testing, it will be good to add our thoughts on Smart Contract debugging. i.e, something like simbolik for solidity |
Beta Was this translation helpful? Give feedback.
0 replies
-
A couple of comments on this:
Agreed that this would be awesome. We do have a Also, cc @hackaugusto and @phklive. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
The smart contract developers need to test their code before deploying it to the blockchain. Often, the smart contract code cannot be fully tested in isolation, and it needs to be tested in the context of the blockchain data (other accounts, notes, etc.) and/or with the accompanying off-chain code (building transactions, analyzing notes, etc.).
Testing smart contracts in isolation (unit tests)
It's tempting to go the regular Rust unit tests route and implement the Miden stdlib, compiler intrinsics (
hmerge
, etc.) in Rust, emulating the Miden VM ops and stdlib functions semantics. However, this approach has the significant drawback - we will be testing the user's code against the Rust implementation of the Miden VM and stdlib, not the actual Miden VM and stdlib. The Rust implementation may have bugs, and the user's code may work in these tests but fail in the actual Miden VM.Instead, we should offer an ergonomic way of compiling their smart contract's crate to MASM and running them in the actual Miden VM. This way, the users can be sure that their code will work in the actual Miden VM.
I'm thinking of something like the following Rust pseudocode:
Since the compilation and loading of the Miden package into the VM are expensive operations, we should offer a way to cache them and reuse them in the user tests.
Testing smart contracts in the context of the blockchain data on off-chain code (integration tests)
Not all smart contracts can be tested in isolation. Some smart contracts depend on the blockchain data (other accounts, notes, etc.) and/or the accompanying off-chain code (building transactions, analyzing notes, etc.).
We could offer to spin a local Miden node to the developer and use it in the tests, but it sounds quite heavyweight and might be an overkill. Instead, I suggest we look into the simulation of the blockchain itself(mockchain). I've used a similar approach in the previous L1 project, and it was very popular, especially when testing or demonstrating complex scenarios like DEX orders interaction, algorithmic stablecoin bank + oracle testing, etc.
I'm still figuring out the implementation details, but the idea can be demonstrated with the following Rust pseudocode:
Under the hood, it would be
miden-base
testing framework + a simplified data store keeping accounts(state) and notes.The future direction could be to run the code above in some playground in the browser and have a shareable link to discuss it with the team members and/or the community.
Beta Was this translation helpful? Give feedback.
All reactions