Skip to content

Commit

Permalink
test: revoke using the actual module revoke method
Browse files Browse the repository at this point in the history
  • Loading branch information
gosuto-inzasheru committed Mar 10, 2024
1 parent a2208c6 commit b8cf0d0
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions test/Revoooker.t.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "forge-std/console.sol";
import { Test } from "forge-std/Test.sol";
import {
RhinestoneModuleKit,
Expand All @@ -12,6 +13,7 @@ import { MODULE_TYPE_EXECUTOR } from "modulekit/external/ERC7579.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { IERC20 } from "forge-std/interfaces/IERC20.sol";
import { Revoooker } from "src/Revoooker.sol";
import { DummyERC20 } from "src/DummyERC20.sol";

contract RevoookerTest is RhinestoneModuleKit, Test {
using ModuleKitHelpers for *;
Expand All @@ -22,15 +24,20 @@ contract RevoookerTest is RhinestoneModuleKit, Test {
// account and modules
AccountInstance internal instance;
Revoooker internal revoker;
DummyERC20 internal dummy;

function setUp() public {
// Initialize the RhinestoneModuleKit
init();
mainnetFork = vm.createFork(vm.envString("MAINNET_RPC_URL"));

// Create the executor
// Create the revoker
revoker = new Revoooker();
vm.label(address(revoker), "Revoooker");

// Deploy a dummy erc20
dummy = new DummyERC20();
vm.label(address(dummy), "DummyERC20");

// Create the account and install the revoker
instance = makeAccountInstance("Revoooker");
instance.installModule({
Expand All @@ -41,14 +48,24 @@ contract RevoookerTest is RhinestoneModuleKit, Test {
}

function testRevoke() public {
vm.selectFork(mainnetFork);
assertEq(vm.activeFork(), mainnetFork);
// Make all calls from the account instance
vm.startPrank(instance.account);

// Confirm the revoker is installed
assert(instance.isModuleInstalled(MODULE_TYPE_EXECUTOR, address(revoker), ""));

// Approve WETH for some spender
// Set up an allowance for spender on the dummy erc20
address spender = makeAddr("spender");
IERC20 weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
assertEq(weth.allowance(address(this), spender), 0);
weth.approve(spender, 1 ether);
assertGt(weth.allowance(address(this), spender), 0);
assertEq(dummy.allowance(instance.account, spender), 0);
dummy.approve(spender, 1 ether);
assertGt(dummy.allowance(instance.account, spender), 0);

// Get rid of the allowance using the revoooker
instance.exec({
target: address(revoker),
value: 0,
callData: abi.encodeCall(Revoooker.revoke, (address(dummy), spender))
});
assertEq(dummy.allowance(instance.account, spender), 0);
}
}

0 comments on commit b8cf0d0

Please sign in to comment.