November 2018
Intermediate to advanced
528 pages
13h 21m
English
Moving on, it’s time to define our first test. We will check whether the addPlayer() function operates properly. Put the following code inside the first contract function in your test file:
it("..should ADD players", async () => { let Cp = await Cplayer.new(); for (let i = 0; i < 3; i++) { await Cp.addPlayer("player" + i, 123, { from: accounts[i] }); const P = await Cp.players.call(accounts[i]); assert.equal(P[2], accounts[i], "player not added"); } });As you can see, the test adopts Mocha's it syntax. If you’re not familiar with the Mocha framework, know that it is a function that is actually a test itself, which takes two arguments. The first is a message using natural language to describe our expectation for the test, ...
Read now
Unlock full access