Skip to content

Commit 463175b

Browse files
committed
feat: implement mint function and add tests for pausable functionality in RLCOFT contract
1 parent ee0a71d commit 463175b

File tree

2 files changed

+162
-2
lines changed

2 files changed

+162
-2
lines changed

src/RLCOFT.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ contract RLCOFT is OFTUpgradeable, UUPSUpgradeable, AccessControlDefaultAdminRul
6868
return 9;
6969
}
7070

71-
function burn(uint256 _value) external returns (bool) {
71+
function mint(address to, uint256 amount) external onlyRole(BRIDGE_ROLE) {
72+
_mint(to, amount);
73+
}
74+
75+
function burn(uint256 _value) external onlyRole(BRIDGE_ROLE) {
7276
_burn(msg.sender, _value);
73-
return true;
7477
}
7578

7679
function owner()

test/RLCOFT.t.sol

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.22;
3+
4+
import {Test, console} from "forge-std/Test.sol";
5+
import {Deploy as RLCOFTDeploy, Configure as RLCOFTConfigure} from "../script/RLCOFT.s.sol";
6+
import {RLCOFT} from "../src/RLCOFT.sol";
7+
import {ITokenSpender} from "../src/ITokenSpender.sol";
8+
9+
contract RLCOFTTest is Test {
10+
RLCOFT public rlcOft;
11+
12+
address public owner;
13+
address public pauser;
14+
address public user1;
15+
address public user2;
16+
17+
// Events to test
18+
event Paused(address account);
19+
event Unpaused(address account);
20+
event Transfer(address indexed from, address indexed to, uint256 value);
21+
22+
function setUp() public {
23+
vm.createSelectFork("https://arbitrum-sepolia.gateway.tenderly.com");
24+
25+
// Create addresses using makeAddr
26+
owner = makeAddr("owner");
27+
pauser = makeAddr("pauser");
28+
user1 = makeAddr("user1");
29+
user2 = makeAddr("user2");
30+
31+
32+
// Set up environment variables for the deployment
33+
vm.setEnv("RLC_OFT_TOKEN_NAME", "RLC OFT Test");
34+
vm.setEnv("RLC_TOKEN_SYMBOL", "RLCT");
35+
vm.setEnv("LAYER_ZERO_ARBITRUM_SEPOLIA_ENDPOINT_ADDRESS", vm.toString('LAYER_ZERO_ARBITRUM_SEPOLIA_ENDPOINT_ADDRESS'));
36+
vm.setEnv("OWNER_ADDRESS", vm.toString(owner));
37+
vm.setEnv("PAUSER_ADDRESS", vm.toString(pauser));
38+
39+
// Deploy the contract using the deployment script
40+
RLCOFTDeploy deployer = new RLCOFTDeploy();
41+
address deployedAddress = deployer.run();
42+
rlcOft = RLCOFT(deployedAddress);
43+
44+
// Mint some tokens for testing
45+
vm.prank(owner);
46+
rlcOft.mint(user1, 1000 * 10**9); // 1000 tokens with 9 decimals
47+
48+
vm.prank(owner);
49+
rlcOft.mint(user2, 500 * 10**9); // 500 tokens with 9 decimals
50+
}
51+
52+
// ============ Pausable Tests ============
53+
function testPauseByPauser() public {
54+
vm.expectEmit(true, false, false, false);
55+
emit Paused(pauser);
56+
57+
vm.prank(pauser);
58+
rlcOft.pause();
59+
60+
assertTrue(rlcOft.paused());
61+
}
62+
63+
function testPauseUnauthorized() public {
64+
vm.expectRevert();
65+
vm.prank(user1);
66+
rlcOft.pause();
67+
}
68+
69+
function testUnpauseByPauser() public {
70+
// First pause
71+
vm.prank(pauser);
72+
rlcOft.pause();
73+
assertTrue(rlcOft.paused());
74+
75+
// Then unpause
76+
vm.expectEmit(true, false, false, false);
77+
emit Unpaused(pauser);
78+
79+
vm.prank(pauser);
80+
rlcOft.unpause();
81+
82+
assertFalse(rlcOft.paused());
83+
}
84+
85+
function testUnpauseUnauthorized() public {
86+
vm.prank(pauser);
87+
rlcOft.pause();
88+
89+
vm.expectRevert();
90+
vm.prank(user1);
91+
rlcOft.unpause();
92+
}
93+
94+
function testTransferWhenPaused() public {
95+
// Pause the contract
96+
vm.prank(pauser);
97+
rlcOft.pause();
98+
99+
// Try to transfer - should fail
100+
vm.expectRevert("Pausable: paused");
101+
vm.prank(user1);
102+
rlcOft.transfer(user2, 100 * 10**9);
103+
}
104+
105+
function testTransferFromWhenPaused() public {
106+
// First approve
107+
vm.prank(user1);
108+
rlcOft.approve(user2, 100 * 10**9);
109+
110+
// Pause the contract
111+
vm.prank(pauser);
112+
rlcOft.pause();
113+
114+
// Try to transferFrom - should fail
115+
vm.expectRevert("Pausable: paused");
116+
vm.prank(user2);
117+
rlcOft.transferFrom(user1, user2, 100 * 10**9);
118+
}
119+
120+
function testMintWhenPaused() public {
121+
// Pause the contract
122+
vm.prank(pauser);
123+
rlcOft.pause();
124+
125+
// Try to mint - should fail
126+
vm.expectRevert("Pausable: paused");
127+
vm.prank(owner);
128+
rlcOft.mint(user1, 100 * 10**9);
129+
}
130+
131+
function testBurnWhenPaused() public {
132+
// Pause the contract
133+
vm.prank(pauser);
134+
rlcOft.pause();
135+
136+
// Try to burn - should fail
137+
vm.expectRevert("Pausable: paused");
138+
vm.prank(user1);
139+
rlcOft.burn(100 * 10**9);
140+
}
141+
142+
function testTransferWhenNotPaused() public {
143+
uint256 transferAmount = 100 * 10**9;
144+
uint256 initialBalance1 = rlcOft.balanceOf(user1);
145+
uint256 initialBalance2 = rlcOft.balanceOf(user2);
146+
147+
vm.expectEmit(true, true, false, true);
148+
emit Transfer(user1, user2, transferAmount);
149+
150+
vm.prank(user1);
151+
bool success = rlcOft.transfer(user2, transferAmount);
152+
153+
assertTrue(success);
154+
assertEq(rlcOft.balanceOf(user1), initialBalance1 - transferAmount);
155+
assertEq(rlcOft.balanceOf(user2), initialBalance2 + transferAmount);
156+
}
157+
}

0 commit comments

Comments
 (0)