From 610e148afc15c5d8d893ed8179da85c4817732a5 Mon Sep 17 00:00:00 2001 From: Tran Minh Duc Date: Wed, 3 Jun 2020 22:13:47 +0700 Subject: [PATCH] add test for missing event --- test/sol6/kyberDao.js | 11 ++++++++++- test/sol6/kyberFeeHandler.js | 8 +++++++- test/sol6/withdrawableNoModifiers.js | 16 ++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/test/sol6/kyberDao.js b/test/sol6/kyberDao.js index c4137a512..84edb01b0 100644 --- a/test/sol6/kyberDao.js +++ b/test/sol6/kyberDao.js @@ -387,9 +387,10 @@ contract('KyberDao', function(accounts) { let link = web3.utils.fromAscii("https://kyberswap.com"); await updateCurrentBlockAndTimestamp(); + let options = [1,2,3,4] let txResult = await submitNewCampaign(kyberDao, 0, currentBlock + 2, currentBlock + 2 + minCampPeriod, - minPercentageInPrecision, cInPrecision, tInPrecision, [1, 2, 3, 4], link, {from: daoOperator} + minPercentageInPrecision, cInPrecision, tInPrecision, options, link, {from: daoOperator} ); expectEvent(txResult, 'NewCampaignCreated', { campaignType: new BN(0), @@ -401,6 +402,14 @@ contract('KyberDao', function(accounts) { tInPrecision: new BN(tInPrecision), link: link }); + let eventLogs; + for (let i = 0; i < txResult.logs.length; i++) { + if (txResult.logs[i].event == 'NewCampaignCreated') { + eventLogs = txResult.logs[i]; + break; + } + } + Helper.assertEqualArray(eventLogs.args.options, options); await Helper.setNextBlockTimestamp(blockToTimestamp(currentBlock + 2)); // vote for first campaign diff --git a/test/sol6/kyberFeeHandler.js b/test/sol6/kyberFeeHandler.js index f9fdbc5fb..3e000e4db 100644 --- a/test/sol6/kyberFeeHandler.js +++ b/test/sol6/kyberFeeHandler.js @@ -468,7 +468,13 @@ contract('KyberFeeHandler', function(accounts) { it("should have updated BRR if expiryTimestamp == 2 ** 64 - 1", async() => { let maxExpiryTimestamp = new BN(2).pow(new BN(64)).sub(new BN(1)); await mockKyberDao.setMockEpochAndExpiryTimestamp(defaultEpoch, maxExpiryTimestamp); - await feeHandler.getBRR(); + let txResult = await feeHandler.getBRR(); + expectEvent(txResult, "BRRUpdated", { + rewardBps: rewardInBPS, + rebateBps: rebateInBPS, + epoch: epoch, + expiryTimestamp: maxExpiryTimestamp, + }) let result = await feeHandler.readBRRData(); Helper.assertEqual(result.expiryTimestamp, maxExpiryTimestamp, "expiry timestamp was not updated"); }); diff --git a/test/sol6/withdrawableNoModifiers.js b/test/sol6/withdrawableNoModifiers.js index 1a0fbbc2e..b17294fbf 100644 --- a/test/sol6/withdrawableNoModifiers.js +++ b/test/sol6/withdrawableNoModifiers.js @@ -14,7 +14,7 @@ let initialEtherBalance = new BN(10); let etherWithdrawAmt = new BN(3); const {zeroBN} = require("../helper.js"); -const { expectRevert } = require('@openzeppelin/test-helpers'); +const { expectRevert, expectEvent } = require('@openzeppelin/test-helpers'); contract('WithdrawableNoModifiers', function(accounts) { before("should init globals, deploy test token", async function () { @@ -37,7 +37,12 @@ contract('WithdrawableNoModifiers', function(accounts) { Helper.assertEqual(admin, rxAdmin, "wrong admin " + rxAdmin.toString()); // withdraw the tokens from withdrawableInst - await withdrawableInst.withdrawToken(token.address, tokenWithdrawAmt, user, {from: admin}); + let txResult = await withdrawableInst.withdrawToken(token.address, tokenWithdrawAmt, user, {from: admin}); + expectEvent(txResult, "TokenWithdraw", { + token: token.address, + amount: tokenWithdrawAmt, + sendTo: user, + }) balance = await token.balanceOf(withdrawableInst.address); Helper.assertEqual(balance, initialTokenBalance.sub(tokenWithdrawAmt), "unexpected balance in withdrawble contract."); @@ -76,8 +81,11 @@ contract('WithdrawableNoModifiers', function(accounts) { it("should test withdraw ether success for admin.", async function () { // withdraw the ether from withdrawableInst - await withdrawableInst.withdrawEther(etherWithdrawAmt, user, {from: admin}); - + let txResult = await withdrawableInst.withdrawEther(etherWithdrawAmt, user, {from: admin}); + expectEvent(txResult, "EtherWithdraw", { + amount: etherWithdrawAmt, + sendTo: user, + }) let balance = await Helper.getBalancePromise(withdrawableInst.address); Helper.assertEqual(balance, initialEtherBalance.sub(etherWithdrawAmt), "unexpected balance in withdrawble contract."); });