-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests passes, including 7702-enabled external geth
- Loading branch information
1 parent
f98cd95
commit 951ab2a
Showing
11 changed files
with
553 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
pragma solidity ^0.8.23; | ||
// SPDX-License-Identifier: MIT | ||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
import "../core/BaseAccount.sol"; | ||
import "../core/Eip7702Support.sol"; | ||
|
||
contract TestEip7702DelegateAccount is BaseAccount { | ||
|
||
IEntryPoint private immutable _entryPoint; | ||
bool public testInitCalled; | ||
|
||
constructor(IEntryPoint anEntryPoint) { | ||
_entryPoint = anEntryPoint; | ||
} | ||
|
||
function testInit() public { | ||
testInitCalled = true; | ||
} | ||
|
||
function entryPoint() public view override virtual returns (IEntryPoint) { | ||
return _entryPoint; | ||
} | ||
|
||
// Require the function call went through EntryPoint or owner | ||
function _requireFromEntryPointOrOwner() internal view { | ||
require(msg.sender == address(this) || msg.sender == address(entryPoint()), "account: not Owner or EntryPoint"); | ||
} | ||
|
||
/** | ||
* execute a transaction (called directly from owner, or by entryPoint) | ||
* @param dest destination address to call | ||
* @param value the value to pass in this call | ||
* @param func the calldata to pass in this call | ||
*/ | ||
function execute(address dest, uint256 value, bytes calldata func) external { | ||
_requireFromEntryPointOrOwner(); | ||
(bool success,) = dest.call{value: value}(func); | ||
require(success, "call failed"); | ||
} | ||
|
||
function _validateSignature( | ||
PackedUserOperation calldata userOp, | ||
bytes32 userOpHash | ||
) internal virtual override returns (uint256 validationData) { | ||
if (userOp.initCode.length > 20) { | ||
require(testInitCalled, "testInit not called"); | ||
} | ||
if (ECDSA.recover(userOpHash, userOp.signature) == address(this)) { | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
|
||
function selfcode() internal returns (uint ret) { | ||
assembly { | ||
extcodecopy(address(), 0, 0, 32) | ||
ret := mload(0) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { spawn, ChildProcess } from 'child_process' | ||
import Debug from 'debug' | ||
|
||
const debug = Debug('aa.geth') | ||
|
||
const port = 54321 | ||
export const gethLauncher = { | ||
name: 'geth', | ||
exec: './scripts/geth.sh', | ||
args: `--http --http.api personal,eth,net,web3,debug --rpc.allow-unprotected-txs --allow-insecure-unlock --dev --http.port=${port}` | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const anvilLauncher = { | ||
name: 'anvil', | ||
exec: './scripts/anvil.sh', | ||
args: `--hardfork prague --port=${port}` | ||
} | ||
|
||
export class GethExecutable { | ||
constructor (private readonly impl = gethLauncher) { | ||
} | ||
|
||
private gethProcess: ChildProcess | null = null | ||
|
||
markerString = /HTTP server started|Listening on/ | ||
|
||
rpcUrl (): string { | ||
return `http://localhost:${port}` | ||
} | ||
|
||
async init (): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
console.log('spawning: ', this.impl.exec, this.impl.args) | ||
this.gethProcess = spawn(this.impl.exec, this.impl.args.split(' ')) | ||
|
||
let allData = '' | ||
if (this.gethProcess != null) { | ||
const timeout = setTimeout(() => { | ||
reject(new Error(`Timed out waiting for marker regex: ${this.markerString.toString()}\n: ${allData}`)) | ||
}, 5000) | ||
|
||
this.gethProcess.stdout?.on('data', (data: string) => { | ||
data = data.toString() | ||
allData += data | ||
debug('stdout:', data) | ||
if (data.match(this.markerString) != null) { | ||
clearTimeout(timeout) | ||
resolve() | ||
} | ||
}) | ||
this.gethProcess.stderr?.on('data', (data: string) => { | ||
data = data.toString() | ||
allData += data | ||
debug('stderr:', data) | ||
|
||
if (data.match(this.markerString) != null) { | ||
clearTimeout(timeout) | ||
resolve() | ||
} | ||
}) | ||
|
||
this.gethProcess.on('exit', (code: number | null) => { | ||
console.log(`${this.impl.name} process exited with code ${code}`) | ||
}) | ||
} else { | ||
reject(new Error('Failed to start geth process')) | ||
} | ||
}) | ||
} | ||
|
||
done (): void { | ||
if (this.gethProcess != null) { | ||
this.gethProcess.kill() | ||
} | ||
} | ||
} |
Oops, something went wrong.