From 3bd9287aedc39fbb130954624649f8f097c147a3 Mon Sep 17 00:00:00 2001 From: olaoyesalem Date: Tue, 15 Oct 2024 18:41:49 +0000 Subject: [PATCH] added more Tests for UntronFee --- contracts/test/UntronFees.t.sol | 57 +++++++++++++++++++++++ contracts/test/common/UntronCoreUtils.sol | 1 + 2 files changed, 58 insertions(+) diff --git a/contracts/test/UntronFees.t.sol b/contracts/test/UntronFees.t.sol index 91a0956..b8af4d3 100644 --- a/contracts/test/UntronFees.t.sol +++ b/contracts/test/UntronFees.t.sol @@ -8,6 +8,7 @@ import "@sp1-contracts/SP1MockVerifier.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; + contract MockUSDT is ERC20 { constructor() ERC20("Mock USDT", "USDT") {} @@ -23,6 +24,8 @@ contract UntronFeesTest is Test { SP1MockVerifier sp1Verifier; MockUSDT usdt; + UntronTools untronTools; + address admin = address(1); constructor() { @@ -40,6 +43,7 @@ contract UntronFeesTest is Test { // Use UntronCore since UntronFees is abstract untronFeesImplementation = new UntronCore(); + // Prepare the initialization data bytes memory initData = abi.encodeWithSelector(UntronCore.initialize.selector, state); @@ -80,4 +84,57 @@ contract UntronFeesTest is Test { vm.expectRevert(); untronFees.setFeesVariables(relayerFee, fulfillerFee); } + + function test_SetExtremeFees(uint256 relayerFee, uint256 fulfillerFee) public { + vm.assume(relayerFee <= 1000000); // Assuming max is 100% in basis points + vm.assume(fulfillerFee <= 1 ether); // Assuming a reasonable max fee in USDT + + vm.startPrank(admin); // Ensure we are using the admin address + untronFees.setFeesVariables(relayerFee, fulfillerFee); + assertEq(untronFees.relayerFee(), relayerFee); + assertEq(untronFees.fulfillerFee(), fulfillerFee); + vm.stopPrank(); // Stop prank after setting fees +} + +function test_SetZeroAndNegativeFees(int256 relayerFee, int256 fulfillerFee) public { + vm.assume(relayerFee < 0 || relayerFee == 0); + vm.assume(fulfillerFee < 0 || fulfillerFee == 0); + +vm.startPrank(admin); + if (relayerFee >= 0 && fulfillerFee >= 0) { + untronFees.setFeesVariables(uint256(relayerFee), uint256(fulfillerFee)); + } else { + vm.expectRevert(); + untronFees.setFeesVariables(uint256(relayerFee), uint256(fulfillerFee)); + } + +vm.stopPrank(); } + + +function test_BoundaryTestingOnFees(uint256 relayerFee, uint256 fulfillerFee) public { + vm.assume(relayerFee >= 0 && relayerFee <= 1000000); + vm.assume(fulfillerFee >= 0 && fulfillerFee <= 1 ether); + + vm.startPrank(admin); // Ensure we are using the admin address + untronFees.setFeesVariables(relayerFee, fulfillerFee); + + // Check if setting fees at boundaries works as expected + assertEq(untronFees.relayerFee(), relayerFee); + assertEq(untronFees.fulfillerFee(), fulfillerFee); + vm.stopPrank(); // Stop prank after setting fees +} + +function test_RoleBasedAccessControl() public { + address nonAdmin = address(2); // Another user + + vm.startPrank(nonAdmin); + + // Expect revert when non-admin tries to set fees + vm.expectRevert(); + untronFees.setFeesVariables(100, 100); + + vm.stopPrank(); +} +} + diff --git a/contracts/test/common/UntronCoreUtils.sol b/contracts/test/common/UntronCoreUtils.sol index d6b69b1..29d2ab1 100644 --- a/contracts/test/common/UntronCoreUtils.sol +++ b/contracts/test/common/UntronCoreUtils.sol @@ -205,6 +205,7 @@ abstract contract UntronCoreUtils is Test { function conversion(uint256 size, uint256 rate, uint256 fixedFee, bool includeRelayerFee) public pure returns (uint256 value, uint256 _relayerFee) { + // convert size into USDT L2 based on the rate uint256 out = (size * rate / 1e6); // if the relayer fee is included, subtract it from the converted size