-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity >=0.8.19; | ||
|
||
library Constant { | ||
address constant BLACK_HOLE_ADDRESS = address(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity >=0.8.19; | ||
|
||
import {ERC721} from "solady/tokens/ERC721.sol"; | ||
import {IStarNFT} from "src/bridge/interfaces/IStarNFT.sol"; | ||
|
||
contract StarNFT is ERC721, IStarNFT { | ||
mapping(uint256 => uint256) internal _cid; | ||
|
||
function mint(address user, uint256 tokenId, uint256 cid_) public { | ||
_mint(user, tokenId); | ||
_cid[tokenId] = cid_; | ||
} | ||
|
||
function cid(uint256 tokenId) public view override returns (uint256) { | ||
return _cid[tokenId]; | ||
} | ||
|
||
function name() public pure override returns (string memory) { | ||
return "Star NFT"; | ||
} | ||
|
||
function symbol() public pure override returns (string memory) { | ||
return "SNFT"; | ||
} | ||
|
||
function tokenURI(uint256) public pure override returns (string memory) { | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import {GalxeBadgeReceiverV2Test} from "test/uint/shared/GalxeBadgeReceiverV2.t.sol"; | ||
import {IBadgeReceiverV2Def} from "src/bridge/interfaces/IBadgeReceiverV2.sol"; | ||
import {Constant} from "src/libraries/Constant.sol"; | ||
|
||
contract GBRV2_Test is GalxeBadgeReceiverV2Test, IBadgeReceiverV2Def { | ||
function testUpdateValidNftAddr(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 { | ||
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 { | ||
changePrank(users.admin); | ||
assertEq(galxeBadgeReceiverV2.allowedDst(chainId), false); | ||
emit DstValidSet(chainId, valid); | ||
galxeBadgeReceiverV2.updateDstValidity(chainId, valid); | ||
assertEq(galxeBadgeReceiverV2.allowedDst(chainId), valid); | ||
} | ||
|
||
function test_SendNFT_Revert_InvalidNFTAddr() public { | ||
changePrank(users.alice); | ||
|
||
vm.expectRevert(IBadgeReceiverV2Def.InvalidNFTAddr.selector); | ||
galxeBadgeReceiverV2.sendNFT(address(starNFT), 1, 1, users.alice); | ||
} | ||
|
||
function test_SendNFT_Revert_DstChainIdIsNotAllowed() public { | ||
changePrank(users.admin); | ||
galxeBadgeReceiverV2.updateValidNftAddr(address(starNFT), true); | ||
|
||
changePrank(users.alice); | ||
|
||
vm.expectRevert(IBadgeReceiverV2Def.DstChainIdIsNotAllowed.selector); | ||
galxeBadgeReceiverV2.sendNFT(address(starNFT), 1, 1, users.alice); | ||
} | ||
|
||
function test_SendNFT_Successfully() public { | ||
changePrank(users.admin); | ||
galxeBadgeReceiverV2.updateValidNftAddr(address(starNFT), true); | ||
galxeBadgeReceiverV2.updateDstValidity(1, true); | ||
|
||
changePrank(users.alice); | ||
|
||
assertEq(starNFT.ownerOf(1), users.alice); | ||
|
||
// check event emit | ||
vm.expectEmit(true, true, true, true); | ||
emit SendNFT(1, 1, 1, address(starNFT), users.alice, users.alice); | ||
|
||
galxeBadgeReceiverV2.sendNFT(address(starNFT), 1, 1, users.alice); | ||
|
||
// check owner change | ||
assertEq(starNFT.ownerOf(1), address(galxeBadgeReceiverV2)); | ||
} | ||
|
||
function test_BurnNFT_Revert_InvalidNFTAddr() public { | ||
changePrank(users.alice); | ||
|
||
vm.expectRevert(IBadgeReceiverV2Def.InvalidNFTAddr.selector); | ||
galxeBadgeReceiverV2.burnNFT(address(starNFT), 1); | ||
} | ||
|
||
function test_BurnNFT_Successfully() public { | ||
changePrank(users.admin); | ||
galxeBadgeReceiverV2.updateValidNftAddr(address(starNFT), true); | ||
galxeBadgeReceiverV2.updateDstValidity(1, true); | ||
|
||
changePrank(users.alice); | ||
|
||
assertEq(starNFT.ownerOf(1), users.alice); | ||
|
||
// check event emit | ||
// vm.expectEmit(true, true, true, true); | ||
// emit BurnAndRefund(1, 1, 1, address(starNFT), users.alice, users.alice); | ||
|
||
galxeBadgeReceiverV2.burnNFT(address(starNFT), 1); | ||
|
||
// check owner change | ||
assertEq(starNFT.ownerOf(1), Constant.BLACK_HOLE_ADDRESS); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters