Skip to content

Commit

Permalink
evm: add multi-transceiver tests and other negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gator-boi committed Mar 20, 2024
1 parent 0d6a720 commit d25c1f6
Show file tree
Hide file tree
Showing 4 changed files with 380 additions and 8 deletions.
6 changes: 6 additions & 0 deletions evm/src/interfaces/INonFungibleNttManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ interface INonFungibleNttManager is IManagerBase {
bytes memory transceiverInstructions
) external payable returns (uint64);

function attestationReceived(
uint16 sourceChainId,
bytes32 sourceNttManagerAddress,
TransceiverStructs.ManagerMessage memory payload
) external;

function executeMsg(
uint16 sourceChainId,
bytes32 sourceNttManagerAddress,
Expand Down
2 changes: 1 addition & 1 deletion evm/src/libraries/TransceiverStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ library TransceiverStructs {
/// This is 0x99'N''F''T'
bytes4 constant NON_FUNGIBLE_NTT_PREFIX = 0x994E4654;

/// @dev Message emitted and received by the nttManager contract.
/// @dev Message emitted and received by any Manager contract variant.
/// The wire format is as follows:
/// - id - 32 bytes
/// - sender - 32 bytes
Expand Down
40 changes: 35 additions & 5 deletions evm/src/mocks/DummyNft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity >=0.8.8 <0.9.0;

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

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

constructor(bytes memory baseUri) ERC721("DummyNft", "DNTF") {
constructor(bytes memory baseUri) ERC721("DummyNft", "DNFT") {
if (baseUri.length == 0) {
revert BaseUriEmpty();
}
Expand Down Expand Up @@ -52,17 +53,46 @@ contract DummyNft is ERC721 {
}

contract DummyNftMintAndBurn is DummyNft {
constructor(bytes memory baseUri) DummyNft(baseUri) {}
bool private reentrant;
address private owner;

constructor(bytes memory baseUri) DummyNft(baseUri) {
owner = msg.sender;
}

function setReentrant(bool enabled) public {
require(msg.sender == owner, "DummyNftMintAndBurn: not owner");
reentrant = enabled;
}

function mint(address to, uint256 tokenId) public override {
// TODO - add access control here?
_safeMint(to, tokenId);

_callback();
}

function burn(uint256 tokenId) public {
// TODO - add access control here?
_burn(tokenId);

_callback();
}

// TODO: Mint/Burn batches.
function safeTransferFrom(address from, address to, uint256 tokenId) public override {
super.safeTransferFrom(from, to, tokenId, "");

_callback();
}

function _callback() public {
if (!reentrant) {
return;
}

uint256[] memory tokenIds = new uint256[](1);
tokenIds[0] = 1;

INonFungibleNttManager(msg.sender).transfer(
tokenIds, 69, bytes32(uint256(uint160(msg.sender))), ""
);
}
}
Loading

0 comments on commit d25c1f6

Please sign in to comment.