diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-06 23:40:03 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-02-07 09:27:47 +0800 |
commit | a264c36a48d224a55c2ef883f207692752ca74c7 (patch) | |
tree | 6ae38d36405de58c9c60d3d2164f8427110a1796 /packages/contracts/test/multi_sig_with_time_lock.ts | |
parent | 0c2ab2265624eb0dc18244b263fed3c8788b5c09 (diff) | |
download | dexon-sol-tools-a264c36a48d224a55c2ef883f207692752ca74c7.tar.gz dexon-sol-tools-a264c36a48d224a55c2ef883f207692752ca74c7.tar.zst dexon-sol-tools-a264c36a48d224a55c2ef883f207692752ca74c7.zip |
Change tests
Diffstat (limited to 'packages/contracts/test/multi_sig_with_time_lock.ts')
-rw-r--r-- | packages/contracts/test/multi_sig_with_time_lock.ts | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index bd64be1ba..6812cb09f 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -6,6 +6,8 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json'; +import { MultiSigWalletContract } from '../src/contract_wrappers/generated/multi_sig_wallet'; +import { MultiSigWalletWithTimeLockContract } from '../src/contract_wrappers/generated/multi_sig_wallet_with_time_lock'; import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { MultiSigWrapper } from '../util/multi_sig_wrapper'; @@ -30,12 +32,12 @@ describe('MultiSigWalletWithTimeLock', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owners = [accounts[0], accounts[1]]; }); - const SIGNATURES_REQUIRED = 2; - const SECONDS_TIME_LOCKED = 10000; + const SIGNATURES_REQUIRED = new BigNumber(2); + const SECONDS_TIME_LOCKED = new BigNumber(10000); - let multiSig: Web3.ContractInstance; + let multiSig: MultiSigWalletWithTimeLockContract; let multiSigWrapper: MultiSigWrapper; - let txId: number; + let txId: BigNumber; let initialSecondsTimeLocked: number; let rpc: RPC; @@ -52,20 +54,21 @@ describe('MultiSigWalletWithTimeLock', () => { describe('changeTimeLock', () => { describe('initially non-time-locked', async () => { before('deploy a walet', async () => { - multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ + const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ owners, SIGNATURES_REQUIRED, 0, ]); - multiSigWrapper = new MultiSigWrapper(multiSig); + multiSig = new MultiSigWalletWithTimeLockContract(multiSigInstance); + multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract); const secondsTimeLocked = await multiSig.secondsTimeLocked(); initialSecondsTimeLocked = secondsTimeLocked.toNumber(); }); it('should throw when not called by wallet', async () => { - return expect(multiSig.changeTimeLock(SECONDS_TIME_LOCKED, { from: owners[0] })).to.be.rejectedWith( - constants.REVERT, - ); + return expect( + multiSig.changeTimeLock.sendTransactionAsync(SECONDS_TIME_LOCKED, { from: owners[0] }), + ).to.be.rejectedWith(constants.REVERT); }); it('should throw without enough confirmations', async () => { @@ -74,7 +77,7 @@ describe('MultiSigWalletWithTimeLock', () => { const dataParams = { name: 'changeTimeLock', abi: MULTI_SIG_ABI, - args: [SECONDS_TIME_LOCKED], + args: [SECONDS_TIME_LOCKED.toNumber()], }; const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); @@ -82,10 +85,10 @@ describe('MultiSigWalletWithTimeLock', () => { SubmissionContractEventArgs >; - txId = log.args.transactionId.toNumber(); - return expect(multiSig.executeTransaction(txId, { from: owners[0] })).to.be.rejectedWith( - constants.REVERT, - ); + txId = log.args.transactionId; + return expect( + multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }), + ).to.be.rejectedWith(constants.REVERT); }); it('should set confirmation time with enough confirmations', async () => { @@ -94,7 +97,7 @@ describe('MultiSigWalletWithTimeLock', () => { const dataParams = { name: 'changeTimeLock', abi: MULTI_SIG_ABI, - args: [SECONDS_TIME_LOCKED], + args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); @@ -102,15 +105,15 @@ describe('MultiSigWalletWithTimeLock', () => { SubmissionContractEventArgs >; - txId = log.args.transactionId.toNumber(); - txHash = await multiSig.confirmTransaction(txId, { from: owners[1] }); + txId = log.args.transactionId; + txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); const res = await zeroEx.awaitTransactionMinedAsync(txHash); expect(res.logs).to.have.length(2); const blockNum = await web3Wrapper.getBlockNumberAsync(); const blockInfo = await web3Wrapper.getBlockAsync(blockNum); const timestamp = new BigNumber(blockInfo.timestamp); - const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.call(txId)); + const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes(txId)); expect(timestamp).to.be.bignumber.equal(confirmationTimeBigNum); }); @@ -121,7 +124,7 @@ describe('MultiSigWalletWithTimeLock', () => { const dataParams = { name: 'changeTimeLock', abi: MULTI_SIG_ABI, - args: [SECONDS_TIME_LOCKED], + args: [SECONDS_TIME_LOCKED.toNumber()], }; let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams); const subRes = await zeroEx.awaitTransactionMinedAsync(txHash); @@ -129,27 +132,28 @@ describe('MultiSigWalletWithTimeLock', () => { SubmissionContractEventArgs >; - txId = log.args.transactionId.toNumber(); - txHash = await multiSig.confirmTransaction(txId, { from: owners[1] }); + txId = log.args.transactionId; + txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] }); expect(initialSecondsTimeLocked).to.be.equal(0); - txHash = await multiSig.executeTransaction(txId, { from: owners[0] }); + txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); const res = await zeroEx.awaitTransactionMinedAsync(txHash); expect(res.logs).to.have.length(2); - const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call()); + const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked()); expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED); }); }); describe('initially time-locked', async () => { before('deploy a walet', async () => { - multiSig = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ + const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ owners, SIGNATURES_REQUIRED, SECONDS_TIME_LOCKED, ]); - multiSigWrapper = new MultiSigWrapper(multiSig); + multiSig = new MultiSigWalletWithTimeLockContract(multiSigInstance); + multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract); const secondsTimeLocked = await multiSig.secondsTimeLocked(); initialSecondsTimeLocked = secondsTimeLocked.toNumber(); @@ -165,8 +169,8 @@ describe('MultiSigWalletWithTimeLock', () => { const log = abiDecoder.tryToDecodeLogOrNoop(subRes.logs[0]) as LogWithDecodedArgs< SubmissionContractEventArgs >; - txId = log.args.transactionId.toNumber(); - txHash = await multiSig.confirmTransaction(txId, { + txId = log.args.transactionId; + txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1], }); const confRes = await zeroEx.awaitTransactionMinedAsync(txHash); @@ -174,16 +178,16 @@ describe('MultiSigWalletWithTimeLock', () => { }); const newSecondsTimeLocked = 0; it('should throw if it has enough confirmations but is not past the time lock', async () => { - return expect(multiSig.executeTransaction(txId, { from: owners[0] })).to.be.rejectedWith( - constants.REVERT, - ); + return expect( + multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }), + ).to.be.rejectedWith(constants.REVERT); }); it('should execute if it has enough confirmations and is past the time lock', async () => { - await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED); - await multiSig.executeTransaction(txId, { from: owners[0] }); + await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber()); + await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }); - const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.call()); + const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked()); expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked); }); }); |