Sitelet https://github.com/Dargon789/account/commit/30a2096cce0811834c5835a8698ec525c3923112
Skip to content

Commit 30a2096

Browse files
authored
Merge branch 'ithacaxyz:main' into main
2 parents 28ff37f + 767e973 commit 30a2096

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎test/Account.t.sol‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,49 @@ contract AccountTest is BaseTest {
354354
uint256 keysCount137 = IthacaAccount(eoaAddress).keyCount();
355355
assertEq(keysCount137, 2, "Keys should be added on chain 137");
356356
}
357+
358+
function testContextKeyHash() public {
359+
DelegatedEOA memory d = _randomEIP7702DelegatedEOA();
360+
361+
PassKey memory key = _randomPassKey();
362+
key.k.isSuperAdmin = true;
363+
364+
vm.prank(d.eoa);
365+
d.d.authorize(key.k);
366+
367+
// Orchestrator workflow
368+
vm.prank(d.d.ORCHESTRATOR());
369+
ERC7821.Call[] memory calls = new ERC7821.Call[](1);
370+
calls[0].data = abi.encodeWithSelector(this.targetFunctionContextKeyHash.selector);
371+
calls[0].to = address(this);
372+
calls[0].value = 0;
373+
bytes memory opData = abi.encode(key.keyHash);
374+
bytes memory executionData = abi.encode(calls, opData);
375+
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, executionData);
376+
377+
assertEq(contextKeyHash, key.keyHash, "Context key hash mismatch orchestrator workflow");
378+
379+
// Reset context key hash
380+
contextKeyHash = bytes32(0);
381+
382+
// Workflow with opData
383+
uint256 nonce = d.d.getNonce(0);
384+
bytes memory signature = _sig(key, d.d.computeDigest(calls, nonce));
385+
opData = abi.encodePacked(nonce, signature);
386+
executionData = abi.encode(calls, opData);
387+
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, executionData);
388+
389+
assertEq(contextKeyHash, key.keyHash, "Context key hash mismatch orchestrator workflow");
390+
391+
// Reset context key hash
392+
contextKeyHash = bytes32(0);
393+
394+
// Simple workflow without opData (self-execution)
395+
bytes memory emptyOpData;
396+
executionData = abi.encode(calls, emptyOpData);
397+
vm.prank(address(d.d));
398+
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, executionData);
399+
400+
assertEq(contextKeyHash, bytes32(0), "Context key hash should be zero for self-execution without opData");
401+
}
357402
}

‎test/Base.t.sol‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ contract BaseTest is SoladyTest {
3434
EIP7702Proxy eip7702Proxy;
3535
TargetFunctionPayload[] targetFunctionPayloads;
3636
Simulator simulator;
37+
bytes32 contextKeyHash;
3738

3839
struct TargetFunctionPayload {
3940
address by;
@@ -94,6 +95,10 @@ contract BaseTest is SoladyTest {
9495
targetFunctionPayloads.push(TargetFunctionPayload(msg.sender, msg.value, data));
9596
}
9697

98+
function targetFunctionContextKeyHash() public payable {
99+
contextKeyHash = IthacaAccount(payable(msg.sender)).getContextKeyHash();
100+
}
101+
97102
function _setEIP7702Delegation(address eoa) internal {
98103
vm.etch(eoa, abi.encodePacked(hex"ef0100", address(account)));
99104
}

0 commit comments

Comments
 (0)