November 2018
Intermediate to advanced
528 pages
13h 21m
English
Here, we will experiment with something interesting. As you know, in the Cplayer contract, the ability to remove players is restricted to an administrator, which is the deployer's account. The following test will check whether an exception will be raised if a different account tries to call removePlayer() :
it("..Only admin can REMOVE players", async function() { let error; await Cp.addPlayer("player1", 123, { from: secondAccount }); try { await Cp.removePlayer(secondAccount, { from: thirdAccount }); assert.fail(); } catch (error) { const msgexist = error.message.search('revert') >= 0; assert.ok(msgexist); }}As we are expecting an error, we can just use try {...} catch{} blocks to handle the exception.
The test will ...
Read now
Unlock full access