From 199d312b29f4000cb72152e60dee6821ea923b07 Mon Sep 17 00:00:00 2001 From: Shivaansh Kapoor Date: Thu, 4 Jul 2024 11:42:31 +0400 Subject: [PATCH] setPostOpCost tests --- contracts/test/Foo.sol | 18 -------- contracts/test/Lock.sol | 46 ------------------- scripts/foundry/Deploy.s.sol | 17 ------- ...tSponsorshipPaymasterWithPremiumTest.t.sol | 25 ++++++++++ ..._TestSponsorshipPaymasterWithPremium.t.sol | 14 ++++++ 5 files changed, 39 insertions(+), 81 deletions(-) delete mode 100644 contracts/test/Foo.sol delete mode 100644 contracts/test/Lock.sol delete mode 100644 scripts/foundry/Deploy.s.sol diff --git a/contracts/test/Foo.sol b/contracts/test/Foo.sol deleted file mode 100644 index 8302d06..0000000 --- a/contracts/test/Foo.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.26; - -/** - * @title Foo - * @dev A simple contract demonstrating a pure function in Solidity. - */ -contract Foo { - /** - * @notice Returns the input value unchanged. - * @dev A pure function that does not alter or interact with contract state. - * @param value The uint256 value to be returned. - * @return uint256 The same value that was input. - */ - function id(uint256 value) external pure returns (uint256) { - return value; - } -} diff --git a/contracts/test/Lock.sol b/contracts/test/Lock.sol deleted file mode 100644 index 522be01..0000000 --- a/contracts/test/Lock.sol +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -/** - * @title Lock - * @dev Implements a time-locked wallet that only allows withdrawals after a certain date. - */ -contract Lock { - uint256 public unlockTime; - address payable public owner; - - /** - * @dev Emitted when funds are withdrawn from the contract. - * @param amount The amount of Ether withdrawn. - * @param when The timestamp of the withdrawal. - */ - event Withdrawal(uint256 amount, uint256 when); - - /** - * @notice Creates a locked wallet. - * @param unlockTime_ The timestamp after which withdrawals can be made. - */ - constructor(uint256 unlockTime_) payable { - require(block.timestamp < unlockTime_, "Wrong Unlock time"); - - unlockTime = unlockTime_; - owner = payable(msg.sender); - } - - /** - * @notice Allows funds to be received via direct transfers. - */ - receive() external payable { } - - /** - * @notice Withdraws all funds if the unlock time has passed and the caller is the owner. - */ - function withdraw() public { - require(block.timestamp > unlockTime, "You can't withdraw yet"); - require(msg.sender == owner, "You aren't the owner"); - - emit Withdrawal(address(this).balance, block.timestamp); - - owner.transfer(address(this).balance); - } -} diff --git a/scripts/foundry/Deploy.s.sol b/scripts/foundry/Deploy.s.sol deleted file mode 100644 index 5a55826..0000000 --- a/scripts/foundry/Deploy.s.sol +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity >=0.8.23 <0.9.0; - -import { Foo } from "../../contracts/test/Foo.sol"; - -import { BaseScript } from "./Base.s.sol"; - -/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting -contract Deploy is BaseScript { - function run() public broadcast returns (Foo foo) { - foo = new Foo(); - } - - function test() public pure returns (uint256) { - return 0; - } -} diff --git a/test/foundry/unit/concrete/TestSponsorshipPaymasterWithPremiumTest.t.sol b/test/foundry/unit/concrete/TestSponsorshipPaymasterWithPremiumTest.t.sol index caf3dc9..646d2e6 100644 --- a/test/foundry/unit/concrete/TestSponsorshipPaymasterWithPremiumTest.t.sol +++ b/test/foundry/unit/concrete/TestSponsorshipPaymasterWithPremiumTest.t.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.26; +import { console2 } from "forge-std/src/console2.sol"; import { NexusTestBase } from "../../base/NexusTestBase.sol"; import { IBiconomySponsorshipPaymaster } from "../../../../contracts/interfaces/IBiconomySponsorshipPaymaster.sol"; import { BiconomySponsorshipPaymaster } from "../../../../contracts/sponsorship/SponsorshipPaymasterWithPremium.sol"; @@ -25,6 +26,7 @@ contract TestSponsorshipPaymasterWithPremium is NexusTestBase { assertEq(address(testArtifact.entryPoint()), ENTRYPOINT_ADDRESS); assertEq(testArtifact.verifyingSigner(), PAYMASTER_SIGNER.addr); assertEq(testArtifact.feeCollector(), PAYMASTER_FEE_COLLECTOR.addr); + assertEq(testArtifact.postopCost(), 0 wei); } function test_CheckInitialPaymasterState() external view { @@ -32,6 +34,7 @@ contract TestSponsorshipPaymasterWithPremium is NexusTestBase { assertEq(address(bicoPaymaster.entryPoint()), ENTRYPOINT_ADDRESS); assertEq(bicoPaymaster.verifyingSigner(), PAYMASTER_SIGNER.addr); assertEq(bicoPaymaster.feeCollector(), PAYMASTER_FEE_COLLECTOR.addr); + assertEq(bicoPaymaster.postopCost(), 0 wei); } function test_OwnershipTransfer() external prankModifier(PAYMASTER_OWNER.addr) { @@ -261,4 +264,26 @@ contract TestSponsorshipPaymasterWithPremium is NexusTestBase { vm.expectRevert("withdraw failed"); bicoPaymaster.withdrawEth(payable(ALICE_ADDRESS), ethAmount); } + + function test_SetPostopCost() external prankModifier(PAYMASTER_OWNER.addr) { + uint48 initialPostopCost = bicoPaymaster.postopCost(); + assertEq(initialPostopCost, 0 wei); + uint48 newPostopCost = initialPostopCost + 1 wei; + + vm.expectEmit(true, true, false, true, address(bicoPaymaster)); + emit IBiconomySponsorshipPaymaster.PostopCostChanged(initialPostopCost, newPostopCost); + bicoPaymaster.setPostopCost(newPostopCost); + + uint48 resultingPostopCost = bicoPaymaster.postopCost(); + assertEq(resultingPostopCost, newPostopCost); + } + + function test_RevertIf_SetPostopCostToHigh() external prankModifier(PAYMASTER_OWNER.addr) { + uint48 initialPostopCost = bicoPaymaster.postopCost(); + assertEq(initialPostopCost, 0 wei); + uint48 newPostopCost = initialPostopCost + 200_001 wei; + + vm.expectRevert("Gas overhead too high"); + bicoPaymaster.setPostopCost(newPostopCost); + } } diff --git a/test/foundry/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol b/test/foundry/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol index 2eb44e7..0b6e7ff 100644 --- a/test/foundry/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol +++ b/test/foundry/unit/fuzz/TestFuzz_TestSponsorshipPaymasterWithPremium.t.sol @@ -76,4 +76,18 @@ contract TestFuzz_SponsorshipPaymasterWithPremium is NexusTestBase { assertEq(ALICE_ADDRESS.balance, initialAliceBalance + ethAmount); assertEq(address(bicoPaymaster).balance, 0 ether); } + + function testFuzz_SetPostopCost(uint48 value) external prankModifier(PAYMASTER_OWNER.addr) { + vm.assume(value <= 200_000 wei); + uint48 initialPostopCost = bicoPaymaster.postopCost(); + assertEq(initialPostopCost, 0 wei); + uint48 newPostopCost = value; + + vm.expectEmit(true, true, false, true, address(bicoPaymaster)); + emit IBiconomySponsorshipPaymaster.PostopCostChanged(initialPostopCost, newPostopCost); + bicoPaymaster.setPostopCost(newPostopCost); + + uint48 resultingPostopCost = bicoPaymaster.postopCost(); + assertEq(resultingPostopCost, newPostopCost); + } }