Add tests for contracts address config

This commit is contained in:
Leonid Logvinov
2017-09-18 16:54:24 +02:00
parent 504e7a25a5
commit 40a0d345b5
2 changed files with 37 additions and 2 deletions

View File

@@ -84,6 +84,16 @@ export class TokenRegistryWrapper extends ContractWrapper {
const token = this._createTokenFromMetadata(metadata);
return token;
}
/**
* Retrieves the Ethereum address of the TokenRegistry contract deployed on the network
* that the user-passed web3 provider is connected to.
* @returns The Ethereum address of the TokenRegistry contract being used.
*/
public async getContractAddressAsync(): Promise<string> {
const tokenRegistryInstance = await this._getTokenRegistryContractAsync();
const tokenRegistryAddress = tokenRegistryInstance.address;
return tokenRegistryAddress;
}
private _createTokenFromMetadata(metadata: TokenMetadata): Token|undefined {
if (metadata[0] === constants.NULL_ADDRESS) {
return undefined;

View File

@@ -4,12 +4,11 @@ import {chaiSetup} from './utils/chai_setup';
import 'mocha';
import * as BigNumber from 'bignumber.js';
import * as Sinon from 'sinon';
import {ZeroEx, Order} from '../src';
import {ZeroEx, Order, ZeroExError, LogWithDecodedArgs} from '../src';
import {constants} from './utils/constants';
import {TokenUtils} from './utils/token_utils';
import {web3Factory} from './utils/web3_factory';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import {LogWithDecodedArgs} from '../src';
const blockchainLifecycle = new BlockchainLifecycle();
chaiSetup.configure();
@@ -231,4 +230,30 @@ describe('ZeroEx library', () => {
expect(log.args._value).to.be.bignumber.equal(zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
});
});
describe('#config', () => {
it('allows to specify exchange contract address', async () => {
const config = {
exchangeContractAddress: ZeroEx.NULL_ADDRESS,
};
const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, config);
return expect(zeroExWithWrongExchangeAddress.exchange.getContractAddressAsync())
.to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
});
it('allows to specify ether token contract address', async () => {
const config = {
etherTokenContractAddress: ZeroEx.NULL_ADDRESS,
};
const zeroExWithWrongEtherTokenAddress = new ZeroEx(web3.currentProvider, config);
return expect(zeroExWithWrongEtherTokenAddress.etherToken.getContractAddressAsync())
.to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
});
it('allows to specify token registry token contract address', async () => {
const config = {
tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS,
};
const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, config);
return expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddressAsync())
.to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
});
});
});