diff options
author | Greg Hysen <hysz@users.noreply.github.com> | 2018-06-09 02:58:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-09 02:58:23 +0800 |
commit | 817c332d11835f02726f0609374d1c25c9ab39b5 (patch) | |
tree | d84c9a96465b5e862629be3dd04325dcccdbc780 /packages/contracts/test | |
parent | add9a9db9ba4294cf12489bf589c527b0921ed1e (diff) | |
parent | 05fbc8e6b061e5cef5bb8b8078176f9b375c2ec5 (diff) | |
download | dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.tar dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.tar.gz dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.tar.bz2 dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.tar.lz dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.tar.xz dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.tar.zst dexon-sol-tools-817c332d11835f02726f0609374d1c25c9ab39b5.zip |
Merge pull request #627 from 0xProject/feature/contracts/erc721SafeTransferFrom
On-Chain AssetData Decoding Lib + safeTransferFrom for ERC721 + Memcpy
Diffstat (limited to 'packages/contracts/test')
-rw-r--r-- | packages/contracts/test/asset_proxy/decoder.ts | 103 | ||||
-rw-r--r-- | packages/contracts/test/asset_proxy/proxies.ts | 234 | ||||
-rw-r--r-- | packages/contracts/test/exchange/core.ts | 38 | ||||
-rw-r--r-- | packages/contracts/test/exchange/dispatcher.ts | 8 | ||||
-rw-r--r-- | packages/contracts/test/exchange/libs.ts | 4 | ||||
-rw-r--r-- | packages/contracts/test/exchange/match_orders.ts | 132 | ||||
-rw-r--r-- | packages/contracts/test/exchange/signature_validator.ts | 4 | ||||
-rw-r--r-- | packages/contracts/test/exchange/transactions.ts | 10 | ||||
-rw-r--r-- | packages/contracts/test/exchange/wrapper.ts | 26 | ||||
-rw-r--r-- | packages/contracts/test/libraries/lib_bytes.ts | 224 | ||||
-rw-r--r-- | packages/contracts/test/libraries/lib_mem.ts | 190 |
11 files changed, 752 insertions, 221 deletions
diff --git a/packages/contracts/test/asset_proxy/decoder.ts b/packages/contracts/test/asset_proxy/decoder.ts new file mode 100644 index 000000000..d4fae1601 --- /dev/null +++ b/packages/contracts/test/asset_proxy/decoder.ts @@ -0,0 +1,103 @@ +import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { BigNumber } from '@0xproject/utils'; +import * as chai from 'chai'; +import ethUtil = require('ethereumjs-util'); + +import { TestAssetDataDecodersContract } from '../../src/generated_contract_wrappers/test_asset_data_decoders'; +import { artifacts } from '../../src/utils/artifacts'; +import { chaiSetup } from '../../src/utils/chai_setup'; +import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; + +chaiSetup.configure(); +const expect = chai.expect; +const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + +describe('TestAssetDataDecoders', () => { + let testAssetProxyDecoder: TestAssetDataDecodersContract; + let testAddress: string; + + before(async () => { + await blockchainLifecycle.startAsync(); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); + before(async () => { + // Setup accounts & addresses + const accounts = await web3Wrapper.getAvailableAddressesAsync(); + testAddress = accounts[0]; + // Deploy TestLibMem + testAssetProxyDecoder = await TestAssetDataDecodersContract.deployFrom0xArtifactAsync( + artifacts.TestAssetDataDecoders, + provider, + txDefaults, + ); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + + describe('Asset Data Decoders', () => { + it('should correctly decode ERC20 asset data)', async () => { + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(testAddress); + const expectedDecodedAssetData = assetProxyUtils.decodeERC20AssetData(encodedAssetData); + let decodedAssetProxyId: number; + let decodedTokenAddress: string; + [decodedAssetProxyId, decodedTokenAddress] = await testAssetProxyDecoder.publicDecodeERC20Data.callAsync( + encodedAssetData, + ); + expect(decodedAssetProxyId).to.be.equal(expectedDecodedAssetData.assetProxyId); + expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress); + }); + + it('should correctly decode ERC721 asset data', async () => { + const tokenId = generatePseudoRandomSalt(); + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(testAddress, tokenId); + const expectedDecodedAssetData = assetProxyUtils.decodeERC721AssetData(encodedAssetData); + let decodedAssetProxyId: number; + let decodedTokenAddress: string; + let decodedTokenId: BigNumber; + let decodedData: string; + [ + decodedAssetProxyId, + decodedTokenAddress, + decodedTokenId, + decodedData, + ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedAssetData); + expect(decodedAssetProxyId).to.be.equal(expectedDecodedAssetData.assetProxyId); + expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress); + expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedAssetData.tokenId); + expect(decodedData).to.be.equal(expectedDecodedAssetData.receiverData); + }); + + it('should correctly decode ERC721 asset data with receiver data', async () => { + const tokenId = generatePseudoRandomSalt(); + const receiverDataFirst32Bytes = ethUtil.bufferToHex( + assetProxyUtils.encodeUint256(generatePseudoRandomSalt()), + ); + const receiverDataExtraBytes = 'FFFF'; + // We add extra bytes to generate a value that doesn't fit perfectly into one word + const receiverData = receiverDataFirst32Bytes + receiverDataExtraBytes; + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(testAddress, tokenId, receiverData); + const expectedDecodedAssetData = assetProxyUtils.decodeERC721AssetData(encodedAssetData); + let decodedAssetProxyId: number; + let decodedTokenAddress: string; + let decodedTokenId: BigNumber; + let decodedReceiverData: string; + [ + decodedAssetProxyId, + decodedTokenAddress, + decodedTokenId, + decodedReceiverData, + ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedAssetData); + expect(decodedAssetProxyId).to.be.equal(expectedDecodedAssetData.assetProxyId); + expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress); + expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedAssetData.tokenId); + expect(decodedReceiverData).to.be.equal(expectedDecodedAssetData.receiverData); + }); + }); +}); diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index d14280c5f..08376ccfb 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -1,24 +1,33 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { assetProxyUtils } from '@0xproject/order-utils'; +import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; +import { LogWithDecodedArgs } from 'ethereum-types'; +import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token'; +import { + DummyERC721ReceiverContract, + TokenReceivedContractEventArgs, +} from '../../src/generated_contract_wrappers/dummy_e_r_c721_receiver'; import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token'; import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy'; import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy'; +import { artifacts } from '../../src/utils/artifacts'; import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions'; import { chaiSetup } from '../../src/utils/chai_setup'; import { constants } from '../../src/utils/constants'; import { ERC20Wrapper } from '../../src/utils/erc20_wrapper'; import { ERC721Wrapper } from '../../src/utils/erc721_wrapper'; -import { provider, web3Wrapper } from '../../src/utils/web3_wrapper'; +import { LogDecoder } from '../../src/utils/log_decoder'; +import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); +// tslint:disable:no-unnecessary-type-assertion describe('Asset Transfer Proxies', () => { let owner: string; let notAuthorized: string; @@ -28,6 +37,7 @@ describe('Asset Transfer Proxies', () => { let zrxToken: DummyERC20TokenContract; let erc721Token: DummyERC721TokenContract; + let erc721Receiver: DummyERC721ReceiverContract; let erc20Proxy: ERC20ProxyContract; let erc721Proxy: ERC721ProxyContract; @@ -69,6 +79,11 @@ describe('Asset Transfer Proxies', () => { }), constants.AWAIT_TRANSACTION_MINED_MS, ); + erc721Receiver = await DummyERC721ReceiverContract.deployFrom0xArtifactAsync( + artifacts.DummyERC721Receiver, + provider, + txDefaults, + ); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -79,14 +94,14 @@ describe('Asset Transfer Proxies', () => { describe('Transfer Proxy - ERC20', () => { describe('transferFrom', () => { it('should successfully transfer tokens', async () => { - // Construct metadata for ERC20 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + // Construct ERC20 asset data + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(10); await web3Wrapper.awaitTransactionSuccessAsync( await erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -105,14 +120,14 @@ describe('Asset Transfer Proxies', () => { }); it('should do nothing if transferring 0 amount of a token', async () => { - // Construct metadata for ERC20 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + // Construct ERC20 asset data + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(0); await web3Wrapper.awaitTransactionSuccessAsync( await erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -131,8 +146,8 @@ describe('Asset Transfer Proxies', () => { }); it('should throw if allowances are too low', async () => { - // Construct metadata for ERC20 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + // Construct ERC20 asset data + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); // Create allowance less than transfer amount. Set allowance on proxy. const allowance = new BigNumber(0); const transferAmount = new BigNumber(10); @@ -145,7 +160,7 @@ describe('Asset Transfer Proxies', () => { // Perform a transfer; expect this to fail. return expectRevertOrAlwaysFailingTransactionAsync( erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, transferAmount, @@ -155,20 +170,14 @@ describe('Asset Transfer Proxies', () => { }); it('should throw if requesting address is not authorized', async () => { - // Construct metadata for ERC20 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + // Construct ERC20 asset data + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(10); return expectRevertOrAlwaysFailingTransactionAsync( - erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, - makerAddress, - takerAddress, - amount, - { - from: notAuthorized, - }, - ), + erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, { + from: notAuthorized, + }), ); }); }); @@ -177,16 +186,16 @@ describe('Asset Transfer Proxies', () => { it('should succesfully make multiple token transfers', async () => { const erc20Balances = await erc20Wrapper.getBalancesAsync(); - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); const amount = new BigNumber(10); const numTransfers = 2; - const assetMetadata = _.times(numTransfers, () => encodedProxyMetadata); + const assetData = _.times(numTransfers, () => encodedAssetData); const fromAddresses = _.times(numTransfers, () => makerAddress); const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => amount); const txHash = await erc20Proxy.batchTransferFrom.sendTransactionAsync( - assetMetadata, + assetData, fromAddresses, toAddresses, amounts, @@ -208,22 +217,18 @@ describe('Asset Transfer Proxies', () => { }); it('should throw if not called by an authorized address', async () => { - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); const amount = new BigNumber(10); const numTransfers = 2; - const assetMetadata = _.times(numTransfers, () => encodedProxyMetadata); + const assetData = _.times(numTransfers, () => encodedAssetData); const fromAddresses = _.times(numTransfers, () => makerAddress); const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => amount); return expectRevertOrAlwaysFailingTransactionAsync( - erc20Proxy.batchTransferFrom.sendTransactionAsync( - assetMetadata, - fromAddresses, - toAddresses, - amounts, - { from: notAuthorized }, - ), + erc20Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { + from: notAuthorized, + }), ); }); }); @@ -237,11 +242,8 @@ describe('Asset Transfer Proxies', () => { describe('Transfer Proxy - ERC721', () => { describe('transferFrom', () => { it('should successfully transfer tokens', async () => { - // Construct metadata for ERC721 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData( - erc721Token.address, - erc721MakerTokenId, - ); + // Construct ERC721 asset data + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); // Verify pre-condition const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); @@ -249,7 +251,7 @@ describe('Asset Transfer Proxies', () => { const amount = new BigNumber(1); await web3Wrapper.awaitTransactionSuccessAsync( await erc721Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -262,12 +264,94 @@ describe('Asset Transfer Proxies', () => { expect(newOwnerMakerAsset).to.be.bignumber.equal(takerAddress); }); - it('should throw if transferring 0 amount of a token', async () => { - // Construct metadata for ERC721 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData( + it('should not call onERC721Received when transferring to a smart contract without receiver data', async () => { + // Construct ERC721 asset data + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); + // Verify pre-condition + const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); + expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); + // Perform a transfer from makerAddress to takerAddress + const amount = new BigNumber(1); + const txHash = await erc721Proxy.transferFrom.sendTransactionAsync( + encodedAssetData, + makerAddress, + erc721Receiver.address, + amount, + { from: exchangeAddress }, + ); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + // Parse transaction logs + const logDecoder = new LogDecoder(web3Wrapper, erc721Receiver.address); + const tx = await logDecoder.getTxWithDecodedLogsAsync(txHash); + // Verify that no log was emitted by erc721 receiver + expect(tx.logs.length).to.be.equal(0); + // Verify transfer was successful + const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); + expect(newOwnerMakerAsset).to.be.bignumber.equal(erc721Receiver.address); + }); + + it('should call onERC721Received when transferring to a smart contract with receiver data', async () => { + // Construct ERC721 asset data + const receiverData = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(generatePseudoRandomSalt())); + const encodedAssetData = assetProxyUtils.encodeERC721AssetData( + erc721Token.address, + erc721MakerTokenId, + receiverData, + ); + // Verify pre-condition + const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); + expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); + // Perform a transfer from makerAddress to takerAddress + const amount = new BigNumber(1); + const txHash = await erc721Proxy.transferFrom.sendTransactionAsync( + encodedAssetData, + makerAddress, + erc721Receiver.address, + amount, + { from: exchangeAddress }, + ); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + // Parse transaction logs + const logDecoder = new LogDecoder(web3Wrapper, erc721Receiver.address); + const tx = await logDecoder.getTxWithDecodedLogsAsync(txHash); + // Validate log emitted by erc721 receiver + expect(tx.logs.length).to.be.equal(1); + const tokenReceivedLog = tx.logs[0] as LogWithDecodedArgs<TokenReceivedContractEventArgs>; + expect(tokenReceivedLog.args.from).to.be.equal(makerAddress); + expect(tokenReceivedLog.args.tokenId).to.be.bignumber.equal(erc721MakerTokenId); + expect(tokenReceivedLog.args.data).to.be.equal(receiverData); + // Verify transfer was successful + const newOwnerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); + expect(newOwnerMakerAsset).to.be.bignumber.equal(erc721Receiver.address); + }); + + it('should throw if there is receiver data but contract does not have onERC721Received', async () => { + // Construct ERC721 asset data + const receiverData = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(generatePseudoRandomSalt())); + const encodedAssetData = assetProxyUtils.encodeERC721AssetData( erc721Token.address, erc721MakerTokenId, + receiverData, + ); + // Verify pre-condition + const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); + expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); + // Perform a transfer from makerAddress to takerAddress + const amount = new BigNumber(1); + return expectRevertOrAlwaysFailingTransactionAsync( + erc721Proxy.transferFrom.sendTransactionAsync( + encodedAssetData, + makerAddress, + erc20Proxy.address, // the ERC20 proxy does not have an ERC721 receiver + amount, + { from: exchangeAddress }, + ), ); + }); + + it('should throw if transferring 0 amount of a token', async () => { + // Construct ERC721 asset data + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); // Verify pre-condition const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); @@ -275,7 +359,7 @@ describe('Asset Transfer Proxies', () => { const amount = new BigNumber(0); return expectRevertOrAlwaysFailingTransactionAsync( erc721Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -285,11 +369,8 @@ describe('Asset Transfer Proxies', () => { }); it('should throw if transferring > 1 amount of a token', async () => { - // Construct metadata for ERC721 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData( - erc721Token.address, - erc721MakerTokenId, - ); + // Construct ERC721 asset data + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); // Verify pre-condition const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); @@ -297,7 +378,7 @@ describe('Asset Transfer Proxies', () => { const amount = new BigNumber(500); return expectRevertOrAlwaysFailingTransactionAsync( erc721Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -307,11 +388,8 @@ describe('Asset Transfer Proxies', () => { }); it('should throw if allowances are too low', async () => { - // Construct metadata for ERC721 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData( - erc721Token.address, - erc721MakerTokenId, - ); + // Construct ERC721 asset data + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); // Remove transfer approval for makerAddress. await web3Wrapper.awaitTransactionSuccessAsync( await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, { @@ -322,29 +400,20 @@ describe('Asset Transfer Proxies', () => { // Perform a transfer; expect this to fail. const amount = new BigNumber(1); return expectRevertOrAlwaysFailingTransactionAsync( - erc20Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, - makerAddress, - takerAddress, - amount, - { - from: notAuthorized, - }, - ), + erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, { + from: notAuthorized, + }), ); }); it('should throw if requesting address is not authorized', async () => { - // Construct metadata for ERC721 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData( - erc721Token.address, - erc721MakerTokenId, - ); + // Construct ERC721 asset data + const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(1); return expectRevertOrAlwaysFailingTransactionAsync( erc721Proxy.transferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -360,16 +429,16 @@ describe('Asset Transfer Proxies', () => { const [makerTokenIdA, makerTokenIdB] = erc721TokensById[makerAddress][erc721Token.address]; const numTransfers = 2; - const assetMetadata = [ - assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdA), - assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdB), + const assetData = [ + assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdA), + assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdB), ]; const fromAddresses = _.times(numTransfers, () => makerAddress); const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => new BigNumber(1)); const txHash = await erc721Proxy.batchTransferFrom.sendTransactionAsync( - assetMetadata, + assetData, fromAddresses, toAddresses, amounts, @@ -392,22 +461,18 @@ describe('Asset Transfer Proxies', () => { const [makerTokenIdA, makerTokenIdB] = erc721TokensById[makerAddress][erc721Token.address]; const numTransfers = 2; - const assetMetadata = [ - assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdA), - assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdB), + const assetData = [ + assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdA), + assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdB), ]; const fromAddresses = _.times(numTransfers, () => makerAddress); const toAddresses = _.times(numTransfers, () => takerAddress); const amounts = _.times(numTransfers, () => new BigNumber(1)); return expectRevertOrAlwaysFailingTransactionAsync( - erc721Proxy.batchTransferFrom.sendTransactionAsync( - assetMetadata, - fromAddresses, - toAddresses, - amounts, - { from: notAuthorized }, - ), + erc721Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, { + from: notAuthorized, + }), ); }); }); @@ -418,3 +483,4 @@ describe('Asset Transfer Proxies', () => { }); }); }); +// tslint:enable:no-unnecessary-type-assertion diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index bee74cca8..53b98c755 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -87,7 +87,7 @@ describe('Exchange core', () => { artifacts.Exchange, provider, txDefaults, - assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + assetProxyUtils.encodeERC20AssetData(zrxToken.address), ); exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); @@ -114,8 +114,8 @@ describe('Exchange core', () => { exchangeAddress: exchange.address, makerAddress, feeRecipientAddress, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress), }; const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; orderFactory = new OrderFactory(privateKey, defaultOrderParams); @@ -711,8 +711,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -737,8 +737,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -759,8 +759,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -781,8 +781,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(2), takerAssetAmount: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -803,8 +803,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(500), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -825,8 +825,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(0), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -846,8 +846,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -886,8 +886,8 @@ describe('Exchange core', () => { signedOrder = orderFactory.newSignedOrder({ takerAssetAmount: new BigNumber(1), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerAssetAddress), }); // Verify pre-conditions const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId); diff --git a/packages/contracts/test/exchange/dispatcher.ts b/packages/contracts/test/exchange/dispatcher.ts index 02d43a132..9e113e47d 100644 --- a/packages/contracts/test/exchange/dispatcher.ts +++ b/packages/contracts/test/exchange/dispatcher.ts @@ -275,13 +275,13 @@ describe('AssetProxyDispatcher', () => { constants.AWAIT_TRANSACTION_MINED_MS, ); // Construct metadata for ERC20 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); // Perform a transfer from makerAddress to takerAddress const erc20Balances = await erc20Wrapper.getBalancesAsync(); const amount = new BigNumber(10); await web3Wrapper.awaitTransactionSuccessAsync( await assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, @@ -301,12 +301,12 @@ describe('AssetProxyDispatcher', () => { it('should throw if dispatching to unregistered proxy', async () => { // Construct metadata for ERC20 proxy - const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address); + const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address); // Perform a transfer from makerAddress to takerAddress const amount = new BigNumber(10); return expectRevertOrAlwaysFailingTransactionAsync( assetProxyDispatcher.publicDispatchTransferFrom.sendTransactionAsync( - encodedProxyMetadata, + encodedAssetData, makerAddress, takerAddress, amount, diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index b12934014..eff05981d 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -38,8 +38,8 @@ describe('Exchange libs', () => { exchangeAddress: libs.address, makerAddress, feeRecipientAddress: addressUtils.generatePseudoRandomAddress(), - makerAssetData: assetProxyUtils.encodeERC20ProxyData(addressUtils.generatePseudoRandomAddress()), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(addressUtils.generatePseudoRandomAddress()), + makerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()), + takerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()), }; const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; orderFactory = new OrderFactory(privateKey, defaultOrderParams); diff --git a/packages/contracts/test/exchange/match_orders.ts b/packages/contracts/test/exchange/match_orders.ts index aab3308ae..18a46187f 100644 --- a/packages/contracts/test/exchange/match_orders.ts +++ b/packages/contracts/test/exchange/match_orders.ts @@ -96,7 +96,7 @@ describe('matchOrders', () => { artifacts.Exchange, provider, txDefaults, - assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + assetProxyUtils.encodeERC20AssetData(zrxToken.address), ); exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); @@ -122,8 +122,8 @@ describe('matchOrders', () => { const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, exchangeAddress: exchange.address, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), }; const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)]; orderFactoryLeft = new OrderFactory(privateKeyLeft, defaultOrderParams); @@ -148,16 +148,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -182,16 +180,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -227,16 +223,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(4), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -261,16 +255,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -295,16 +287,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -334,8 +324,8 @@ describe('matchOrders', () => { // branch in the contract twice for this test. const signedOrderRight2 = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -364,8 +354,6 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressLeft, @@ -373,8 +361,8 @@ describe('matchOrders', () => { const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -404,8 +392,6 @@ describe('matchOrders', () => { // branch in the contract twice for this test. const signedOrderLeft2 = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18), feeRecipientAddress: feeRecipientAddressLeft, @@ -437,16 +423,14 @@ describe('matchOrders', () => { const feeRecipientAddress = feeRecipientAddressLeft; const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress, @@ -465,16 +449,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -494,16 +476,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -523,16 +503,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -552,16 +530,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -581,16 +557,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: makerAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: makerAddressRight, @@ -609,16 +583,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -635,16 +607,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -661,16 +631,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -691,16 +659,14 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -721,16 +687,16 @@ describe('matchOrders', () => { // Create orders to match const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(5), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(2), 18), feeRecipientAddress: feeRecipientAddressRight, @@ -752,16 +718,16 @@ describe('matchOrders', () => { const erc721TokenToTransfer = erc721LeftMakerAssetIds[0]; const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), makerAssetAmount: new BigNumber(1), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20TakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: new BigNumber(1), feeRecipientAddress: feeRecipientAddressRight, @@ -787,16 +753,16 @@ describe('matchOrders', () => { const erc721TokenToTransfer = erc721RightMakerAssetIds[0]; const signedOrderLeft = orderFactoryLeft.newSignedOrder({ makerAddress: makerAddressLeft, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer), makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), takerAssetAmount: new BigNumber(1), feeRecipientAddress: feeRecipientAddressLeft, }); const signedOrderRight = orderFactoryRight.newSignedOrder({ makerAddress: makerAddressRight, - makerAssetData: assetProxyUtils.encodeERC721ProxyData(defaultERC721AssetAddress, erc721TokenToTransfer), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultERC20MakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC721AssetData(defaultERC721AssetAddress, erc721TokenToTransfer), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress), makerAssetAmount: new BigNumber(1), takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(10), 18), feeRecipientAddress: feeRecipientAddressRight, diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index 79db620b4..c39fd6ee4 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -42,8 +42,8 @@ describe('MixinSignatureValidator', () => { exchangeAddress: signatureValidator.address, makerAddress, feeRecipientAddress: addressUtils.generatePseudoRandomAddress(), - makerAssetData: assetProxyUtils.encodeERC20ProxyData(addressUtils.generatePseudoRandomAddress()), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(addressUtils.generatePseudoRandomAddress()), + makerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()), + takerAssetData: assetProxyUtils.encodeERC20AssetData(addressUtils.generatePseudoRandomAddress()), }; const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; orderFactory = new OrderFactory(privateKey, defaultOrderParams); diff --git a/packages/contracts/test/exchange/transactions.ts b/packages/contracts/test/exchange/transactions.ts index 7897fa558..12390ce01 100644 --- a/packages/contracts/test/exchange/transactions.ts +++ b/packages/contracts/test/exchange/transactions.ts @@ -72,7 +72,7 @@ describe('Exchange transactions', () => { artifacts.Exchange, provider, txDefaults, - assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + assetProxyUtils.encodeERC20AssetData(zrxToken.address), ); exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); @@ -91,8 +91,8 @@ describe('Exchange transactions', () => { exchangeAddress: exchange.address, makerAddress, feeRecipientAddress, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerTokenAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerTokenAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerTokenAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerTokenAddress), }; makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)]; @@ -224,8 +224,8 @@ describe('Exchange transactions', () => { exchangeAddress: exchange.address, makerAddress, feeRecipientAddress, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerTokenAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerTokenAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerTokenAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerTokenAddress), }; whitelistOrderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams); }); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 258e1ff81..b66cff90a 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -81,7 +81,7 @@ describe('Exchange wrappers', () => { artifacts.Exchange, provider, txDefaults, - assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + assetProxyUtils.encodeERC20AssetData(zrxToken.address), ); exchangeWrapper = new ExchangeWrapper(exchange, provider); await exchangeWrapper.registerAssetProxyAsync(AssetProxyId.ERC20, erc20Proxy.address, owner); @@ -108,8 +108,8 @@ describe('Exchange wrappers', () => { exchangeAddress: exchange.address, makerAddress, feeRecipientAddress, - makerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultMakerAssetAddress), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(defaultTakerAssetAddress), + makerAssetData: assetProxyUtils.encodeERC20AssetData(defaultMakerAssetAddress), + takerAssetData: assetProxyUtils.encodeERC20AssetData(defaultTakerAssetAddress), }; const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; orderFactory = new OrderFactory(privateKey, defaultOrderParams); @@ -304,7 +304,7 @@ describe('Exchange wrappers', () => { const signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: makerZRXBalance, makerFee: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await erc20Wrapper.getBalancesAsync(); @@ -316,7 +316,7 @@ describe('Exchange wrappers', () => { const signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(makerZRXAllowance), makerFee: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await erc20Wrapper.getBalancesAsync(); @@ -328,7 +328,7 @@ describe('Exchange wrappers', () => { const signedOrder = orderFactory.newSignedOrder({ takerAssetAmount: takerZRXBalance, takerFee: new BigNumber(1), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await erc20Wrapper.getBalancesAsync(); @@ -340,7 +340,7 @@ describe('Exchange wrappers', () => { const signedOrder = orderFactory.newSignedOrder({ takerAssetAmount: new BigNumber(takerZRXAllowance), takerFee: new BigNumber(1), - takerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }); await exchangeWrapper.fillOrderNoThrowAsync(signedOrder, takerAddress); const newBalances = await erc20Wrapper.getBalancesAsync(); @@ -354,8 +354,8 @@ describe('Exchange wrappers', () => { const signedOrder = orderFactory.newSignedOrder({ makerAssetAmount: new BigNumber(1), takerAssetAmount: new BigNumber(1), - makerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerAssetId), - takerAssetData: assetProxyUtils.encodeERC721ProxyData(erc721Token.address, takerAssetId), + makerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerAssetId), + takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId), }); // Verify pre-conditions const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId); @@ -692,7 +692,7 @@ describe('Exchange wrappers', () => { signedOrders = [ orderFactory.newSignedOrder(), orderFactory.newSignedOrder({ - takerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }), orderFactory.newSignedOrder(), ]; @@ -785,7 +785,7 @@ describe('Exchange wrappers', () => { signedOrders = [ orderFactory.newSignedOrder(), orderFactory.newSignedOrder({ - takerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + takerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }), orderFactory.newSignedOrder(), ]; @@ -874,7 +874,7 @@ describe('Exchange wrappers', () => { signedOrders = [ orderFactory.newSignedOrder(), orderFactory.newSignedOrder({ - makerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }), orderFactory.newSignedOrder(), ]; @@ -967,7 +967,7 @@ describe('Exchange wrappers', () => { signedOrders = [ orderFactory.newSignedOrder(), orderFactory.newSignedOrder({ - makerAssetData: assetProxyUtils.encodeERC20ProxyData(zrxToken.address), + makerAssetData: assetProxyUtils.encodeERC20AssetData(zrxToken.address), }), orderFactory.newSignedOrder(), ]; diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts index 0996cdc84..2fefb7aeb 100644 --- a/packages/contracts/test/libraries/lib_bytes.ts +++ b/packages/contracts/test/libraries/lib_bytes.ts @@ -1,4 +1,5 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; +import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; import { BigNumber } from '@0xproject/utils'; import BN = require('bn.js'); import * as chai from 'chai'; @@ -28,6 +29,15 @@ describe('LibBytes', () => { let testAddress: string; const testBytes32 = '0x102030405060708090a0b0c0d0e0f0102030405060708090a0b0c0d0e0f01020'; const testUint256 = new BigNumber(testBytes32, 16); + let shortData: string; + let shortTestBytes: string; + let shortTestBytesAsBuffer: Buffer; + let wordOfData: string; + let wordOfTestBytes: string; + let wordOfTestBytesAsBuffer: Buffer; + let longData: string; + let longTestBytes: string; + let longTestBytesAsBuffer: Buffer; before(async () => { await blockchainLifecycle.startAsync(); @@ -48,6 +58,26 @@ describe('LibBytes', () => { expect(byteArrayLongerThan32BytesLength).to.be.greaterThan(32); const testBytes32Length = ethUtil.toBuffer(testBytes32).byteLength; expect(testBytes32Length).to.be.equal(32); + // Create short test bytes + shortData = '0xffffaa'; + const encodedShortData = ethUtil.toBuffer(shortData); + const shortDataLength = new BigNumber(encodedShortData.byteLength); + const encodedShortDataLength = assetProxyUtils.encodeUint256(shortDataLength); + shortTestBytesAsBuffer = Buffer.concat([encodedShortDataLength, encodedShortData]); + shortTestBytes = ethUtil.bufferToHex(shortTestBytesAsBuffer); + // Create test bytes one word in length + wordOfData = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(generatePseudoRandomSalt())); + const encodedWordOfData = ethUtil.toBuffer(wordOfData); + const wordOfDataLength = new BigNumber(encodedWordOfData.byteLength); + const encodedWordOfDataLength = assetProxyUtils.encodeUint256(wordOfDataLength); + wordOfTestBytesAsBuffer = Buffer.concat([encodedWordOfDataLength, encodedWordOfData]); + wordOfTestBytes = ethUtil.bufferToHex(wordOfTestBytesAsBuffer); + // Create long test bytes (combines short test bytes with word of test bytes) + longData = ethUtil.bufferToHex(Buffer.concat([encodedShortData, encodedWordOfData])); + const longDataLength = new BigNumber(encodedShortData.byteLength + encodedWordOfData.byteLength); + const encodedLongDataLength = assetProxyUtils.encodeUint256(longDataLength); + longTestBytesAsBuffer = Buffer.concat([encodedLongDataLength, encodedShortData, encodedWordOfData]); + longTestBytes = ethUtil.bufferToHex(longTestBytesAsBuffer); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -60,7 +90,7 @@ describe('LibBytes', () => { it('should revert if length is 0', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopByte.callAsync(constants.NULL_BYTES), - constants.LIB_BYTES_GT_ZERO_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_THAN_ZERO_LENGTH_REQUIRED, ); }); @@ -77,7 +107,7 @@ describe('LibBytes', () => { it('should revert if length is less than 20', async () => { return expectRevertOrOtherErrorAsync( libBytes.publicPopAddress.callAsync(byteArrayShorterThan20Bytes), - constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, ); }); @@ -163,7 +193,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadAddress.callAsync(shortByteArray, offset), - constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, ); }); @@ -172,7 +202,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(byteArray).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadAddress.callAsync(byteArray, badOffset), - constants.LIB_BYTES_GTE_20_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_20_LENGTH_REQUIRED, ); }); }); @@ -209,7 +239,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes32.callAsync(byteArrayShorterThan32Bytes, offset), - constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, ); }); @@ -217,7 +247,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadBytes32.callAsync(testBytes32, badOffset), - constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, ); }); }); @@ -258,7 +288,7 @@ describe('LibBytes', () => { const offset = new BigNumber(0); return expectRevertOrOtherErrorAsync( libBytes.publicReadUint256.callAsync(byteArrayShorterThan32Bytes, offset), - constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, ); }); @@ -269,7 +299,7 @@ describe('LibBytes', () => { const badOffset = new BigNumber(testUint256AsBuffer.byteLength); return expectRevertOrOtherErrorAsync( libBytes.publicReadUint256.callAsync(byteArray, badOffset), - constants.LIB_BYTES_GTE_32_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, ); }); }); @@ -291,7 +321,7 @@ describe('LibBytes', () => { const byteArrayLessThan4Bytes = '0x010101'; return expectRevertOrOtherErrorAsync( libBytes.publicReadFirst4.callAsync(byteArrayLessThan4Bytes), - constants.LIB_BYTES_GTE_4_LENGTH_REQUIRED, + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED, ); }); it('should return the first 4 bytes of a byte array of arbitrary length', async () => { @@ -300,4 +330,180 @@ describe('LibBytes', () => { expect(first4Bytes).to.equal(expectedFirst4Bytes); }); }); + + describe('readBytes', () => { + it('should successfully read short, nested array of bytes when it takes up the whole array', async () => { + const testBytesOffset = new BigNumber(0); + const bytes = await libBytes.publicReadBytes.callAsync(shortTestBytes, testBytesOffset); + return expect(bytes).to.be.equal(shortData); + }); + + it('should successfully read short, nested array of bytes when it is offset in the array', async () => { + const prefixByteArrayBuffer = ethUtil.toBuffer('0xabcdef'); + const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, shortTestBytesAsBuffer]); + const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer); + const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength); + const bytes = await libBytes.publicReadBytes.callAsync(combinedByteArray, testUint256Offset); + return expect(bytes).to.be.equal(shortData); + }); + + it('should successfully read a nested array of bytes - one word in length - when it takes up the whole array', async () => { + const testBytesOffset = new BigNumber(0); + const bytes = await libBytes.publicReadBytes.callAsync(wordOfTestBytes, testBytesOffset); + return expect(bytes).to.be.equal(wordOfData); + }); + + it('should successfully read a nested array of bytes - one word in length - when it is offset in the array', async () => { + const prefixByteArrayBuffer = ethUtil.toBuffer('0xabcdef'); + const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, wordOfTestBytesAsBuffer]); + const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer); + const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength); + const bytes = await libBytes.publicReadBytes.callAsync(combinedByteArray, testUint256Offset); + return expect(bytes).to.be.equal(wordOfData); + }); + + it('should successfully read long, nested array of bytes when it takes up the whole array', async () => { + const testBytesOffset = new BigNumber(0); + const bytes = await libBytes.publicReadBytes.callAsync(longTestBytes, testBytesOffset); + return expect(bytes).to.be.equal(longData); + }); + + it('should successfully read long, nested array of bytes when it is offset in the array', async () => { + const prefixByteArrayBuffer = ethUtil.toBuffer('0xabcdef'); + const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, longTestBytesAsBuffer]); + const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer); + const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength); + const bytes = await libBytes.publicReadBytes.callAsync(combinedByteArray, testUint256Offset); + return expect(bytes).to.be.equal(longData); + }); + + it('should fail if the byte array is too short to hold the length of a nested byte array', async () => { + // The length of the nested array is 32 bytes. By storing less than 32 bytes, a length cannot be read. + const offset = new BigNumber(0); + return expectRevertOrOtherErrorAsync( + libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, offset), + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ); + }); + + it('should fail if we store a nested byte array length, without a nested byte array', async () => { + const offset = new BigNumber(0); + return expectRevertOrOtherErrorAsync( + libBytes.publicReadBytes.callAsync(testBytes32, offset), + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED, + ); + }); + + it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => { + const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength); + return expectRevertOrOtherErrorAsync( + libBytes.publicReadBytes.callAsync(byteArrayShorterThan32Bytes, badOffset), + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ); + }); + + it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => { + const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); + return expectRevertOrOtherErrorAsync( + libBytes.publicReadBytes.callAsync(testBytes32, badOffset), + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_32_LENGTH_REQUIRED, + ); + }); + }); + + describe('writeBytes', () => { + it('should successfully write short, nested array of bytes when it takes up the whole array)', async () => { + const testBytesOffset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex(new Buffer(shortTestBytesAsBuffer.byteLength)); + const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, shortData); + const bytesRead = await libBytes.publicReadBytes.callAsync(bytesWritten, testBytesOffset); + return expect(bytesRead).to.be.equal(shortData); + }); + + it('should successfully write short, nested array of bytes when it is offset in the array', async () => { + // Write a prefix to the array + const prefixData = '0xabcdef'; + const prefixDataAsBuffer = ethUtil.toBuffer(prefixData); + const prefixOffset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex( + new Buffer(prefixDataAsBuffer.byteLength + shortTestBytesAsBuffer.byteLength), + ); + let bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, prefixOffset, prefixData); + // Write data after prefix + const testBytesOffset = new BigNumber(prefixDataAsBuffer.byteLength); + bytesWritten = await libBytes.publicWriteBytes.callAsync(bytesWritten, testBytesOffset, shortData); + // Read data after prefix and validate + const bytes = await libBytes.publicReadBytes.callAsync(bytesWritten, testBytesOffset); + return expect(bytes).to.be.equal(shortData); + }); + + it('should successfully write a nested array of bytes - one word in length - when it takes up the whole array', async () => { + const testBytesOffset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex(new Buffer(wordOfTestBytesAsBuffer.byteLength)); + const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, wordOfData); + const bytesRead = await libBytes.publicReadBytes.callAsync(bytesWritten, testBytesOffset); + return expect(bytesRead).to.be.equal(wordOfData); + }); + + it('should successfully write a nested array of bytes - one word in length - when it is offset in the array', async () => { + // Write a prefix to the array + const prefixData = '0xabcdef'; + const prefixDataAsBuffer = ethUtil.toBuffer(prefixData); + const prefixOffset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex( + new Buffer(prefixDataAsBuffer.byteLength + wordOfTestBytesAsBuffer.byteLength), + ); + let bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, prefixOffset, prefixData); + // Write data after prefix + const testBytesOffset = new BigNumber(prefixDataAsBuffer.byteLength); + bytesWritten = await libBytes.publicWriteBytes.callAsync(bytesWritten, testBytesOffset, wordOfData); + // Read data after prefix and validate + const bytes = await libBytes.publicReadBytes.callAsync(bytesWritten, testBytesOffset); + return expect(bytes).to.be.equal(wordOfData); + }); + + it('should successfully write a long, nested bytes when it takes up the whole array', async () => { + const testBytesOffset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex(new Buffer(longTestBytesAsBuffer.byteLength)); + const bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, testBytesOffset, longData); + const bytesRead = await libBytes.publicReadBytes.callAsync(bytesWritten, testBytesOffset); + return expect(bytesRead).to.be.equal(longData); + }); + + it('should successfully write long, nested array of bytes when it is offset in the array', async () => { + // Write a prefix to the array + const prefixData = '0xabcdef'; + const prefixDataAsBuffer = ethUtil.toBuffer(prefixData); + const prefixOffset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex( + new Buffer(prefixDataAsBuffer.byteLength + longTestBytesAsBuffer.byteLength), + ); + let bytesWritten = await libBytes.publicWriteBytes.callAsync(emptyByteArray, prefixOffset, prefixData); + // Write data after prefix + const testBytesOffset = new BigNumber(prefixDataAsBuffer.byteLength); + bytesWritten = await libBytes.publicWriteBytes.callAsync(bytesWritten, testBytesOffset, longData); + // Read data after prefix and validate + const bytes = await libBytes.publicReadBytes.callAsync(bytesWritten, testBytesOffset); + return expect(bytes).to.be.equal(longData); + }); + + it('should fail if the byte array is too short to hold the length of a nested byte array', async () => { + const offset = new BigNumber(0); + const emptyByteArray = ethUtil.bufferToHex(new Buffer(1)); + return expectRevertOrOtherErrorAsync( + libBytes.publicWriteBytes.callAsync(emptyByteArray, offset, longData), + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED, + ); + }); + + it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array)', async () => { + const emptyByteArray = ethUtil.bufferToHex(new Buffer(shortTestBytesAsBuffer.byteLength)); + const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength); + return expectRevertOrOtherErrorAsync( + libBytes.publicWriteBytes.callAsync(emptyByteArray, badOffset, shortData), + constants.LIB_BYTES_GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED, + ); + }); + }); }); +// tslint:disable:max-file-line-count diff --git a/packages/contracts/test/libraries/lib_mem.ts b/packages/contracts/test/libraries/lib_mem.ts new file mode 100644 index 000000000..90d54edcb --- /dev/null +++ b/packages/contracts/test/libraries/lib_mem.ts @@ -0,0 +1,190 @@ +import { BigNumber } from '@0xproject/utils'; +import * as chai from 'chai'; + +import { TestLibMemContract } from '../../src/generated_contract_wrappers/test_lib_mem'; +import { artifacts } from '../../src/utils/artifacts'; +import { chaiSetup } from '../../src/utils/chai_setup'; +import { provider, txDefaults } from '../../src/utils/web3_wrapper'; + +chaiSetup.configure(); +const expect = chai.expect; + +// BUG: Ideally we would use Buffer.from(memory).toString('hex') +// https://github.com/Microsoft/TypeScript/issues/23155 +const toHex = (buf: Uint8Array): string => buf.reduce((a, v) => a + ('00' + v.toString(16)).slice(-2), '0x'); + +const fromHex = (str: string): Uint8Array => Uint8Array.from(Buffer.from(str.slice(2), 'hex')); + +describe('LibMem', () => { + let testLibMem: TestLibMemContract; + + before(async () => { + // Deploy TestLibMem + testLibMem = await TestLibMemContract.deployFrom0xArtifactAsync(artifacts.TestLibMem, provider, txDefaults); + }); + + describe('memCopy', () => { + // Create memory 0x000102...FF + const memSize = 256; + const memory = new Uint8Array(memSize).map((_, i) => i); + const memHex = toHex(memory); + + // Reference implementation to test against + const refMemcpy = (mem: Uint8Array, dest: number, source: number, length: number): Uint8Array => + Uint8Array.from(memory).copyWithin(dest, source, source + length); + + // Test vectors: destination, source, length, job description + type Tests = Array<[number, number, number, string]>; + + const test = (tests: Tests) => + tests.forEach(([dest, source, length, job]) => + it(job, async () => { + const expected = refMemcpy(memory, dest, source, length); + const resultStr = await testLibMem.testMemcpy.callAsync( + memHex, + new BigNumber(dest), + new BigNumber(source), + new BigNumber(length), + ); + const result = fromHex(resultStr); + expect(result).to.deep.equal(expected); + }), + ); + + test([[0, 0, 0, 'copies zero bytes with overlap']]); + + describe('copies forward', () => + test([ + [128, 0, 0, 'zero bytes'], + [128, 0, 1, 'one byte'], + [128, 0, 11, 'eleven bytes'], + [128, 0, 31, 'thirty-one bytes'], + [128, 0, 32, 'one word'], + [128, 0, 64, 'two words'], + [128, 0, 96, 'three words'], + [128, 0, 33, 'one word and one byte'], + [128, 0, 72, 'two words and eight bytes'], + [128, 0, 100, 'three words and four bytes'], + ])); + + describe('copies forward within one word', () => + test([ + [16, 0, 0, 'zero bytes'], + [16, 0, 1, 'one byte'], + [16, 0, 11, 'eleven bytes'], + [16, 0, 16, 'sixteen bytes'], + ])); + + describe('copies forward with one byte overlap', () => + test([ + [0, 0, 1, 'one byte'], + [10, 0, 11, 'eleven bytes'], + [30, 0, 31, 'thirty-one bytes'], + [31, 0, 32, 'one word'], + [32, 0, 33, 'one word and one byte'], + [71, 0, 72, 'two words and eight bytes'], + [99, 0, 100, 'three words and four bytes'], + ])); + + describe('copies forward with thirty-one bytes overlap', () => + test([ + [0, 0, 31, 'thirty-one bytes'], + [1, 0, 32, 'one word'], + [2, 0, 33, 'one word and one byte'], + [41, 0, 72, 'two words and eight bytes'], + [69, 0, 100, 'three words and four bytes'], + ])); + + describe('copies forward with one word overlap', () => + test([ + [0, 0, 32, 'one word'], + [1, 0, 33, 'one word and one byte'], + [41, 0, 72, 'two words and eight bytes'], + [69, 0, 100, 'three words and four bytes'], + ])); + + describe('copies forward with one word and one byte overlap', () => + test([ + [0, 0, 33, 'one word and one byte'], + [40, 0, 72, 'two words and eight bytes'], + [68, 0, 100, 'three words and four bytes'], + ])); + + describe('copies forward with two words overlap', () => + test([ + [0, 0, 64, 'two words'], + [8, 0, 72, 'two words and eight bytes'], + [36, 0, 100, 'three words and four bytes'], + ])); + + describe('copies forward within one word and one byte overlap', () => + test([[0, 0, 1, 'one byte'], [10, 0, 11, 'eleven bytes'], [15, 0, 16, 'sixteen bytes']])); + + describe('copies backward', () => + test([ + [0, 128, 0, 'zero bytes'], + [0, 128, 1, 'one byte'], + [0, 128, 11, 'eleven bytes'], + [0, 128, 31, 'thirty-one bytes'], + [0, 128, 32, 'one word'], + [0, 128, 64, 'two words'], + [0, 128, 96, 'three words'], + [0, 128, 33, 'one word and one byte'], + [0, 128, 72, 'two words and eight bytes'], + [0, 128, 100, 'three words and four bytes'], + ])); + + describe('copies backward within one word', () => + test([ + [0, 16, 0, 'zero bytes'], + [0, 16, 1, 'one byte'], + [0, 16, 11, 'eleven bytes'], + [0, 16, 16, 'sixteen bytes'], + ])); + + describe('copies backward with one byte overlap', () => + test([ + [0, 0, 1, 'one byte'], + [0, 10, 11, 'eleven bytes'], + [0, 30, 31, 'thirty-one bytes'], + [0, 31, 32, 'one word'], + [0, 32, 33, 'one word and one byte'], + [0, 71, 72, 'two words and eight bytes'], + [0, 99, 100, 'three words and four bytes'], + ])); + + describe('copies backward with thirty-one bytes overlap', () => + test([ + [0, 0, 31, 'thirty-one bytes'], + [0, 1, 32, 'one word'], + [0, 2, 33, 'one word and one byte'], + [0, 41, 72, 'two words and eight bytes'], + [0, 69, 100, 'three words and four bytes'], + ])); + + describe('copies backward with one word overlap', () => + test([ + [0, 0, 32, 'one word'], + [0, 1, 33, 'one word and one byte'], + [0, 41, 72, 'two words and eight bytes'], + [0, 69, 100, 'three words and four bytes'], + ])); + + describe('copies backward with one word and one byte overlap', () => + test([ + [0, 0, 33, 'one word and one byte'], + [0, 40, 72, 'two words and eight bytes'], + [0, 68, 100, 'three words and four bytes'], + ])); + + describe('copies backward with two words overlap', () => + test([ + [0, 0, 64, 'two words'], + [0, 8, 72, 'two words and eight bytes'], + [0, 36, 100, 'three words and four bytes'], + ])); + + describe('copies forward within one word and one byte overlap', () => + test([[0, 0, 1, 'one byte'], [0, 10, 11, 'eleven bytes'], [0, 15, 16, 'sixteen bytes']])); + }); +}); |