Skip to content

Commit e5ceb49

Browse files
authored
Merge pull request #241 from 0xcert/test-extcodehash
WIP: test code hash
2 parents 8ecfc29 + b54b834 commit e5ceb49

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/tests/mocks/nf-token-receiver-test-mock.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "../../contracts/tokens/erc721-token-receiver.sol";
66
contract NFTokenReceiverTestMock is
77
ERC721TokenReceiver
88
{
9+
event Received();
910

1011
function onERC721Received(
1112
address _operator,
@@ -14,14 +15,14 @@ contract NFTokenReceiverTestMock is
1415
bytes calldata _data
1516
)
1617
external
17-
pure
1818
override
1919
returns(bytes4)
2020
{
2121
_operator;
2222
_from;
2323
_tokenId;
2424
_data;
25+
emit Received();
2526
return 0x150b7a02;
2627
}
2728

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.6;
3+
4+
import "../../contracts/mocks/nf-token-mock.sol";
5+
import "./nf-token-receiver-test-mock.sol";
6+
7+
contract SendsToSelfOnConstruct is
8+
NFTokenReceiverTestMock
9+
{
10+
uint constant TOKEN_ID = 1;
11+
12+
constructor()
13+
{
14+
NFTokenMock tokens = new NFTokenMock();
15+
tokens.mint(address(this), TOKEN_ID);
16+
tokens.safeTransferFrom(address(this), address(this), TOKEN_ID);
17+
}
18+
19+
}

src/tests/tokens/nf-token.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,17 @@ spec.test('throws when trying to burn non existant NFT', async (ctx) => {
397397
const id1 = ctx.get('id1');
398398

399399
await ctx.reverts(() => nftoken.instance.methods.burn(id1).send({ from: owner }), '003002');
400-
});
400+
});
401+
402+
spec.test('safeTransfer does not call onERC721Received to constructing contract', async (ctx) => {
403+
const sendsToSelfOnConstruct = await ctx.deploy({
404+
src: './build/sends-to-self-on-construct.json',
405+
contract: 'SendsToSelfOnConstruct',
406+
});
407+
408+
const logs = sendsToSelfOnConstruct.receipt.logs;
409+
ctx.is(logs.length, 2); // There need to be 2 logs. First transfer event for creating the token. Second transfer event for sending yourself a token.
410+
// There must not be a Receive event.
411+
ctx.is(logs[0].topics[0], '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'); // this represents transfer topic hash
412+
ctx.is(logs[1].topics[0], '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'); // this represents transfer topic hash
413+
});

0 commit comments

Comments
 (0)