Skip to content

Commit 1a7aae1

Browse files
committed
evm: add multi-transceiver tests and other negative tests
1 parent c7c90a9 commit 1a7aae1

File tree

4 files changed

+380
-8
lines changed

4 files changed

+380
-8
lines changed

evm/src/interfaces/INonFungibleNttManager.sol

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ interface INonFungibleNttManager is IManagerBase {
8787
bytes memory transceiverInstructions
8888
) external payable returns (uint64);
8989

90+
function attestationReceived(
91+
uint16 sourceChainId,
92+
bytes32 sourceNttManagerAddress,
93+
TransceiverStructs.ManagerMessage memory payload
94+
) external;
95+
9096
function executeMsg(
9197
uint16 sourceChainId,
9298
bytes32 sourceNttManagerAddress,

evm/src/libraries/TransceiverStructs.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library TransceiverStructs {
2929
/// This is 0x99'N''F''T'
3030
bytes4 constant NON_FUNGIBLE_NTT_PREFIX = 0x994E4654;
3131

32-
/// @dev Message emitted and received by the nttManager contract.
32+
/// @dev Message emitted and received by any Manager contract variant.
3333
/// The wire format is as follows:
3434
/// - id - 32 bytes
3535
/// - sender - 32 bytes

evm/src/mocks/DummyNft.sol

+35-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pragma solidity >=0.8.8 <0.9.0;
44

55
import {ERC721} from "openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
6+
import {INonFungibleNttManager} from "../interfaces/INonFungibleNttManager.sol";
67

78
contract DummyNft is ERC721 {
89
// Common URI for all NFTs handled by this contract.
@@ -12,7 +13,7 @@ contract DummyNft is ERC721 {
1213
error BaseUriEmpty();
1314
error BaseUriTooLong();
1415

15-
constructor(bytes memory baseUri) ERC721("DummyNft", "DNTF") {
16+
constructor(bytes memory baseUri) ERC721("DummyNft", "DNFT") {
1617
if (baseUri.length == 0) {
1718
revert BaseUriEmpty();
1819
}
@@ -52,17 +53,46 @@ contract DummyNft is ERC721 {
5253
}
5354

5455
contract DummyNftMintAndBurn is DummyNft {
55-
constructor(bytes memory baseUri) DummyNft(baseUri) {}
56+
bool private reentrant;
57+
address private owner;
58+
59+
constructor(bytes memory baseUri) DummyNft(baseUri) {
60+
owner = msg.sender;
61+
}
62+
63+
function setReentrant(bool enabled) public {
64+
require(msg.sender == owner, "DummyNftMintAndBurn: not owner");
65+
reentrant = enabled;
66+
}
5667

5768
function mint(address to, uint256 tokenId) public override {
58-
// TODO - add access control here?
5969
_safeMint(to, tokenId);
70+
71+
_callback();
6072
}
6173

6274
function burn(uint256 tokenId) public {
63-
// TODO - add access control here?
6475
_burn(tokenId);
76+
77+
_callback();
6578
}
6679

67-
// TODO: Mint/Burn batches.
80+
function safeTransferFrom(address from, address to, uint256 tokenId) public override {
81+
super.safeTransferFrom(from, to, tokenId, "");
82+
83+
_callback();
84+
}
85+
86+
function _callback() public {
87+
if (!reentrant) {
88+
return;
89+
}
90+
91+
uint256[] memory tokenIds = new uint256[](1);
92+
tokenIds[0] = 1;
93+
94+
INonFungibleNttManager(msg.sender).transfer(
95+
tokenIds, 69, bytes32(uint256(uint160(msg.sender))), ""
96+
);
97+
}
6898
}

0 commit comments

Comments
 (0)