diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2019-02-09 06:46:39 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2019-02-09 09:12:54 +0800 |
commit | 500b4940a320c842394c996f15495c1cdc7b3547 (patch) | |
tree | 53433c0b22e2d6db482e6b2be5b94f2a4c1e6d21 /packages/contract-wrappers | |
parent | 6d0dc47157f7cc17f1f3da7a1960456e4ae9bede (diff) | |
download | dexon-0x-contracts-500b4940a320c842394c996f15495c1cdc7b3547.tar.gz dexon-0x-contracts-500b4940a320c842394c996f15495c1cdc7b3547.tar.zst dexon-0x-contracts-500b4940a320c842394c996f15495c1cdc7b3547.zip |
Improvements and conventions in utils package + abi decoder
Diffstat (limited to 'packages/contract-wrappers')
4 files changed, 16 insertions, 12 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index bd9a377ed..f43dc5d26 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -172,8 +172,8 @@ export class ContractWrappers { return this._web3Wrapper.getProvider(); } /** - * Get the provider instance currently used by contract-wrappers - * @return Web3 provider instance + * Get the abi decoder instance currently used by contract-wrappers + * @return AbiDecoder instance */ public getAbiDecoder(): AbiDecoder { return this._web3Wrapper.abiDecoder; diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 5eaf6118f..5fc400edf 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -38,7 +38,7 @@ export { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper'; export { TransactionEncoder } from './utils/transaction_encoder'; -export { AbiDecoder, TransactionData } from '@0x/utils'; +export { AbiDecoder, DecodedCalldata } from '@0x/utils'; export { ContractWrappersError, diff --git a/packages/contract-wrappers/src/utils/transaction_encoder.ts b/packages/contract-wrappers/src/utils/transaction_encoder.ts index 8bf67ee56..0832ee73a 100644 --- a/packages/contract-wrappers/src/utils/transaction_encoder.ts +++ b/packages/contract-wrappers/src/utils/transaction_encoder.ts @@ -248,8 +248,8 @@ export class TransactionEncoder { * @return Hex encoded abi of the function call. */ public matchOrdersTx(leftOrder: SignedOrder, rightOrder: SignedOrder): string { - assert.doesConformToSchema('order', leftOrder, schemas.orderSchema); - assert.doesConformToSchema('order', rightOrder, schemas.orderSchema); + assert.doesConformToSchema('leftOrder', leftOrder, schemas.orderSchema); + assert.doesConformToSchema('rightOrder', rightOrder, schemas.orderSchema); const abiEncodedData = this._getExchangeContract().matchOrders.getABIEncodedTransactionData( leftOrder, rightOrder, diff --git a/packages/contract-wrappers/test/calldata_decoder_test.ts b/packages/contract-wrappers/test/calldata_decoder_test.ts index d44e13a89..ba1539ef5 100644 --- a/packages/contract-wrappers/test/calldata_decoder_test.ts +++ b/packages/contract-wrappers/test/calldata_decoder_test.ts @@ -33,12 +33,12 @@ describe('ABI Decoding Calldata', () => { before(async () => { // Create accounts const accounts = await web3Wrapper.getAvailableAddressesAsync(); - const [makerAddressLeft, makerAddressRight] = accounts.slice(0, 2); + const [makerAddressLeft, makerAddressRight] = accounts; + const [privateKeyLeft, privateKeyRight] = constants.TESTRPC_PRIVATE_KEYS; const exchangeAddress = addressUtils.generatePseudoRandomAddress(); const feeRecipientAddress = addressUtils.generatePseudoRandomAddress(); - const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)]; - const privateKeyRight = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressRight)]; - // Create orders to match + // Create orders to match. + // Values are arbitrary, with the exception of maker addresses (generated above). orderLeft = { makerAddress: makerAddressLeft, makerAssetData: assetDataUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), @@ -87,7 +87,9 @@ describe('ABI Decoding Calldata', () => { describe('decode', () => { it('should successfully decode DutchAuction.matchOrders calldata', async () => { const contractName = 'DutchAuction'; - const decodedTxData = contractWrappers.getAbiDecoder().tryDecodeCalldata(matchOrdersTxData, contractName); + const decodedTxData = contractWrappers + .getAbiDecoder() + .decodeCalldataOrThrow(matchOrdersTxData, contractName); const expectedFunctionName = 'matchOrders'; const expectedFunctionArguments = { buyOrder: orderLeft, @@ -101,7 +103,9 @@ describe('ABI Decoding Calldata', () => { }); it('should successfully decode Exchange.matchOrders calldata (and distinguish from DutchAuction.matchOrders)', async () => { const contractName = 'Exchange'; - const decodedTxData = contractWrappers.getAbiDecoder().tryDecodeCalldata(matchOrdersTxData, contractName); + const decodedTxData = contractWrappers + .getAbiDecoder() + .decodeCalldataOrThrow(matchOrdersTxData, contractName); const expectedFunctionName = 'matchOrders'; const expectedFunctionArguments = { leftOrder: orderLeft, @@ -116,7 +120,7 @@ describe('ABI Decoding Calldata', () => { it('should throw if cannot decode calldata', async () => { const badTxData = '0x01020304'; expect(() => { - contractWrappers.getAbiDecoder().tryDecodeCalldata(badTxData); + contractWrappers.getAbiDecoder().decodeCalldataOrThrow(badTxData); }).to.throw("No functions registered for selector '0x01020304'"); }); }); |