Remix tutorial for moonbeam smart contract developers. Part 2

Lucas | Eaglenode
MATeS of Moonbeam
Published in
2 min readMay 24, 2022

How to test a smart contract?

In this tutorial we are talking about testing of smart contract. If you want to analyze a smart contract code jump to Part 1 article.

Create a MoonbeamWalletTest.js file

We are using mochajs framework. In first line we need to import the framework then initialize a test case. We are sending a real transaction by using a library. To do that you need to specify a RPC node which will connect to the moonbase blockchain (testnet of moonbeam).

In this scenario we want to send a DEV tokens to contract address. In other words we will test receive() function. But solidity doesn’t allow invoke a keyword directly so we have to simulate a transaction.

Tu run test click MoonbeamWalletTest.js file and Run option

In console you should see a test result. We can spot a contract address, owner address and the positive result of test.

You can go to moonbase explorer and see that 0.001 DEV tokens has been sent to the contract.

That’s it. Now you are able to test a smart contract in solidity!

--

--