Skip to content

Commit

Permalink
added more Tests for UntronFee
Browse files Browse the repository at this point in the history
  • Loading branch information
olaoyesalem committed Oct 15, 2024
1 parent b212028 commit 3bd9287
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions contracts/test/UntronFees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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") {}

Expand All @@ -23,6 +24,8 @@ contract UntronFeesTest is Test {
SP1MockVerifier sp1Verifier;
MockUSDT usdt;

UntronTools untronTools;

address admin = address(1);

constructor() {
Expand All @@ -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);

Expand Down Expand Up @@ -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();
}
}

1 change: 1 addition & 0 deletions contracts/test/common/UntronCoreUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bd9287

Please sign in to comment.