diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-06-01 09:59:02 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-06-08 06:38:48 +0800 |
commit | 8496c1cdd3bc477fcfe584adf8200f4ed35da2b0 (patch) | |
tree | 078dc48542a8a73da8217d7e6ce990c674aab303 /packages/contracts/test/asset_proxy/proxies.ts | |
parent | 3c3851c221873baf3b7fec7213324dae0c1c3351 (diff) | |
download | dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.tar dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.tar.gz dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.tar.bz2 dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.tar.lz dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.tar.xz dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.tar.zst dexon-sol-tools-8496c1cdd3bc477fcfe584adf8200f4ed35da2b0.zip |
Call safeTransferFrom only when there is receiver data present
Diffstat (limited to 'packages/contracts/test/asset_proxy/proxies.ts')
-rw-r--r-- | packages/contracts/test/asset_proxy/proxies.ts | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts index d6bc8163b..f44c44045 100644 --- a/packages/contracts/test/asset_proxy/proxies.ts +++ b/packages/contracts/test/asset_proxy/proxies.ts @@ -280,7 +280,7 @@ describe('Asset Transfer Proxies', () => { expect(newOwnerMakerAsset).to.be.bignumber.equal(takerAddress); }); - it('should call onERC721Received when transferring to a smart contract', async () => { + it('should not call onERC721Received when transferring to a smart contract without receiver data', async () => { // Construct metadata for ERC721 proxy const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); // Verify pre-condition @@ -296,23 +296,20 @@ describe('Asset Transfer Proxies', () => { amount, { from: exchangeAddress }, ); + // Parse transaction logs const tx = await zeroEx.awaitTransactionMinedAsync(txHash); tx.logs = _.filter(tx.logs, log => log.address === erc721Receiver.address); const logDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID); tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log)); - // 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(nullDataHex); + // 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 and receive extra data', async () => { + it('should call onERC721Received when transferring to a smart contract with receiver data', async () => { // Construct metadata for ERC721 proxy const data = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(ZeroEx.generatePseudoRandomSalt())); const encodedAssetData = assetProxyUtils.encodeERC721AssetData( @@ -338,7 +335,7 @@ describe('Asset Transfer Proxies', () => { tx.logs = _.filter(tx.logs, log => log.address === erc721Receiver.address); const logDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID); tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log)); - // Validate log emitted by erc721 receiver + // 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); @@ -349,9 +346,14 @@ describe('Asset Transfer Proxies', () => { expect(newOwnerMakerAsset).to.be.bignumber.equal(erc721Receiver.address); }); - it('should throw if receiving contract does not have onERC721Received', async () => { + it('should throw if there is receiver data but contract does not have onERC721Received', async () => { // Construct metadata for ERC721 proxy - const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId); + const data = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(ZeroEx.generatePseudoRandomSalt())); + const encodedAssetData = assetProxyUtils.encodeERC721AssetData( + erc721Token.address, + erc721MakerTokenId, + data, + ); // Verify pre-condition const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId); expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress); |