Make zeroEx.exchange.getContractAddress non-async

This commit is contained in:
Leonid Logvinov
2017-11-22 11:53:04 -06:00
parent efe8e07854
commit 4fe28ec53c
5 changed files with 18 additions and 12 deletions

View File

@@ -664,7 +664,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback); assert.isFunction('callback', callback);
const exchangeContractAddress = await this.getContractAddressAsync(); const exchangeContractAddress = this.getContractAddress();
const subscriptionToken = this._subscribe<ArgsType>( const subscriptionToken = this._subscribe<ArgsType>(
exchangeContractAddress, eventName, indexFilterValues, artifacts.ExchangeArtifact.abi, callback, exchangeContractAddress, eventName, indexFilterValues, artifacts.ExchangeArtifact.abi, callback,
); );
@@ -691,7 +691,7 @@ export class ExchangeWrapper extends ContractWrapper {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema); assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const exchangeContractAddress = await this.getContractAddressAsync(); const exchangeContractAddress = this.getContractAddress();
const logs = await this._getLogsAsync<ArgsType>( const logs = await this._getLogsAsync<ArgsType>(
exchangeContractAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.ExchangeArtifact.abi, exchangeContractAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.ExchangeArtifact.abi,
); );
@@ -702,10 +702,17 @@ export class ExchangeWrapper extends ContractWrapper {
* that the user-passed web3 provider is connected to. * that the user-passed web3 provider is connected to.
* @returns The Ethereum address of the Exchange contract being used. * @returns The Ethereum address of the Exchange contract being used.
*/ */
public async getContractAddressAsync(): Promise<string> { public getContractAddress(): string {
const exchangeInstance = await this._getExchangeContractAsync(); const networkId = this._web3Wrapper.getNetworkId();
const exchangeAddress = exchangeInstance.address; if (_.isUndefined(this._contractAddressIfExists)) {
return exchangeAddress; const contractAddress = artifacts.ExchangeArtifact.networks[networkId].address;
if (_.isUndefined(contractAddress)) {
throw new Error(ZeroExError.ExchangeContractDoesNotExist);
}
return contractAddress;
} else {
return this._contractAddressIfExists;
}
} }
/** /**
* Checks if order is still fillable and throws an error otherwise. Useful for orderbook * Checks if order is still fillable and throws an error otherwise. Useful for orderbook

View File

@@ -240,8 +240,7 @@ describe('ZeroEx library', () => {
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
}; };
const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig); const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig);
return expect(zeroExWithWrongExchangeAddress.exchange.getContractAddressAsync()) expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS);
.to.be.rejectedWith(ZeroExError.ContractDoesNotExist);
}); });
it('allows to specify ether token contract address', async () => { it('allows to specify ether token contract address', async () => {
const zeroExConfig = { const zeroExConfig = {

View File

@@ -29,7 +29,7 @@ describe('Artifacts', () => {
await (zeroEx.token as any)._getTokenTransferProxyAddressAsync(); await (zeroEx.token as any)._getTokenTransferProxyAddressAsync();
}).timeout(TIMEOUT); }).timeout(TIMEOUT);
it('exchange contract is deployed', async () => { it('exchange contract is deployed', async () => {
await zeroEx.exchange.getContractAddressAsync(); await (zeroEx.exchange as any)._getExchangeContractAsync();
}).timeout(TIMEOUT); }).timeout(TIMEOUT);
}); });
describe('contracts are deployed on ropsten', () => { describe('contracts are deployed on ropsten', () => {
@@ -49,7 +49,7 @@ describe('Artifacts', () => {
await (zeroEx.token as any)._getTokenTransferProxyAddressAsync(); await (zeroEx.token as any)._getTokenTransferProxyAddressAsync();
}).timeout(TIMEOUT); }).timeout(TIMEOUT);
it('exchange contract is deployed', async () => { it('exchange contract is deployed', async () => {
await zeroEx.exchange.getContractAddressAsync(); await (zeroEx.exchange as any)._getExchangeContractAsync();
}).timeout(TIMEOUT); }).timeout(TIMEOUT);
}); });
}); });

View File

@@ -45,7 +45,7 @@ describe('ExchangeWrapper', () => {
before(async () => { before(async () => {
web3 = web3Factory.create(); web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(web3.currentProvider, config);
exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens); tokenUtils = new TokenUtils(tokens);

View File

@@ -56,7 +56,7 @@ describe('OrderStateWatcher', () => {
before(async () => { before(async () => {
web3 = web3Factory.create(); web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider, config); zeroEx = new ZeroEx(web3.currentProvider, config);
exchangeContractAddress = await zeroEx.exchange.getContractAddressAsync(); exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync(); userAddresses = await zeroEx.getAvailableAddressesAsync();
[, maker, taker] = userAddresses; [, maker, taker] = userAddresses;
tokens = await zeroEx.tokenRegistry.getTokensAsync(); tokens = await zeroEx.tokenRegistry.getTokensAsync();