0

Is there a guide on how to create your own Mock contracts in order to properly test smart contracts on local network? And how to conclude if one corresponds to the idea, and meets the requirements of the main contract?

I noticed that some Mock contracts (ERC20, MockV3Aggregator) have something in common like constructors or return statement. But how do you define if the Mock correct and will not to much be different from the original one and make test experience so much similar with the deployment process?

2 Answers 2

0

Usually you just need to provide a fake implementation to the desired methods you use/test. Your mock can be clean without mocking(implement) all of the methods you wouldn't use in your business logic.

Same OOP principles applies here.

I noticed that some Mock contracts (ERC20, MockV3Aggregator) have something in common like constructors or return statement.

yes, they seem to run some initialization code.

... will not to much be different from the original one and make test experience so much similar with the deployment process?

well it is required for them to have the same function signature as the original Contract. Also you need to have some understanding what values are expected to be returned.

There are already implemented Mocks in github, so you can use them. If not, be creative with the first paragraph I wrote.

0

You can test your smart contract by using Truffle. There is even a command [truffle test] that will run all the written tests. That way you can double-check if your contracts work.

If however, you want to test the deployment of your contracts. You can do it on your own local network, or one of the running test networks that are freely available online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.