Skip to content

Commit

Permalink
rm unused function & add a smart contract call (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmychu0807 authored Jan 11, 2025
1 parent e8bc0bc commit 01b6bdd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
55 changes: 50 additions & 5 deletions test/SemaphoreMSAValidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ import {
AccountInstance,
UserOpData
} from "modulekit/ModuleKit.sol";
import { IERC7579Module, IERC7579Validator } from "modulekit/Modules.sol";
import {
VALIDATION_SUCCESS,
MODULE_TYPE_VALIDATOR
} from "modulekit/accounts/common/interfaces/IERC7579Module.sol";
import { PackedUserOperation } from "modulekit/external/ERC4337.sol";
import { ERC4337Helpers } from "modulekit/test/utils/ERC4337Helpers.sol";

// Semaphore
import {
Semaphore,
ISemaphore,
ISemaphoreGroups,
ISemaphoreVerifier,
SemaphoreVerifier
} from "../src/utils/Semaphore.sol";
Expand Down Expand Up @@ -401,7 +398,7 @@ contract SemaphoreValidatorUnitTest is RhinestoneModuleKit, Test {
assertEq(afterBalance - beforeBalance, value);
}

function test_initiateTxOneMemberNonValidatorCall()
function test_initiateTxMemberNonValidatorCall()
public
setupSmartAcctOneMember
deploySimpleContract
Expand All @@ -422,7 +419,7 @@ contract SemaphoreValidatorUnitTest is RhinestoneModuleKit, Test {
userOpData.execUserOps();
}

function test_initiateTxOneMemberAllowedSelectorInvalidSemaphoreProof()
function test_initiateTxMemberAllowedSelectorInvalidSemaphoreProof()
public
setupSmartAcctOneMember
deploySimpleContract
Expand All @@ -445,4 +442,52 @@ contract SemaphoreValidatorUnitTest is RhinestoneModuleKit, Test {
smartAcct.expect4337Revert(SemaphoreMSAValidator.InvalidSemaphoreProof.selector);
userOpData.execUserOps();
}

function test_initiateTxMemberAndExecuteValid()
public
setupSmartAcctOneMember
deploySimpleContract
{
User storage member = $users[0];
uint256 testVal = 7;
uint256 value = 0;

bytes memory txCallData = abi.encodeCall(SimpleContract.setVal, (testVal));
uint256 seq = semaphoreValidator.getNextSeqNum(smartAcct.account);
bytes32 txHash =
keccak256(abi.encodePacked(seq, address(simpleContract), value, txCallData));

{
// Using scope to limit the number of local variables, work around the `stack too deep`
// error.
// Generate the semaphore proof
(, uint256 groupId) = semaphoreValidator.getGroupId(smartAcct.account);
uint256[] memory members = new uint256[](1);
members[0] = member.identity.commitment();
ISemaphore.SemaphoreProof memory smProof =
member.identity.generateSempahoreProof(groupId, members, txHash);

// Composing the UserOpData
UserOpData memory userOpData = smartAcct.getExecOps({
target: address(semaphoreValidator),
value: value,
callData: abi.encodeCall(
SemaphoreMSAValidator.initiateTx,
(address(simpleContract), txCallData, smProof, true)
),
txValidator: address(semaphoreValidator)
});

userOpData.userOp.signature = member.identity.signHash(userOpData.userOpHash);

// Expect transaction to go thru and emit two events
vm.expectEmit(true, true, true, true, address(semaphoreValidator));
emit SemaphoreMSAValidator.InitiatedTx(smartAcct.account, seq, txHash);
vm.expectEmit(true, true, true, true, address(semaphoreValidator));
emit SemaphoreMSAValidator.ExecutedTx(smartAcct.account, txHash);
userOpData.execUserOps();
}

assertEq(simpleContract.val(), testVal);
}
}
2 changes: 1 addition & 1 deletion test/utils/SimpleContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.23;

contract SimpleContract {
uint256 val;
uint256 public val;

constructor(uint256 _val) {
val = _val;
Expand Down

0 comments on commit 01b6bdd

Please sign in to comment.