-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
127 changed files
with
2,104 additions
and
4,912 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,4 @@ | ||
export * from "./utils/index.js" | ||
export * from "./signers/local-account.js" | ||
export * from "./signers/wallet-client.js" | ||
export * from "./toNexusAccount.js" |
File renamed without changes.
File renamed without changes.
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,115 @@ | ||
import { http, type Account, type Address, type Chain, isHex } from "viem" | ||
import { afterAll, beforeAll, describe, expect, test } from "vitest" | ||
import { toNetwork } from "../../tests/testSetup" | ||
import { | ||
getBalance, | ||
getTestAccount, | ||
killNetwork, | ||
toTestClient, | ||
topUp | ||
} from "../../tests/testUtils" | ||
import type { MasterClient, NetworkConfig } from "../../tests/testUtils" | ||
import { type NexusAccount, toNexusAccount } from "./toNexusAccount" | ||
import type { UserOperationStruct } from "./utils/Types" | ||
|
||
describe("nexus.account", () => { | ||
let network: NetworkConfig | ||
let chain: Chain | ||
let bundlerUrl: string | ||
|
||
// Test utils | ||
let testClient: MasterClient | ||
let account: Account | ||
let nexusAccountAddress: Address | ||
let nexusAccount: NexusAccount | ||
|
||
beforeAll(async () => { | ||
network = await toNetwork() | ||
|
||
chain = network.chain | ||
bundlerUrl = network.bundlerUrl | ||
account = getTestAccount(0) | ||
testClient = toTestClient(chain, getTestAccount(0)) | ||
|
||
nexusAccount = await toNexusAccount({ | ||
owner: account, | ||
chain, | ||
transport: http() | ||
}) | ||
|
||
nexusAccountAddress = await nexusAccount.getCounterFactualAddress() | ||
}) | ||
afterAll(async () => { | ||
await killNetwork([network?.rpcPort, network?.bundlerPort]) | ||
}) | ||
|
||
test.concurrent("should have 4337 account actions", async () => { | ||
const [ | ||
counterfactualAddress, | ||
userOpHash, | ||
address, | ||
factoryArgs, | ||
stubSignature, | ||
signedMessage, | ||
nonce, | ||
initCode, | ||
isDeployed, | ||
encodedExecute, | ||
encodedExecuteBatch | ||
] = await Promise.all([ | ||
nexusAccount.getCounterFactualAddress(), | ||
nexusAccount.getUserOpHash({ | ||
sender: account.address, | ||
nonce: 0n, | ||
data: "0x", | ||
signature: "0x", | ||
verificationGasLimit: 1n, | ||
preVerificationGas: 1n, | ||
callData: "0x", | ||
callGasLimit: 1n, | ||
maxFeePerGas: 1n, | ||
maxPriorityFeePerGas: 1n | ||
} as UserOperationStruct), | ||
nexusAccount.getAddress(), | ||
nexusAccount.getFactoryArgs(), | ||
nexusAccount.getStubSignature(), | ||
nexusAccount.signMessage({ message: "hello" }), | ||
nexusAccount.getNonce(), | ||
nexusAccount.getInitCode(), | ||
nexusAccount.isDeployed(), | ||
nexusAccount.encodeExecute({ to: account.address, value: 100n }), | ||
nexusAccount.encodeExecuteBatch([{ to: account.address, value: 100n }]) | ||
]) | ||
|
||
expect(counterfactualAddress).toBe( | ||
"0xa3962DB24D3cAb711e18d5A508591C6dB82a0f54" | ||
) | ||
expect(isHex(userOpHash)).toBe(true) | ||
expect(address).toBe("0xa3962DB24D3cAb711e18d5A508591C6dB82a0f54") | ||
expect(factoryArgs.factory).toBe( | ||
"0x8025afaD10209b8bEF3A3C94684AaE4D309c9996" | ||
) | ||
expect(factoryArgs.factoryData).toBe( | ||
"0x0d51f0b7000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
) | ||
expect(stubSignature).toBe( | ||
"0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000d98238BBAeA4f91683d250003799EAd31d7F5c55000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000" | ||
) | ||
expect(signedMessage).toBe( | ||
"0x0000000000000000000000008025afad10209b8bef3a3c94684aae4d309c99960000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000a40d51f0b7000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000008025afad10209b8bef3a3c94684aae4d309c99960000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000a40d51f0b7000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055d98238bbaea4f91683d250003799ead31d7f5c55f16ea9a3478698f695fd1401bfe27e9e4a7e8e3da94aa72b021125e31fa899cc573c48ea3fe1d4ab61a9db10c19032026e3ed2dbccba5a178235ac27f94504311c000000000000000000000064926492649264926492649264926492649264926492649264926492649264926492649264926492649264926492649264926492649264926492649264926492" | ||
) | ||
expect(nonce).toBe( | ||
22906337356820620590513465594309079979684970955157942146586636189696n | ||
) | ||
expect(initCode).toBe( | ||
"0x8025afaD10209b8bEF3A3C94684AaE4D309c99960d51f0b7000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
) | ||
expect(isDeployed).toBe(false) | ||
expect(encodedExecute).toBe( | ||
"0xe9ae5c53000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000034f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000064000000000000000000000000" | ||
) | ||
expect(encodedExecuteBatch).toBe( | ||
"0xe9ae5c530100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000" | ||
) | ||
}) | ||
}) |
Oops, something went wrong.