Skip to content

Commit 7eabc38

Browse files
committed
add tests for delegation behavior
1 parent c306de8 commit 7eabc38

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/EIP7702Proxy/delegate.t.sol

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.23;
3+
4+
import {EIP7702ProxyBase} from "../base/EIP7702ProxyBase.sol";
5+
import {EIP7702Proxy} from "../../src/EIP7702Proxy.sol";
6+
import {CoinbaseSmartWallet} from "../../lib/smart-wallet/src/CoinbaseSmartWallet.sol";
7+
8+
contract DelegateTest is EIP7702ProxyBase {
9+
function setUp() public override {
10+
super.setUp();
11+
12+
// Initialize the proxy for delegation tests
13+
bytes memory initArgs = _createInitArgs(_newOwner);
14+
bytes memory signature = _signInitData(_EOA_PRIVATE_KEY, initArgs);
15+
vm.prank(_eoa);
16+
EIP7702Proxy(_eoa).initialize(initArgs, signature);
17+
}
18+
19+
function testBlocksGuardedInitializer() public {
20+
bytes memory initData = abi.encodeWithSelector(
21+
CoinbaseSmartWallet.initialize.selector,
22+
_createInitArgs(_newOwner)
23+
);
24+
25+
vm.expectRevert(EIP7702Proxy.InvalidInitializer.selector);
26+
address(_eoa).call(initData);
27+
}
28+
29+
function testDelegatesReadCall() public {
30+
assertTrue(
31+
CoinbaseSmartWallet(payable(_eoa)).isOwnerAddress(_newOwner),
32+
"Delegated read call should succeed"
33+
);
34+
}
35+
36+
function testDelegatesWriteCall() public {
37+
// Test a state-changing call
38+
address recipient = address(0xBEEF);
39+
uint256 amount = 1 ether;
40+
41+
// Fund the proxy
42+
vm.deal(address(_eoa), amount);
43+
44+
vm.prank(_newOwner);
45+
CoinbaseSmartWallet(payable(_eoa)).execute(
46+
payable(recipient),
47+
amount,
48+
"" // empty calldata for simple transfer
49+
);
50+
51+
assertEq(
52+
recipient.balance,
53+
amount,
54+
"Delegated write call should transfer ETH"
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)