Fixed the DevUtils tests

This commit is contained in:
Alex Towle
2019-12-20 15:51:38 -08:00
parent 9b7277d464
commit 54eb1d9055
3 changed files with 24 additions and 16 deletions

View File

@@ -1,25 +1,34 @@
import { artifacts, DevUtilsContract } from '@0x/contracts-dev-utils';
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange';
import { blockchainTests, constants, expect, orderHashUtils } from '@0x/contracts-test-utils';
import { Order } from '@0x/types';
import { BigNumber } from '@0x/utils';
blockchainTests('DevUtils.getOrderHash', env => {
let devUtils: DevUtilsContract;
let exchange: ExchangeContract;
let chainId: number;
before(async () => {
chainId = await env.getChainIdAsync();
exchange = await ExchangeContract.deployFrom0xArtifactAsync(
exchangeArtifacts.Exchange,
env.provider,
env.txDefaults,
exchangeArtifacts,
new BigNumber(chainId),
);
devUtils = await DevUtilsContract.deployFrom0xArtifactAsync(
artifacts.DevUtils,
env.provider,
env.txDefaults,
artifacts,
constants.NULL_ADDRESS,
exchange.address,
);
});
it('should return the order hash', async () => {
const expectedOrderHash = '0x331cb7e07a757bae130702da6646c26531798c92bcfaf671817268fd2c188531';
const exchangeAddress = '0x1dc4c1cefef38a777b15aa20260a54e584b16c48';
const chainId = 50;
const order: Order = {
makerAddress: constants.NULL_ADDRESS,
takerAddress: constants.NULL_ADDRESS,
@@ -35,11 +44,11 @@ blockchainTests('DevUtils.getOrderHash', env => {
makerAssetAmount: new BigNumber(0),
takerAssetAmount: new BigNumber(0),
expirationTimeSeconds: new BigNumber(0),
exchangeAddress,
exchangeAddress: exchange.address,
chainId,
};
expect(await devUtils.getOrderHash(order, new BigNumber(chainId), exchangeAddress).callAsync()).to.be.equal(
expectedOrderHash,
expect(await devUtils.getOrderHash(order, new BigNumber(chainId), exchange.address).callAsync()).to.be.equal(
orderHashUtils.getOrderHashHex(order),
);
});
});

View File

@@ -20,8 +20,7 @@ import { artifacts as erc721Artifacts, DummyERC721TokenContract } from '@0x/cont
import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange';
import { blockchainTests, constants, expect, LogDecoder } from '@0x/contracts-test-utils';
import { AssetProxyId } from '@0x/types';
import { BigNumber, LibBytesRevertErrors, StringRevertError } from '@0x/utils';
import * as ethUtil from 'ethereumjs-util';
import { BigNumber, hexUtils, LibBytesRevertErrors, StringRevertError } from '@0x/utils';
import { artifacts, LibAssetDataContract } from '@0x/contracts-dev-utils';
@@ -63,7 +62,7 @@ const KNOWN_STATIC_CALL_ENCODING = {
};
// TODO(jalextowle): This file could really be cleaned up by using the DeploymentManager tool.
blockchainTests('LibAssetData', env => {
blockchainTests.resets('LibAssetData', env => {
let exchange: ExchangeContract;
let erc20Proxy: ERC20ProxyContract;
let erc721Proxy: ERC721ProxyContract;
@@ -423,8 +422,8 @@ blockchainTests('LibAssetData', env => {
it('should return a balance of MAX_UINT256 if the the StaticCallProxy assetData contains data for a successful staticcall', async () => {
const staticCallData = staticCallTarget.isOddNumber(new BigNumber(1)).getABIEncodedTransactionData();
const trueAsBuffer = ethUtil.toBuffer('0x0000000000000000000000000000000000000000000000000000000000000001');
const expectedResultHash = ethUtil.bufferToHex(ethUtil.sha3(trueAsBuffer));
const trueAsString = '0x0000000000000000000000000000000000000000000000000000000000000001';
const expectedResultHash = hexUtils.hash(trueAsString);
const assetData = await libAssetData
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
.callAsync();
@@ -434,8 +433,8 @@ blockchainTests('LibAssetData', env => {
it('should return a balance of 0 if the the StaticCallProxy assetData contains data for an unsuccessful staticcall', async () => {
const staticCallData = staticCallTarget.isOddNumber(new BigNumber(0)).getABIEncodedTransactionData();
const trueAsBuffer = ethUtil.toBuffer('0x0000000000000000000000000000000000000000000000000000000000000001');
const expectedResultHash = ethUtil.bufferToHex(ethUtil.sha3(trueAsBuffer));
const trueAsString = '0x0000000000000000000000000000000000000000000000000000000000000001';
const expectedResultHash = hexUtils.hash(trueAsString);
const assetData = await libAssetData
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, expectedResultHash)
.callAsync();

View File

@@ -11,7 +11,7 @@ import { Maker } from '../framework/actors/maker';
import { DeploymentManager } from '../framework/deployment_manager';
// TODO(jalextowle): This can be cleaned up by using the actors more.
blockchainTests.resets.only('OrderValidationUtils/OrderTransferSimulatorUtils', env => {
blockchainTests.resets('OrderValidationUtils/OrderTransferSimulatorUtils', env => {
let takerAddress: string;
let owner: string;