Skip to content

Commit

Permalink
remove duplicated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spengrah committed Dec 1, 2024
1 parent 80e7bba commit 606bd8e
Showing 1 changed file with 0 additions and 145 deletions.
145 changes: 0 additions & 145 deletions test/HatsSignerGate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1782,148 +1782,3 @@ contract Views is WithHSGInstanceTest {
assertFalse(instance.canAttachToSafe(newSafe), "should not be attachable");
}
}

contract HSGGuarding is WithHSGInstanceTest {
uint256 public disallowedValue = 1337;
uint256 public goodValue = 9_000_000_000;
address public recipient = makeAddr("recipient");
uint256 public signerCount = 2;

function setUp() public override {
super.setUp();

// set it on our hsg instance
vm.prank(owner);
instance.setGuard(address(tstGuard));
assertEq(instance.getGuard(), address(tstGuard), "guard should be tstGuard");

// deal the safe some eth
deal(address(safe), 1 ether);

// add signerCount number of signers
_addSignersSameHat(signerCount, signerHat);

address[] memory owners = safe.getOwners();
assertEq(owners.length, signerCount, "owners should be signerCount");
}

/// @dev a successful transaction should hit the tstGuard's checkTransaction and checkAfterExecution funcs
function test_executed() public {
uint256 preNonce = safe.nonce();
uint256 preValue = address(safe).balance;
uint256 transferValue = goodValue;
uint256 postValue = preValue - transferValue;

// create the tx
bytes32 txHash = _getTxHash(recipient, transferValue, Enum.Operation.Call, hex"00", safe);

// have 3 signers sign it
bytes memory signatures = _createNSigsForTx(txHash, signerCount);

// we expect the `sender` param to be address(0) because the sender param from hsg.checkTransaction is empty
vm.expectEmit();
emit TestGuard.PreChecked(address(0));
vm.expectEmit();
emit TestGuard.PostChecked(true);

// have one of the signers submit/exec the tx
vm.prank(signerAddresses[0]);
safe.execTransaction(
recipient,
transferValue,
hex"00",
Enum.Operation.Call,
// not using the refunder
0,
0,
0,
address(0),
payable(address(0)),
signatures
);

// confirm the tx succeeded by checking ETH balance changes
assertEq(address(safe).balance, postValue);
assertEq(recipient.balance, transferValue);
assertEq(safe.nonce(), preNonce + 1);
}

// the test guard should revert in checkTransaction
function test_revert_checkTransaction() public {
// we make this happen by using a bad value in the safe.execTransaction call
uint256 preNonce = safe.nonce();
uint256 preValue = address(safe).balance;
uint256 transferValue = disallowedValue;

// create the tx
bytes32 txHash = _getTxHash(recipient, transferValue, Enum.Operation.Call, hex"00", safe);

// have 3 signers sign it
bytes memory signatures = _createNSigsForTx(txHash, signerCount);

// we expect the test guard to revert in checkTransaction
vm.expectRevert("Cannot send 1337");

// have one of the signers submit/exec the tx
vm.prank(signerAddresses[0]);
safe.execTransaction(
recipient,
transferValue,
hex"00",
Enum.Operation.Call,
// not using the refunder
0,
0,
0,
address(0),
payable(address(0)),
signatures
);

// confirm the tx did not succeed by checking ETH balance changes
assertEq(address(safe).balance, preValue);
assertEq(recipient.balance, 0);
assertEq(safe.nonce(), preNonce);
}

// the test guard should revert in checkAfterExecution
function test_revert_checkAfterExecution() public {
// we make this happen by setting the test guard to disallow execution
tstGuard.disallowExecution();

// craft a basic eth transfer tx
uint256 preNonce = safe.nonce();
uint256 preValue = address(safe).balance;
uint256 transferValue = goodValue;

// create the tx
bytes32 txHash = _getTxHash(recipient, transferValue, Enum.Operation.Call, hex"00", safe);

// have 3 signers sign it
bytes memory signatures = _createNSigsForTx(txHash, signerCount);

// we expect the test guard to revert in checkTransaction
vm.expectRevert("Reverted in checkAfterExecution");

// have one of the signers submit/exec the tx
vm.prank(signerAddresses[0]);
safe.execTransaction(
recipient,
transferValue,
hex"00",
Enum.Operation.Call,
// not using the refunder
0,
0,
0,
address(0),
payable(address(0)),
signatures
);

// confirm the tx did not succeed by checking ETH balance changes
assertEq(address(safe).balance, preValue);
assertEq(recipient.balance, 0);
assertEq(safe.nonce(), preNonce);
}
}

0 comments on commit 606bd8e

Please sign in to comment.