Skip to content

Commit

Permalink
test: Basic Foundry Tests for Hybrid Session Key Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurdubey521 committed Dec 18, 2023
1 parent 6a84e57 commit 089e7cb
Show file tree
Hide file tree
Showing 5 changed files with 719 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"code-complexity": ["error", 7],
"function-max-lines": ["error", 80],
"max-line-length": ["warn", 120],
"max-states-count": ["error", 15],
"max-states-count": ["error", 20],
"no-empty-blocks": "error",
"no-unused-vars": "error",
"payable-fallback": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {StatefulSessionKeyManagerBase} from "./StatefulSessionKeyManagerBase.sol
* @title Session Key Manager module for Biconomy Modular Smart Accounts.
* @dev Similar to the Stateful Session Key Manager module, but the session enable transaction
* is batched with the first transaction that uses the session key.
* Session creation is offline and completely free.
* Session creation is offline.
* @author Ankur Dubey - <[email protected]>
* @author Fil Makarov - <[email protected]>
*/
Expand All @@ -27,6 +27,8 @@ contract SessionKeyManagerHybrid is
UserOperation calldata userOp,
bytes32 userOpHash
) external virtual override returns (uint256 rv) {
// TODO: Optimize
// TODO use calldata references wherever possible
(bytes memory moduleSignature, ) = abi.decode(
userOp.signature,
(bytes, address)
Expand All @@ -40,9 +42,9 @@ contract SessionKeyManagerHybrid is
if (isSessionEnableTransaction == 1) {
(
,
uint256 sessionKeyIndex,
uint48 validUntil,
uint48 validAfter,
uint256 sessionKeyIndex,
address sessionValidationModule,
bytes memory sessionKeyData,
bytes memory sessionEnableData,
Expand All @@ -51,10 +53,10 @@ contract SessionKeyManagerHybrid is
) = abi.decode(
moduleSignature,
(
uint256,
uint256,
uint48,
uint48,
uint256,
address,
bytes,
bytes,
Expand Down Expand Up @@ -179,6 +181,7 @@ contract SessionKeyManagerHybrid is
sessionValidationModule,
sessionKeyData
);

if (sessionDigest != computedDigest) {
revert("SessionKeyDataHashMismatch");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ abstract contract StatefulSessionKeyManagerBase is
}

function _sessionDataDigestUnpacked(
uint256 _validUntil,
uint256 _validAfter,
uint48 _validUntil,
uint48 _validAfter,
address _sessionValidationModule,
bytes memory _sessionKeyData
) internal pure returns (bytes32) {
Expand Down
36 changes: 19 additions & 17 deletions test/foundry/base/SATestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,30 @@ abstract contract SATestBase is Test {
uint256 privateKey;
}

TestAccount[] testAccounts;
TestAccount alice;
TestAccount bob;
TestAccount charlie;
TestAccount dan;
TestAccount emma;
TestAccount frank;
TestAccount george;
TestAccount henry;
TestAccount ida;

TestAccount owner;
TestAccount[] internal testAccounts;
mapping(address account => TestAccount) internal testAccountsByAddress;
TestAccount internal alice;
TestAccount internal bob;
TestAccount internal charlie;
TestAccount internal dan;
TestAccount internal emma;
TestAccount internal frank;
TestAccount internal george;
TestAccount internal henry;
TestAccount internal ida;

TestAccount internal owner;

// Test Tokens
MockToken token;
MockToken internal token;

// ERC4337 Contracts
EntryPoint entryPoint;
SmartAccount saImplementation;
SmartAccountFactory factory;
EntryPoint internal entryPoint;
SmartAccount internal saImplementation;
SmartAccountFactory internal factory;

// Modules
EcdsaOwnershipRegistryModule ecdsaOwnershipRegistryModule;
EcdsaOwnershipRegistryModule internal ecdsaOwnershipRegistryModule;

function getNextPrivateKey() internal returns (uint256) {
return vm.deriveKey(mnemonic, ++nextKeyIndex);
Expand All @@ -82,6 +83,7 @@ abstract contract SATestBase is Test {
testAccounts.push(
TestAccount(payable(vm.addr(privateKey)), privateKey)
);
testAccountsByAddress[testAccounts[i].addr] = testAccounts[i];

deal(testAccounts[i].addr, initialMainAccountFunds);
}
Expand Down
Loading

0 comments on commit 089e7cb

Please sign in to comment.