aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/exchange/wrapper.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-13 22:10:05 +0800
committerFabio Berger <me@fabioberger.com>2018-06-13 22:10:05 +0800
commitb4fead9606ecc9655b2038fcef1c75217752f67d (patch)
treeb363eee11085850328837004b41ff23c5d31efb6 /packages/contracts/test/exchange/wrapper.ts
parent61243b418e4d962cd8d8a1d7a49f04510b3c1c7f (diff)
parent4efd28c092e74b438d0397069c0c55cc90c537f2 (diff)
downloaddexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.tar
dexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.gz
dexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.bz2
dexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.lz
dexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.xz
dexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.zst
dexon-sol-tools-b4fead9606ecc9655b2038fcef1c75217752f67d.zip
Merge branch 'v2-prototype' into feature/combinatorial-testing
* v2-prototype: (26 commits) Rename _coverageCollector -> _profilerCollector in TraceCollectionSubprovider Refactor sol-cov to de-duplicate code for coverage and profiling Rename popByte and popAddress Hard code test addresses/bytes32 instead of generating pseudorandom ones Update artifacts Rename computeCoverageAsync -> computeSingleTraceCoverageAsync Fix linter errors Refactor sol-cov to avoid keeping traceInfo in memory Unpop byte rather than making deep copy Pass gas in to marketBuyOrdersNoThrow Looks up the memory location of makerAssetData/takerAssetData Make ZRX_PROXY_ID constant rather than popping it from ZRX_ASSET_DATA Add tests for deepCopyBytes and missing write methods from LibBytes Pop id from assetData before dispatching to AssetProxies Upgrade solidity-parser-entlr 0.2.11 => 0.2.12 Fix import order Fix typos Add CHANGELOGs Speed-up sol-cov Increase delay when sending transactions during devnet startup ...
Diffstat (limited to 'packages/contracts/test/exchange/wrapper.ts')
-rw-r--r--packages/contracts/test/exchange/wrapper.ts105
1 files changed, 86 insertions, 19 deletions
diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts
index b66cff90a..abba1ac4f 100644
--- a/packages/contracts/test/exchange/wrapper.ts
+++ b/packages/contracts/test/exchange/wrapper.ts
@@ -81,7 +81,7 @@ describe('Exchange wrappers', () => {
artifacts.Exchange,
provider,
txDefaults,
- assetProxyUtils.encodeERC20AssetData(zrxToken.address),
+ zrxToken.address,
);
exchangeWrapper = new ExchangeWrapper(exchange, provider);
await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner);
@@ -712,6 +712,10 @@ describe('Exchange wrappers', () => {
);
await exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
takerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 6000000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -781,20 +785,49 @@ describe('Exchange wrappers', () => {
expect(newBalances).to.be.deep.equal(erc20Balances);
});
- it('should throw when a signedOrder does not use the same takerAssetAddress', async () => {
+ it('should not fill a signedOrder that does not use the same takerAssetAddress', async () => {
signedOrders = [
orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder(),
orderFactory.newSignedOrder({
takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
}),
- orderFactory.newSignedOrder(),
];
+ const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18);
+ const filledSignedOrders = signedOrders.slice(0, -1);
+ _.forEach(filledSignedOrders, signedOrder => {
+ erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][
+ defaultMakerAssetAddress
+ ].minus(signedOrder.makerAssetAmount);
+ erc20Balances[makerAddress][defaultTakerAssetAddress] = erc20Balances[makerAddress][
+ defaultTakerAssetAddress
+ ].add(signedOrder.takerAssetAmount);
+ erc20Balances[makerAddress][zrxToken.address] = erc20Balances[makerAddress][zrxToken.address].minus(
+ signedOrder.makerFee,
+ );
+ erc20Balances[takerAddress][defaultMakerAssetAddress] = erc20Balances[takerAddress][
+ defaultMakerAssetAddress
+ ].add(signedOrder.makerAssetAmount);
+ erc20Balances[takerAddress][defaultTakerAssetAddress] = erc20Balances[takerAddress][
+ defaultTakerAssetAddress
+ ].minus(signedOrder.takerAssetAmount);
+ erc20Balances[takerAddress][zrxToken.address] = erc20Balances[takerAddress][zrxToken.address].minus(
+ signedOrder.takerFee,
+ );
+ erc20Balances[feeRecipientAddress][zrxToken.address] = erc20Balances[feeRecipientAddress][
+ zrxToken.address
+ ].add(signedOrder.makerFee.add(signedOrder.takerFee));
+ });
+ await exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
+ takerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 600000,
+ });
- return expectRevertOrAlwaysFailingTransactionAsync(
- exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
- takerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
- }),
- );
+ const newBalances = await erc20Wrapper.getBalancesAsync();
+ expect(newBalances).to.be.deep.equal(erc20Balances);
});
});
@@ -894,6 +927,10 @@ describe('Exchange wrappers', () => {
);
await exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
makerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 600000,
});
const newBalances = await erc20Wrapper.getBalancesAsync();
@@ -926,8 +963,8 @@ describe('Exchange wrappers', () => {
);
});
- it('should fill all signedOrders if cannot fill entire takerAssetFillAmount', async () => {
- const takerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18);
+ it('should fill all signedOrders if cannot fill entire makerAssetFillAmount', async () => {
+ const makerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18);
_.forEach(signedOrders, signedOrder => {
erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][
defaultMakerAssetAddress
@@ -951,8 +988,8 @@ describe('Exchange wrappers', () => {
zrxToken.address
].add(signedOrder.makerFee.add(signedOrder.takerFee));
});
- await exchangeWrapper.marketSellOrdersNoThrowAsync(signedOrders, takerAddress, {
- takerAssetFillAmount,
+ await exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
+ makerAssetFillAmount,
// HACK(albrow): We need to hardcode the gas estimate here because
// the Geth gas estimator doesn't work with the way we use
// delegatecall and swallow errors.
@@ -963,20 +1000,50 @@ describe('Exchange wrappers', () => {
expect(newBalances).to.be.deep.equal(erc20Balances);
});
- it('should throw when a signedOrder does not use the same makerAssetAddress', async () => {
+ it('should not fill a signedOrder that does not use the same makerAssetAddress', async () => {
signedOrders = [
orderFactory.newSignedOrder(),
+ orderFactory.newSignedOrder(),
orderFactory.newSignedOrder({
makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address),
}),
- orderFactory.newSignedOrder(),
];
- return expectRevertOrAlwaysFailingTransactionAsync(
- exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
- makerAssetFillAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1000), 18),
- }),
- );
+ const makerAssetFillAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(100000), 18);
+ const filledSignedOrders = signedOrders.slice(0, -1);
+ _.forEach(filledSignedOrders, signedOrder => {
+ erc20Balances[makerAddress][defaultMakerAssetAddress] = erc20Balances[makerAddress][
+ defaultMakerAssetAddress
+ ].minus(signedOrder.makerAssetAmount);
+ erc20Balances[makerAddress][defaultTakerAssetAddress] = erc20Balances[makerAddress][
+ defaultTakerAssetAddress
+ ].add(signedOrder.takerAssetAmount);
+ erc20Balances[makerAddress][zrxToken.address] = erc20Balances[makerAddress][zrxToken.address].minus(
+ signedOrder.makerFee,
+ );
+ erc20Balances[takerAddress][defaultMakerAssetAddress] = erc20Balances[takerAddress][
+ defaultMakerAssetAddress
+ ].add(signedOrder.makerAssetAmount);
+ erc20Balances[takerAddress][defaultTakerAssetAddress] = erc20Balances[takerAddress][
+ defaultTakerAssetAddress
+ ].minus(signedOrder.takerAssetAmount);
+ erc20Balances[takerAddress][zrxToken.address] = erc20Balances[takerAddress][zrxToken.address].minus(
+ signedOrder.takerFee,
+ );
+ erc20Balances[feeRecipientAddress][zrxToken.address] = erc20Balances[feeRecipientAddress][
+ zrxToken.address
+ ].add(signedOrder.makerFee.add(signedOrder.takerFee));
+ });
+ await exchangeWrapper.marketBuyOrdersNoThrowAsync(signedOrders, takerAddress, {
+ makerAssetFillAmount,
+ // HACK(albrow): We need to hardcode the gas estimate here because
+ // the Geth gas estimator doesn't work with the way we use
+ // delegatecall and swallow errors.
+ gas: 600000,
+ });
+
+ const newBalances = await erc20Wrapper.getBalancesAsync();
+ expect(newBalances).to.be.deep.equal(erc20Balances);
});
});