aboutsummaryrefslogtreecommitdiffstats
path: root/test/0x.js_test.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-07-04 03:28:34 +0800
committerGitHub <noreply@github.com>2017-07-04 03:28:34 +0800
commitd4cef89587ef8ea0f7fbab1146c4524e8f588eac (patch)
tree93dcf602b5a738bad03c121384707fcf19518310 /test/0x.js_test.ts
parentd506a1f98562dd11ecff5e936a93fce6d14e48a9 (diff)
parent8204409c6d6bf773aa8ebb38006a3975ed43a684 (diff)
downloaddexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar
dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.gz
dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.bz2
dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.lz
dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.xz
dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.tar.zst
dexon-sol-tools-d4cef89587ef8ea0f7fbab1146c4524e8f588eac.zip
Merge pull request #82 from 0xProject/add-exchange-address-to-order-struct
Allow multiple Exchange contracts and multiple artifacts
Diffstat (limited to 'test/0x.js_test.ts')
-rw-r--r--test/0x.js_test.ts33
1 files changed, 14 insertions, 19 deletions
diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts
index 9ec0a0c8e..50db402c4 100644
--- a/test/0x.js_test.ts
+++ b/test/0x.js_test.ts
@@ -16,10 +16,11 @@ describe('ZeroEx library', () => {
it('overrides provider in nested web3s and invalidates contractInstances', async () => {
const web3 = web3Factory.create();
const zeroEx = new ZeroEx(web3.currentProvider);
+ const [exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressesAsync();
// Instantiate the contract instances with the current provider
- await (zeroEx.exchange as any)._getExchangeContractAsync();
+ await (zeroEx.exchange as any)._getExchangeContractAsync(exchangeContractAddress);
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
- expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined();
+ expect((zeroEx.exchange as any)._exchangeContractByAddress[exchangeContractAddress]).to.not.be.undefined();
expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined();
const newProvider = web3Factory.getRpcProvider();
@@ -28,7 +29,7 @@ describe('ZeroEx library', () => {
await zeroEx.setProviderAsync(newProvider);
// Check that contractInstances with old provider are removed after provider update
- expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined();
+ expect((zeroEx.exchange as any)._exchangeContractByAddress[exchangeContractAddress]).to.be.undefined();
expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.be.undefined();
// Check that all nested web3 instances return the updated provider
@@ -52,6 +53,10 @@ describe('ZeroEx library', () => {
const address = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
const web3 = web3Factory.create();
const zeroEx = new ZeroEx(web3.currentProvider);
+ let exchangeContractAddress: string;
+ before(async () => {
+ [exchangeContractAddress] = await zeroEx.exchange.getAvailableContractAddressesAsync();
+ });
it('should return false if the data doesn\'t pertain to the signature & address', async () => {
expect(ZeroEx.isValidSignature('0x0', signature, address)).to.be.false();
return expect(
@@ -77,7 +82,7 @@ describe('ZeroEx library', () => {
const isValidSignatureLocal = ZeroEx.isValidSignature(dataHex, signature, address);
expect(isValidSignatureLocal).to.be.true();
const isValidSignatureOnContract = await (zeroEx.exchange as any)
- ._isValidSignatureUsingContractCallAsync(dataHex, signature, address);
+ ._isValidSignatureUsingContractCallAsync(dataHex, signature, address, exchangeContractAddress);
return expect(isValidSignatureOnContract).to.be.true();
});
});
@@ -125,15 +130,16 @@ describe('ZeroEx library', () => {
expect(baseUnitAmount).to.be.bignumber.equal(expectedUnitAmount);
});
});
- describe('#getOrderHashHexAsync', () => {
- const exchangeContractAddress = constants.NULL_ADDRESS;
- const expectedOrderHash = '0x103a5e97dab5dbeb8f385636f86a7d1e458a7ccbe1bd194727f0b2f85ab116c7';
+ describe('#getOrderHashHex', () => {
+ const expectedOrderHash = '0x39da987067a3c9e5f1617694f1301326ba8c8b0498ebef5df4863bed394e3c83';
+ const fakeExchangeContractAddress = '0xb69e673309512a9d726f87304c6984054f87a93b';
const order: Order = {
maker: constants.NULL_ADDRESS,
taker: constants.NULL_ADDRESS,
feeRecipient: constants.NULL_ADDRESS,
makerTokenAddress: constants.NULL_ADDRESS,
takerTokenAddress: constants.NULL_ADDRESS,
+ exchangeContractAddress: fakeExchangeContractAddress,
salt: new BigNumber(0),
makerFee: new BigNumber(0),
takerFee: new BigNumber(0),
@@ -141,22 +147,11 @@ describe('ZeroEx library', () => {
takerTokenAmount: new BigNumber(0),
expirationUnixTimestampSec: new BigNumber(0),
};
- let stubs: Sinon.SinonStub[] = [];
- afterEach(() => {
- // clean up any stubs after the test has completed
- _.each(stubs, s => s.restore());
- stubs = [];
- });
it('calculates the order hash', async () => {
const web3 = web3Factory.create();
const zeroEx = new ZeroEx(web3.currentProvider);
- stubs = [
- Sinon.stub((zeroEx as any), '_getExchangeAddressAsync')
- .returns(Promise.resolve(exchangeContractAddress)),
- ];
-
- const orderHash = await zeroEx.getOrderHashHexAsync(order);
+ const orderHash = zeroEx.getOrderHashHex(order);
expect(orderHash).to.be.equal(expectedOrderHash);
});
});