aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/multi_sig_with_time_lock.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/test/multi_sig_with_time_lock.ts')
-rw-r--r--packages/contracts/test/multi_sig_with_time_lock.ts150
1 files changed, 43 insertions, 107 deletions
diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts
index 732077df2..c369ca63a 100644
--- a/packages/contracts/test/multi_sig_with_time_lock.ts
+++ b/packages/contracts/test/multi_sig_with_time_lock.ts
@@ -1,40 +1,39 @@
import { BlockchainLifecycle, web3Factory } from '@0xproject/dev-utils';
import { LogWithDecodedArgs } from '@0xproject/types';
-import { AbiDecoder, BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
+import * as _ from 'lodash';
import 'make-promises-safe';
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 {
+ MultiSigWalletWithTimeLockContract,
+ SubmissionContractEventArgs,
+} from '../src/contract_wrappers/generated/multi_sig_wallet_with_time_lock';
import { artifacts } from '../src/utils/artifacts';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
import { MultiSigWrapper } from '../src/utils/multi_sig_wrapper';
-import { SubmissionContractEventArgs } from '../src/utils/types';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
-const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi;
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-const abiDecoder = new AbiDecoder([MULTI_SIG_ABI]);
describe('MultiSigWalletWithTimeLock', () => {
let owners: string[];
+ const requiredApprovals = new BigNumber(2);
+ const SECONDS_TIME_LOCKED = new BigNumber(1000000);
+
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owners = [accounts[0], accounts[1]];
});
- const SIGNATURES_REQUIRED = new BigNumber(2);
- const SECONDS_TIME_LOCKED = new BigNumber(10000);
let multiSig: MultiSigWalletWithTimeLockContract;
let multiSigWrapper: MultiSigWrapper;
- let txId: BigNumber;
- let initialSecondsTimeLocked: number;
+
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
@@ -51,19 +50,18 @@ describe('MultiSigWalletWithTimeLock', () => {
await blockchainLifecycle.revertAsync();
});
before('deploy a wallet', async () => {
+ const secondsTimeLocked = new BigNumber(0);
multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync(
artifacts.MultiSigWalletWithTimeLock,
provider,
txDefaults,
owners,
- SIGNATURES_REQUIRED,
- new BigNumber(0),
+ requiredApprovals,
+ secondsTimeLocked,
);
- multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
-
- const secondsTimeLocked = await multiSig.secondsTimeLocked.callAsync();
- initialSecondsTimeLocked = secondsTimeLocked.toNumber();
+ multiSigWrapper = new MultiSigWrapper(multiSig, provider);
});
+
it('should throw when not called by wallet', async () => {
return expect(
multiSig.changeTimeLock.sendTransactionAsync(SECONDS_TIME_LOCKED, { from: owners[0] }),
@@ -72,22 +70,11 @@ describe('MultiSigWalletWithTimeLock', () => {
it('should throw without enough confirmations', async () => {
const destination = multiSig.address;
- const from = owners[0];
- const dataParams = {
- name: 'changeTimeLock',
- abi: MULTI_SIG_ABI,
- args: [SECONDS_TIME_LOCKED.toNumber()],
- };
- const txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
- const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
- SubmissionContractEventArgs
- >;
+ const changeTimeLockData = multiSig.changeTimeLock.getABIEncodedTransactionData(SECONDS_TIME_LOCKED);
+ const res = await multiSigWrapper.submitTransactionAsync(destination, changeTimeLockData, owners[0]);
+ const log = res.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = log.args.transactionId;
- txId = log.args.transactionId;
return expect(
multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),
).to.be.rejectedWith(constants.REVERT);
@@ -95,28 +82,13 @@ describe('MultiSigWalletWithTimeLock', () => {
it('should set confirmation time with enough confirmations', async () => {
const destination = multiSig.address;
- const from = owners[0];
- const dataParams = {
- name: 'changeTimeLock',
- abi: MULTI_SIG_ABI,
- args: [SECONDS_TIME_LOCKED.toNumber()],
- };
- let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
- const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
- SubmissionContractEventArgs
- >;
+ const changeTimeLockData = multiSig.changeTimeLock.getABIEncodedTransactionData(SECONDS_TIME_LOCKED);
+ const subRes = await multiSigWrapper.submitTransactionAsync(destination, changeTimeLockData, owners[0]);
+ const subLog = subRes.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = subLog.args.transactionId;
- txId = log.args.transactionId;
- txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
- const res = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- expect(res.logs).to.have.length(2);
+ const confirmRes = await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
+ expect(confirmRes.logs).to.have.length(2);
const blockNum = await web3Wrapper.getBlockNumberAsync();
const blockInfo = await web3Wrapper.getBlockAsync(blockNum);
@@ -128,33 +100,13 @@ describe('MultiSigWalletWithTimeLock', () => {
it('should be executable with enough confirmations and secondsTimeLocked of 0', async () => {
const destination = multiSig.address;
- const from = owners[0];
- const dataParams = {
- name: 'changeTimeLock',
- abi: MULTI_SIG_ABI,
- args: [SECONDS_TIME_LOCKED.toNumber()],
- };
- let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
- const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
- SubmissionContractEventArgs
- >;
-
- txId = log.args.transactionId;
- txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
- await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
-
- expect(initialSecondsTimeLocked).to.be.equal(0);
+ const changeTimeLockData = multiSig.changeTimeLock.getABIEncodedTransactionData(SECONDS_TIME_LOCKED);
+ const subRes = await multiSigWrapper.submitTransactionAsync(destination, changeTimeLockData, owners[0]);
+ const subLog = subRes.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
+ const txId = subLog.args.transactionId;
- txHash = await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] });
- const res = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- expect(res.logs).to.have.length(2);
+ await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
+ await multiSigWrapper.executeTransactionAsync(txId, owners[1]);
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync());
expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED);
@@ -167,45 +119,29 @@ describe('MultiSigWalletWithTimeLock', () => {
after(async () => {
await blockchainLifecycle.revertAsync();
});
- before('deploy a wallet', async () => {
+ let txId: BigNumber;
+ const newSecondsTimeLocked = new BigNumber(0);
+ before('deploy a wallet, submit transaction to change timelock, and confirm the transaction', async () => {
multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync(
artifacts.MultiSigWalletWithTimeLock,
provider,
txDefaults,
owners,
- SIGNATURES_REQUIRED,
+ requiredApprovals,
SECONDS_TIME_LOCKED,
);
- multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
+ multiSigWrapper = new MultiSigWrapper(multiSig, provider);
- const secondsTimeLocked = await multiSig.secondsTimeLocked.callAsync();
- initialSecondsTimeLocked = secondsTimeLocked.toNumber();
- const destination = multiSig.address;
- const from = owners[0];
- const dataParams = {
- name: 'changeTimeLock',
- abi: MULTI_SIG_ABI,
- args: [newSecondsTimeLocked],
- };
- let txHash = await multiSigWrapper.submitTransactionAsync(destination, from, dataParams);
- let txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
+ const changeTimeLockData = multiSig.changeTimeLock.getABIEncodedTransactionData(newSecondsTimeLocked);
+ const res = await multiSigWrapper.submitTransactionAsync(
+ multiSig.address,
+ changeTimeLockData,
+ owners[0],
);
- const log = abiDecoder.tryToDecodeLogOrNoop(txReceipt.logs[0]) as LogWithDecodedArgs<
- SubmissionContractEventArgs
- >;
+ const log = res.logs[0] as LogWithDecodedArgs<SubmissionContractEventArgs>;
txId = log.args.transactionId;
- txHash = await multiSig.confirmTransaction.sendTransactionAsync(txId, {
- from: owners[1],
- });
- txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- expect(txReceipt.logs).to.have.length(2);
+ await multiSigWrapper.confirmTransactionAsync(txId, owners[1]);
});
- const newSecondsTimeLocked = 0;
it('should throw if it has enough confirmations but is not past the time lock', async () => {
return expect(
multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] }),