-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nfts): add galxe mapping contract and deploy script (#17563)
- Loading branch information
Showing
5 changed files
with
82 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
contract RegisterGalxePoints { | ||
mapping(address => bool) public alreadyRegistered; | ||
|
||
event Registered(address registrant); | ||
|
||
function register() public { | ||
require(!alreadyRegistered[msg.sender], "Address already registered"); | ||
alreadyRegistered[msg.sender] = true; | ||
emit Registered(msg.sender); | ||
} | ||
} |
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,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import { Script, console } from "forge-std/src/Script.sol"; | ||
import { RegisterGalxePoints } from "../../contracts/galxe/RegisterGalxePoints.sol"; | ||
|
||
contract DeployRegisterMyGalaxyPointScript is Script { | ||
function run() public { | ||
uint256 deployerPrivateKey = vm.envUint("MAINNET_PRIVATE_KEY"); | ||
address deployerAddress = vm.addr(deployerPrivateKey); | ||
|
||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
RegisterGalxePoints registerGalxePoints = new RegisterGalxePoints(); | ||
|
||
console.log( | ||
"Deployed RegisterGalxePoints to:", | ||
address(registerGalxePoints), | ||
"from", | ||
deployerAddress | ||
); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
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,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.24; | ||
|
||
import { Test } from "forge-std/src/Test.sol"; | ||
|
||
import { RegisterGalxePoints } from "../../contracts/galxe/RegisterGalxePoints.sol"; | ||
|
||
contract RegisterGalxePointsTest is Test { | ||
RegisterGalxePoints public registerGalxePoints; | ||
|
||
address public owner = vm.addr(0x1); | ||
|
||
function setUp() public { | ||
// create whitelist merkle tree | ||
vm.startBroadcast(owner); | ||
|
||
registerGalxePoints = new RegisterGalxePoints(); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
// Test register function on RegisterGalxePoints also test for Registered event emitted | ||
|
||
function testRegister() public { | ||
vm.startPrank(owner); | ||
vm.expectEmit(true, false, false, true); | ||
emit RegisterGalxePoints.Registered(owner); | ||
registerGalxePoints.register(); | ||
|
||
vm.stopPrank(); | ||
} | ||
|
||
// Test case to check if already registered user is not allowed to register again | ||
function testCannotRegisterTwice() public { | ||
vm.startPrank(owner); | ||
registerGalxePoints.register(); | ||
vm.expectRevert("Address already registered"); | ||
registerGalxePoints.register(); | ||
vm.stopPrank(); | ||
} | ||
} |