Add tests for OrderTransferSimulationUtils
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
"src/DevUtils.sol",
|
"src/DevUtils.sol",
|
||||||
"src/LibAssetData.sol",
|
"src/LibAssetData.sol",
|
||||||
"src/LibTransactionDecoder.sol",
|
"src/LibTransactionDecoder.sol",
|
||||||
"src/EthBalanceChecker.sol"
|
"src/EthBalanceChecker.sol",
|
||||||
|
"src/OrderTransferSimulationUtils.sol"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"abis": "./generated-artifacts/@(DevUtils|LibAssetData|LibTransactionDecoder|EthBalanceChecker).json",
|
"abis": "./generated-artifacts/@(DevUtils|LibAssetData|LibTransactionDecoder|EthBalanceChecker|OrderTransferSimulationUtils).json",
|
||||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import { ContractArtifact } from 'ethereum-types';
|
|||||||
import * as DevUtils from '../generated-artifacts/DevUtils.json';
|
import * as DevUtils from '../generated-artifacts/DevUtils.json';
|
||||||
import * as LibAssetData from '../generated-artifacts/LibAssetData.json';
|
import * as LibAssetData from '../generated-artifacts/LibAssetData.json';
|
||||||
import * as LibTransactionDecoder from '../generated-artifacts/LibTransactionDecoder.json';
|
import * as LibTransactionDecoder from '../generated-artifacts/LibTransactionDecoder.json';
|
||||||
|
import * as OrderTransferSimulationUtils from '../generated-artifacts/OrderTransferSimulationUtils.json';
|
||||||
export const artifacts = {
|
export const artifacts = {
|
||||||
DevUtils: DevUtils as ContractArtifact,
|
DevUtils: DevUtils as ContractArtifact,
|
||||||
LibAssetData: LibAssetData as ContractArtifact,
|
LibAssetData: LibAssetData as ContractArtifact,
|
||||||
LibTransactionDecoder: LibTransactionDecoder as ContractArtifact,
|
LibTransactionDecoder: LibTransactionDecoder as ContractArtifact,
|
||||||
|
OrderTransferSimulationUtils: OrderTransferSimulationUtils as ContractArtifact,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,3 +6,4 @@
|
|||||||
export * from '../generated-wrappers/dev_utils';
|
export * from '../generated-wrappers/dev_utils';
|
||||||
export * from '../generated-wrappers/lib_asset_data';
|
export * from '../generated-wrappers/lib_asset_data';
|
||||||
export * from '../generated-wrappers/lib_transaction_decoder';
|
export * from '../generated-wrappers/lib_transaction_decoder';
|
||||||
|
export * from '../generated-wrappers/order_transfer_simulation_utils';
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||||
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
|
import { assetDataUtils, orderHashUtils } from '@0x/order-utils';
|
||||||
import { SignedOrder } from '@0x/types';
|
import { OrderTransferResults, SignedOrder } from '@0x/types';
|
||||||
import { BigNumber, providerUtils } from '@0x/utils';
|
import { BigNumber, providerUtils } from '@0x/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ chaiSetup.configure();
|
|||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||||
|
|
||||||
describe('OrderValidationUtils', () => {
|
describe('OrderValidationUtils/OrderTransferSimulatorUtils', () => {
|
||||||
let makerAddress: string;
|
let makerAddress: string;
|
||||||
let takerAddress: string;
|
let takerAddress: string;
|
||||||
let owner: string;
|
let owner: string;
|
||||||
@@ -412,6 +412,7 @@ describe('OrderValidationUtils', () => {
|
|||||||
});
|
});
|
||||||
describe('getOrderRelevantStates', async () => {
|
describe('getOrderRelevantStates', async () => {
|
||||||
it('should return the correct information for multiple orders', async () => {
|
it('should return the correct information for multiple orders', async () => {
|
||||||
|
signedOrder = await orderFactory.newSignedOrderAsync();
|
||||||
await erc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerAssetAmount);
|
await erc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerAssetAmount);
|
||||||
await erc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerAssetAmount, {
|
await erc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerAssetAmount, {
|
||||||
from: makerAddress,
|
from: makerAddress,
|
||||||
@@ -443,5 +444,149 @@ describe('OrderValidationUtils', () => {
|
|||||||
expect(isValidSignature[1]).to.equal(false);
|
expect(isValidSignature[1]).to.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('getSimulatedOrderTransferResults', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
signedOrder = await orderFactory.newSignedOrderAsync();
|
||||||
|
});
|
||||||
|
it('should return TakerAssetDataFailed if the takerAsset transfer fails', async () => {
|
||||||
|
const orderTransferResults = await devUtils.getSimulatedOrderTransferResults.callAsync(
|
||||||
|
signedOrder,
|
||||||
|
takerAddress,
|
||||||
|
signedOrder.takerAssetAmount,
|
||||||
|
);
|
||||||
|
expect(orderTransferResults).to.equal(OrderTransferResults.TakerAssetDataFailed);
|
||||||
|
});
|
||||||
|
it('should return MakerAssetDataFailed if the makerAsset transfer fails', async () => {
|
||||||
|
await erc20Token2.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token2.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerAssetAmount, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
const orderTransferResults = await devUtils.getSimulatedOrderTransferResults.callAsync(
|
||||||
|
signedOrder,
|
||||||
|
takerAddress,
|
||||||
|
signedOrder.takerAssetAmount,
|
||||||
|
);
|
||||||
|
expect(orderTransferResults).to.equal(OrderTransferResults.MakerAssetDataFailed);
|
||||||
|
});
|
||||||
|
it('should return TakerFeeAssetDataFailed if the takerFeeAsset transfer fails', async () => {
|
||||||
|
await erc20Token2.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token2.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerAssetAmount, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
await erc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerAssetAmount, {
|
||||||
|
from: makerAddress,
|
||||||
|
});
|
||||||
|
const orderTransferResults = await devUtils.getSimulatedOrderTransferResults.callAsync(
|
||||||
|
signedOrder,
|
||||||
|
takerAddress,
|
||||||
|
signedOrder.takerAssetAmount,
|
||||||
|
);
|
||||||
|
expect(orderTransferResults).to.equal(OrderTransferResults.TakerFeeAssetDataFailed);
|
||||||
|
});
|
||||||
|
it('should return MakerFeeAssetDataFailed if the makerFeeAsset transfer fails', async () => {
|
||||||
|
await erc20Token2.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token2.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerAssetAmount, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
await erc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerAssetAmount, {
|
||||||
|
from: makerAddress,
|
||||||
|
});
|
||||||
|
await feeErc20Token.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerFee, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await feeErc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerFee, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
const orderTransferResults = await devUtils.getSimulatedOrderTransferResults.callAsync(
|
||||||
|
signedOrder,
|
||||||
|
takerAddress,
|
||||||
|
signedOrder.takerAssetAmount,
|
||||||
|
);
|
||||||
|
expect(orderTransferResults).to.equal(OrderTransferResults.MakerFeeAssetDataFailed);
|
||||||
|
});
|
||||||
|
it('should return TransfersSuccessful if all transfers succeed', async () => {
|
||||||
|
await erc20Token2.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token2.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerAssetAmount, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
await erc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerAssetAmount, {
|
||||||
|
from: makerAddress,
|
||||||
|
});
|
||||||
|
await feeErc20Token.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerFee, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await feeErc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerFee, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
await feeErc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerFee, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await feeErc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerFee, {
|
||||||
|
from: makerAddress,
|
||||||
|
});
|
||||||
|
const orderTransferResults = await devUtils.getSimulatedOrderTransferResults.callAsync(
|
||||||
|
signedOrder,
|
||||||
|
takerAddress,
|
||||||
|
signedOrder.takerAssetAmount,
|
||||||
|
);
|
||||||
|
expect(orderTransferResults).to.equal(OrderTransferResults.TransfersSuccessful);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('getSimulatedOrdersTransferResults', async () => {
|
||||||
|
it('should simulate the transfers of each order independently from one another', async () => {
|
||||||
|
// Set balances and allowances to exactly enough to fill a single order
|
||||||
|
await erc20Token2.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token2.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerAssetAmount, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
await erc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerAssetAmount, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await erc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerAssetAmount, {
|
||||||
|
from: makerAddress,
|
||||||
|
});
|
||||||
|
await feeErc20Token.setBalance.awaitTransactionSuccessAsync(takerAddress, signedOrder.takerFee, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await feeErc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.takerFee, {
|
||||||
|
from: takerAddress,
|
||||||
|
});
|
||||||
|
await feeErc20Token.setBalance.awaitTransactionSuccessAsync(makerAddress, signedOrder.makerFee, {
|
||||||
|
from: owner,
|
||||||
|
});
|
||||||
|
await feeErc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, signedOrder.makerFee, {
|
||||||
|
from: makerAddress,
|
||||||
|
});
|
||||||
|
const [
|
||||||
|
orderTransferResults1,
|
||||||
|
orderTransferResults2,
|
||||||
|
] = await devUtils.getSimulatedOrdersTransferResults.callAsync(
|
||||||
|
[signedOrder, signedOrder],
|
||||||
|
[takerAddress, takerAddress],
|
||||||
|
[signedOrder.takerAssetAmount, signedOrder.takerAssetAmount],
|
||||||
|
);
|
||||||
|
expect(orderTransferResults1).to.equal(OrderTransferResults.TransfersSuccessful);
|
||||||
|
expect(orderTransferResults2).to.equal(OrderTransferResults.TransfersSuccessful);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// tslint:disable:max-file-line-count
|
// tslint:disable:max-file-line-count
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"generated-artifacts/DevUtils.json",
|
"generated-artifacts/DevUtils.json",
|
||||||
"generated-artifacts/LibAssetData.json",
|
"generated-artifacts/LibAssetData.json",
|
||||||
"generated-artifacts/LibTransactionDecoder.json",
|
"generated-artifacts/LibTransactionDecoder.json",
|
||||||
"generated-artifacts/EthBalanceChecker.json"
|
"generated-artifacts/EthBalanceChecker.json",
|
||||||
|
"generated-artifacts/OrderTransferSimulationUtils.json"
|
||||||
],
|
],
|
||||||
"exclude": ["./deploy/solc/solc_bin"]
|
"exclude": ["./deploy/solc/solc_bin"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -803,3 +803,11 @@ export enum OrderStatus {
|
|||||||
FullyFilled,
|
FullyFilled,
|
||||||
Cancelled,
|
Cancelled,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum OrderTransferResults {
|
||||||
|
TakerAssetDataFailed,
|
||||||
|
MakerAssetDataFailed,
|
||||||
|
TakerFeeAssetDataFailed,
|
||||||
|
MakerFeeAssetDataFailed,
|
||||||
|
TransfersSuccessful,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user