Skip to content

Commit

Permalink
fix: send batch nft internal call err
Browse files Browse the repository at this point in the history
  • Loading branch information
noyyyy committed Dec 1, 2023
1 parent 9576b3d commit 677d275
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/dev/src/bridge/GalxeBadgeReceiverV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ contract GalxeBadgeReceiverV2 is IBadgeReceiverV2, Ownable, IERC721Receiver {
_sendNFT(nftAddr, dstChainId, tokenId, receiver);
}

function sendBatchNFT(address nftAddr, uint256[] calldata tokenIds) external {
function sendBatchNFT(address nftAddr, uint256 dstChainId, uint256[] calldata tokenIds, address receiver)
external
{
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
_burnNFT(nftAddr, tokenId);
_sendNFT(nftAddr, dstChainId, tokenId, receiver);
}
}

Expand Down
36 changes: 33 additions & 3 deletions packages/dev/test/uint/concrete/GBR_V2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import {IBadgeReceiverV2Def} from "src/bridge/interfaces/IBadgeReceiverV2.sol";
import {Constant} from "src/libraries/Constant.sol";

contract GBR_V2_Test is GalxeBadgeReceiverV2Test, IBadgeReceiverV2Def {
function testUpdateValidNftAddr(address nftAddr, bool valid) public {
function test_UpdateValidNftAddr(address nftAddr, bool valid) public {
changePrank(users.admin);
assertEq(galxeBadgeReceiverV2.whitelistNFT(nftAddr), false);
emit ValidNftAddrSet(nftAddr, valid);
galxeBadgeReceiverV2.updateValidNftAddr(nftAddr, valid);
assertEq(galxeBadgeReceiverV2.whitelistNFT(nftAddr), valid);
}

function testUpdateSigner(address signer, bool valid) public {
function test_UpdateSigner(address signer, bool valid) public {
changePrank(users.admin);
assertEq(galxeBadgeReceiverV2.signers(signer), false);
emit SignerSet(signer, valid);
galxeBadgeReceiverV2.updateSigner(signer, valid);
assertEq(galxeBadgeReceiverV2.signers(signer), valid);
}

function testUpdateDstValidity(uint256 chainId, bool valid) public {
function test_UpdateDstValidity(uint256 chainId, bool valid) public {
changePrank(users.admin);
assertEq(galxeBadgeReceiverV2.allowedDst(chainId), false);
emit DstValidSet(chainId, valid);
Expand Down Expand Up @@ -66,6 +66,36 @@ contract GBR_V2_Test is GalxeBadgeReceiverV2Test, IBadgeReceiverV2Def {
assertEq(starNFT.ownerOf(1), address(galxeBadgeReceiverV2));
}

function test_SendBatchNFT_Successfully() public {
changePrank(users.admin);
galxeBadgeReceiverV2.updateValidNftAddr(address(starNFT), true);
galxeBadgeReceiverV2.updateDstValidity(1, true);

changePrank(users.alice);

assertEq(starNFT.ownerOf(2), users.alice);
assertEq(starNFT.ownerOf(3), users.alice);
assertEq(starNFT.ownerOf(4), users.alice);

// check event emit
vm.expectEmit(true, true, true, true);
emit SendNFT(1, 2, 2, address(starNFT), users.alice, users.alice);
emit SendNFT(1, 3, 2, address(starNFT), users.alice, users.alice);
emit SendNFT(1, 4, 3, address(starNFT), users.alice, users.alice);

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

galxeBadgeReceiverV2.sendBatchNFT(address(starNFT), 1, tokenIds, users.alice);

// check owner change
assertEq(starNFT.ownerOf(2), address(galxeBadgeReceiverV2));
assertEq(starNFT.ownerOf(3), address(galxeBadgeReceiverV2));
assertEq(starNFT.ownerOf(4), address(galxeBadgeReceiverV2));
}

function test_BurnNFT_Revert_InvalidNFTAddr() public {
changePrank(users.alice);

Expand Down

0 comments on commit 677d275

Please sign in to comment.