Use the same templates as 0x.js

This commit is contained in:
Leonid Logvinov
2018-02-23 14:13:35 -08:00
parent 34274a1042
commit 93b2736d65
30 changed files with 178 additions and 184 deletions

View File

@@ -60,16 +60,20 @@ describe('Exchange', () => {
deployer.deployAsync(ContractName.DummyToken),
deployer.deployAsync(ContractName.DummyToken),
]);
rep = new DummyTokenContract(repInstance);
dgd = new DummyTokenContract(dgdInstance);
zrx = new DummyTokenContract(zrxInstance);
rep = new DummyTokenContract(web3Wrapper, repInstance.abi, repInstance.address);
dgd = new DummyTokenContract(web3Wrapper, dgdInstance.abi, dgdInstance.address);
zrx = new DummyTokenContract(web3Wrapper, zrxInstance.abi, zrxInstance.address);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
]);
exchange = new ExchangeContract(exchangeInstance);
exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
zeroEx = new ZeroEx(web3.currentProvider, {
exchangeContractAddress: exchange.address,
@@ -647,7 +651,7 @@ describe('Exchange', () => {
it('should not change balances if makerTokenAddress is ZRX, makerTokenAmount + makerFee > maker allowance, \
and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const makerZRXAllowance = await zrx.allowance(maker, tokenTransferProxy.address);
const makerZRXAllowance = await zrx.allowance.callAsync(maker, tokenTransferProxy.address);
signedOrder = await orderFactory.newSignedOrderAsync({
makerTokenAddress: zrx.address,
makerTokenAmount: new BigNumber(makerZRXAllowance),
@@ -673,7 +677,7 @@ describe('Exchange', () => {
it('should not change balances if takerTokenAddress is ZRX, takerTokenAmount + takerFee > taker allowance, \
and shouldThrowOnInsufficientBalanceOrAllowance = false', async () => {
const takerZRXAllowance = await zrx.allowance(taker, tokenTransferProxy.address);
const takerZRXAllowance = await zrx.allowance.callAsync(taker, tokenTransferProxy.address);
signedOrder = await orderFactory.newSignedOrderAsync({
takerTokenAddress: zrx.address,
takerTokenAmount: new BigNumber(takerZRXAllowance),

View File

@@ -47,7 +47,7 @@ describe('Exchange', () => {
zrx.address,
tokenTransferProxy.address,
]);
const exchange = new ExchangeContract(exchangeInstance);
const exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] });
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
exchangeWrapper = new ExchangeWrapper(exchange, zeroEx);

View File

@@ -60,18 +60,26 @@ describe('Exchange', () => {
deployer.deployAsync(ContractName.DummyToken),
deployer.deployAsync(ContractName.DummyToken),
]);
rep = new DummyTokenContract(repInstance);
dgd = new DummyTokenContract(dgdInstance);
zrx = new DummyTokenContract(zrxInstance);
rep = new DummyTokenContract(web3Wrapper, repInstance.abi, repInstance.address);
dgd = new DummyTokenContract(web3Wrapper, dgdInstance.abi, dgdInstance.address);
zrx = new DummyTokenContract(web3Wrapper, zrxInstance.abi, zrxInstance.address);
const tokenRegistryInstance = await deployer.deployAsync(ContractName.TokenRegistry);
tokenRegistry = new TokenRegistryContract(tokenRegistryInstance);
tokenRegistry = new TokenRegistryContract(
web3Wrapper,
tokenRegistryInstance.abi,
tokenRegistryInstance.address,
);
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
);
const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [
zrx.address,
tokenTransferProxy.address,
]);
exchange = new ExchangeContract(exchangeInstance);
exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] });
const zeroEx = new ZeroEx(web3.currentProvider, { networkId: constants.TESTRPC_NETWORK_ID });
exWrapper = new ExchangeWrapper(exchange, zeroEx);

View File

@@ -59,10 +59,14 @@ describe('MultiSigWalletWithTimeLock', () => {
SIGNATURES_REQUIRED,
0,
]);
multiSig = new MultiSigWalletWithTimeLockContract(multiSigInstance);
multiSig = new MultiSigWalletWithTimeLockContract(
web3Wrapper,
multiSigInstance.abi,
multiSigInstance.address,
);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
const secondsTimeLocked = await multiSig.secondsTimeLocked();
const secondsTimeLocked = await multiSig.secondsTimeLocked.callAsync();
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
});
it('should throw when not called by wallet', async () => {
@@ -113,7 +117,7 @@ describe('MultiSigWalletWithTimeLock', () => {
const blockNum = await web3Wrapper.getBlockNumberAsync();
const blockInfo = await web3Wrapper.getBlockAsync(blockNum);
const timestamp = new BigNumber(blockInfo.timestamp);
const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes(txId));
const confirmationTimeBigNum = new BigNumber(await multiSig.confirmationTimes.callAsync(txId));
expect(timestamp).to.be.bignumber.equal(confirmationTimeBigNum);
});
@@ -141,7 +145,7 @@ describe('MultiSigWalletWithTimeLock', () => {
const res = await zeroEx.awaitTransactionMinedAsync(txHash);
expect(res.logs).to.have.length(2);
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked());
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync());
expect(secondsTimeLocked).to.be.bignumber.equal(SECONDS_TIME_LOCKED);
});
});
@@ -152,10 +156,14 @@ describe('MultiSigWalletWithTimeLock', () => {
SIGNATURES_REQUIRED,
SECONDS_TIME_LOCKED,
]);
multiSig = new MultiSigWalletWithTimeLockContract(multiSigInstance);
multiSig = new MultiSigWalletWithTimeLockContract(
web3Wrapper,
multiSigInstance.abi,
multiSigInstance.address,
);
multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract);
const secondsTimeLocked = await multiSig.secondsTimeLocked();
const secondsTimeLocked = await multiSig.secondsTimeLocked.callAsync();
initialSecondsTimeLocked = secondsTimeLocked.toNumber();
const destination = multiSig.address;
const from = owners[0];
@@ -187,7 +195,7 @@ describe('MultiSigWalletWithTimeLock', () => {
await rpc.increaseTimeAsync(SECONDS_TIME_LOCKED.toNumber());
await multiSig.executeTransaction.sendTransactionAsync(txId, { from: owners[0] });
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked());
const secondsTimeLocked = new BigNumber(await multiSig.secondsTimeLocked.callAsync());
expect(secondsTimeLocked).to.be.bignumber.equal(newSecondsTimeLocked);
});
});

