@@ -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}
0 commit comments