Step #2.2: Deploy EOS smart contract

Now it’s time to compile & deploy our smart contract.

Before we do that I want to move your attention to the contracts folder. You can see that inside we have three subfolders: include , rc and src .

Include

In include we keep all .hpp (header) files. For our project these are types.hpp and jupiter.hpp .

types.hpp contain all structs we’re using in our dApp.

jupiter.hpp contain all actions declarations.

Rc

In rc we keep our Ricardian contracts for each action.

Src

In src are all EOS smart contracts containing the implementation of each action. We have 3 files: jupiter.cpp , warrior.cpp and ship.cpp .

warrior.cpp and ship.cpp are the contracts containing the logic. jupiter.cpp is the master contract which combines everything in one place. This is the smart contract we’re going to deploy.

Thanks to that project architecture you’re able to develop more high-quality and CPU efficiency contracts. And you need only one EOS account = less money for dApp development and running 😎

I hope it’s a bit clear now. Let’s deploy!

Deploy

I have included the jupiter.wasm & jupiter.abi files so you don’t need to compile. We can move directly to deploying. Run the following command:

infeos deploy

If everything goes well it’s time for testing!

Step #3: Unit test EOS smart contracts with Javascript

Open the test folder. You’ll see two files: WarriorTests.js and ShipTests.js .

Ship Tests

When you open ShipTests.js you’ll see the following code:

There are a few things I want to mention here.

infeos is providing an amazing class called EOSIOTest. It contains some helper functions that will assist you during your testing process

For example, deployerAccount returns an object of type EOSIOAccount. This object is the account which deployed the master smart contract. Thanks to it you have access to its name, base permissions (owner & active), key pairs (owner & active) and even a function called getAccountData that could return the account data directly from the blockchain.

The second thing I want to mention is that you can choose how and when the smart contract will be deployed. At the moment I recommend to deploy your smart contract through deploy.js

and then in the tests to get only its instance:

EOSIOContract is an amazing class coming from infeos which can return you an instance of every deployed EOSIO smart contract.

Let’s write and explore our first test. We’ll create a new ship:

Look at line 4:

Thanks to the contract instance coming from EOSIOContract you have access to all actions from the smart contract. Isn’t that amazing! Just choose your action and pass the needed parameters. It works like magic!

Once the action is executed it’s time to check if the created ship is the expected one. With EOSIORpc you have the power behind EOSJS. We fetch the table containing all ships and we get the last record — our ship.

The next step is to assert! Here we check if the name of the ship is the same as the one we used to create it in the first place.

Run now the test with the following command:

infeos test

If the test is passing everything will be green!

Let’s move to WarriorTests.js. The structure is the same only the tests are different.

Are you a fan of Captain Marvel? Yes! Me too! Let’s create a new warrior named Carol Danvers:

Let’s create another test but this time will add a ship:

And one final test where we’re going to expect throw:

The code is the same, but take a look at:

EOSIOTest gives you a helper function called expectThrow. It takes two parameters: a function and an error message. The message will be print if addShip doesn’t throw.

Now let’s run it again

infeos test

Woohoo! All tests are passing! With infeos is so easy and fast to test your EOSIO smart contracts!

Tell me what you think in the comments and don’t forget to share. EOSIO developers can now write their unit tests in JavaScript!