View File

@@ -49,7 +49,11 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
[authorizedAddress, unauthorizedAddress] = accounts;
const initialOwner = accounts[0];
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, {
from: initialOwner,
});
@@ -57,7 +61,11 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
[owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address],
);
multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract(multiSigInstance);
multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract(
web3Wrapper,
multiSigInstance.abi,
multiSigInstance.address,
);
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {
from: initialOwner,
});
@@ -74,12 +82,14 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
describe('isFunctionRemoveAuthorizedAddress', () => {
it('should throw if data is not for removeAuthorizedAddress', async () => {
const data = MultiSigWrapper.encodeFnArgs('addAuthorizedAddress', PROXY_ABI, [owners[0]]);
return expect(multiSig.isFunctionRemoveAuthorizedAddress(data)).to.be.rejectedWith(constants.REVERT);
return expect(multiSig.isFunctionRemoveAuthorizedAddress.callAsync(data)).to.be.rejectedWith(
constants.REVERT,
);
});
it('should return true if data is for removeAuthorizedAddress', async () => {
const data = MultiSigWrapper.encodeFnArgs('removeAuthorizedAddress', PROXY_ABI, [owners[0]]);
const isFunctionRemoveAuthorizedAddress = await multiSig.isFunctionRemoveAuthorizedAddress(data);
const isFunctionRemoveAuthorizedAddress = await multiSig.isFunctionRemoveAuthorizedAddress.callAsync(data);
expect(isFunctionRemoveAuthorizedAddress).to.be.true();
});
});
@@ -114,7 +124,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
const isConfirmed = await multiSig.isConfirmed.callAsync(txId);
expect(isConfirmed).to.be.true();
return expect(
@@ -133,7 +143,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
const isConfirmed = await multiSig.isConfirmed.callAsync(txId);
expect(isConfirmed).to.be.true();
return expect(
@@ -152,10 +162,10 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
const isConfirmed = await multiSig.isConfirmed.callAsync(txId);
expect(isConfirmed).to.be.true();
await multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] });
const isAuthorized = await tokenTransferProxy.authorized(authorizedAddress);
const isAuthorized = await tokenTransferProxy.authorized.callAsync(authorizedAddress);
expect(isAuthorized).to.be.false();
});
@@ -170,10 +180,10 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => {
const log = abiDecoder.tryToDecodeLogOrNoop(res.logs[0]) as LogWithDecodedArgs<SubmissionContractEventArgs>;
const txId = log.args.transactionId;
await multiSig.confirmTransaction.sendTransactionAsync(txId, { from: owners[1] });
const isConfirmed = await multiSig.isConfirmed(txId);
const isConfirmed = await multiSig.isConfirmed.callAsync(txId);
expect(isConfirmed).to.be.true();
await multiSig.executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from: owners[1] });
const tx = await multiSig.transactions(txId);
const tx = await multiSig.transactions.callAsync(txId);
const isExecuted = tx[3];
expect(isExecuted).to.be.true();
return expect(

View File

@@ -31,7 +31,7 @@ describe('TokenRegistry', () => {
owner = accounts[0];
notOwner = accounts[1];
const tokenRegInstance = await deployer.deployAsync(ContractName.TokenRegistry);
tokenReg = new TokenRegistryContract(tokenRegInstance);
tokenReg = new TokenRegistryContract(web3Wrapper, tokenRegInstance.abi, tokenRegInstance.address);
tokenRegWrapper = new TokenRegWrapper(tokenReg);
});
beforeEach(async () => {

View File

@@ -25,7 +25,11 @@ describe('TokenTransferProxy', () => {
owner = address = accounts[0];
notOwner = accounts[1];
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
@@ -41,7 +45,7 @@ describe('TokenTransferProxy', () => {
});
it('should allow owner to add an authorized address', async () => {
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, { from: owner });
const isAuthorized = await tokenTransferProxy.authorized(address);
const isAuthorized = await tokenTransferProxy.authorized.callAsync(address);
expect(isAuthorized).to.be.true();
});
it('should throw if owner attempts to authorize a duplicate address', async () => {
@@ -67,7 +71,7 @@ describe('TokenTransferProxy', () => {
await tokenTransferProxy.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
const isAuthorized = await tokenTransferProxy.authorized(address);
const isAuthorized = await tokenTransferProxy.authorized.callAsync(address);
expect(isAuthorized).to.be.false();
});
@@ -82,19 +86,19 @@ describe('TokenTransferProxy', () => {
describe('getAuthorizedAddresses', () => {
it('should return all authorized addresses', async () => {
const initial = await tokenTransferProxy.getAuthorizedAddresses();
const initial = await tokenTransferProxy.getAuthorizedAddresses.callAsync();
expect(initial).to.have.length(0);
await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses();
const afterAdd = await tokenTransferProxy.getAuthorizedAddresses.callAsync();
expect(afterAdd).to.have.length(1);
expect(afterAdd).to.include(address);
await tokenTransferProxy.removeAuthorizedAddress.sendTransactionAsync(address, {
from: owner,
});
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses();
const afterRemove = await tokenTransferProxy.getAuthorizedAddresses.callAsync();
expect(afterRemove).to.have.length(0);
});
});

View File

@@ -33,9 +33,13 @@ describe('TokenTransferProxy', () => {
accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = notAuthorized = accounts[0];
const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy);
tokenTransferProxy = new TokenTransferProxyContract(tokenTransferProxyInstance);
tokenTransferProxy = new TokenTransferProxyContract(
web3Wrapper,
tokenTransferProxyInstance.abi,
tokenTransferProxyInstance.address,
);
const repInstance = await deployer.deployAsync(ContractName.DummyToken);
rep = new DummyTokenContract(repInstance);
rep = new DummyTokenContract(web3Wrapper, repInstance.abi, repInstance.address);
dmyBalances = new Balances([rep], [accounts[0], accounts[1]]);
await Promise.all([

View File

@@ -35,7 +35,7 @@ describe('UnlimitedAllowanceToken', () => {
owner = accounts[0];
spender = accounts[1];
const tokenInstance = await deployer.deployAsync(ContractName.DummyToken);
token = new DummyTokenContract(tokenInstance);
token = new DummyTokenContract(web3Wrapper, tokenInstance.abi, tokenInstance.address);
await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner });
tokenAddress = token.address;
});

View File

@@ -36,7 +36,7 @@ describe('ZRXToken', () => {
networkId: constants.TESTRPC_NETWORK_ID,
});
const zrxInstance = await deployer.deployAsync(ContractName.ZRXToken);
zrx = new ZRXTokenContract(zrxInstance);
zrx = new ZRXTokenContract(web3Wrapper, zrxInstance.abi, zrxInstance.address);
zrxAddress = zrx.address;
MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
});
@@ -48,25 +48,25 @@ describe('ZRXToken', () => {
});
describe('constants', () => {
it('should have 18 decimals', async () => {
const decimals = new BigNumber(await zrx.decimals());
const decimals = new BigNumber(await zrx.decimals.callAsync());
const expectedDecimals = 18;
expect(decimals).to.be.bignumber.equal(expectedDecimals);
});
it('should have a total supply of 1 billion tokens', async () => {
const totalSupply = new BigNumber(await zrx.totalSupply());
const totalSupply = new BigNumber(await zrx.totalSupply.callAsync());
const expectedTotalSupply = 1000000000;
expect(ZeroEx.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply);
});
it('should be named 0x Protocol Token', async () => {
const name = await zrx.name();
const name = await zrx.name.callAsync();
const expectedName = '0x Protocol Token';
expect(name).to.be.equal(expectedName);
});
it('should have the symbol ZRX', async () => {
const symbol = await zrx.symbol();
const symbol = await zrx.symbol.callAsync();
const expectedSymbol = 'ZRX';
expect(symbol).to.be.equal(expectedSymbol);
});
@@ -75,7 +75,7 @@ describe('ZRXToken', () => {
describe('constructor', () => {
it('should initialize owner balance to totalSupply', async () => {
const ownerBalance = await zeroEx.token.getBalanceAsync(zrxAddress, owner);
const totalSupply = new BigNumber(await zrx.totalSupply());
const totalSupply = new BigNumber(await zrx.totalSupply.callAsync());
expect(totalSupply).to.be.bignumber.equal(ownerBalance);
});
});