From 9b2231ed246f3bbba23cc7eeae06662e82315efb Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Tue, 5 Nov 2019 14:40:19 -0800 Subject: [PATCH] Improved readability on some tests + updated staking changelog --- contracts/staking/CHANGELOG.json | 4 ++ .../test/unit_tests/mixin_scheduler_test.ts | 38 +++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/contracts/staking/CHANGELOG.json b/contracts/staking/CHANGELOG.json index 58226795f7..cd30ad7573 100644 --- a/contracts/staking/CHANGELOG.json +++ b/contracts/staking/CHANGELOG.json @@ -25,6 +25,10 @@ { "note": "Fix overflow w/ `LibFixedMath._mul(-1, -2*255)", "pr": 2311 + }, + { + "note": "Unit tests for MixinScheduler", + "pr": 2314 } ] }, diff --git a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts index 91f5af181a..9838c00c71 100644 --- a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts +++ b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts @@ -1,25 +1,21 @@ -import { blockchainTests, expect } from '@0x/contracts-test-utils'; +import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils'; import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; -import * as _ from 'lodash'; -import { artifacts, TestMixinSchedulerContract, TestMixinSchedulerGoToNextEpochTestInfoEventArgs } from '../../src'; +import { + artifacts, + TestMixinSchedulerContract, + TestMixinSchedulerEvents, + TestMixinSchedulerGoToNextEpochTestInfoEventArgs, +} from '../../src'; import { constants as stakingConstants } from '../utils/constants'; blockchainTests.resets('MixinScheduler unit tests', env => { - let accounts: string[]; - let owner: string; - let authorizedAddress: string; - let notAuthorizedAddresses: string[]; let testContract: TestMixinSchedulerContract; before(async () => { - // Create accounts - accounts = await env.getAccountAddressesAsync(); - [owner, authorizedAddress, ...notAuthorizedAddresses] = accounts; - // Deploy contracts testContract = await TestMixinSchedulerContract.deployFrom0xArtifactAsync( artifacts.TestMixinScheduler, @@ -45,7 +41,7 @@ blockchainTests.resets('MixinScheduler unit tests', env => { describe('_initMixinScheduler', () => { it('Should succeed if scheduler is not yet initialized (`currentEpochStartTimeInSeconds == 0`)', async () => { - const initCurrentEpochStartTimeInSeconds = new BigNumber(0); + const initCurrentEpochStartTimeInSeconds = constants.ZERO_AMOUNT; const txReceipt = await testContract.initMixinSchedulerTest.awaitTransactionSuccessAsync( initCurrentEpochStartTimeInSeconds, ); @@ -75,18 +71,22 @@ blockchainTests.resets('MixinScheduler unit tests', env => { it('Should succeed if epoch end time is strictly less than to block timestamp', async () => { const epochEndTimeDelta = new BigNumber(-10); const txReceipt = await testContract.goToNextEpochTest.awaitTransactionSuccessAsync(epochEndTimeDelta); - // tslint:disable-next-line no-unnecessary-type-assertion - const testLog: TestMixinSchedulerGoToNextEpochTestInfoEventArgs = (txReceipt.logs[0] as LogWithDecodedArgs< - TestMixinSchedulerGoToNextEpochTestInfoEventArgs - >).args; const currentEpoch = await testContract.currentEpoch.callAsync(); const currentEpochStartTimeInSeconds = await testContract.currentEpochStartTimeInSeconds.callAsync(); - expect(currentEpoch).to.bignumber.equal(testLog.oldEpoch.plus(1)); - expect(currentEpochStartTimeInSeconds).to.bignumber.equal(testLog.blockTimestamp); + verifyEventsFromLogs( + txReceipt.logs, + [ + { + oldEpoch: currentEpoch.minus(1), + blockTimestamp: currentEpochStartTimeInSeconds, + }, + ], + TestMixinSchedulerEvents.GoToNextEpochTestInfo, + ); }); it('Should succeed if epoch end time is equal to block timestamp', async () => { - const epochEndTimeDelta = new BigNumber(0); + const epochEndTimeDelta = constants.ZERO_AMOUNT; const txReceipt = await testContract.goToNextEpochTest.awaitTransactionSuccessAsync(epochEndTimeDelta); // tslint:disable-next-line no-unnecessary-type-assertion const testLog: TestMixinSchedulerGoToNextEpochTestInfoEventArgs = (txReceipt.logs[0] as LogWithDecodedArgs<