1+ import { Hex } from "ox" ;
2+ import { encodePacked , stringToHex , toHex } from "viem" ;
13import { beforeAll , describe , expect , it } from "vitest" ;
24import { TEST_CLIENT } from "../../../test/src/test-clients.js" ;
35import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js" ;
46import { baseSepolia } from "../../chains/chain-definitions/base-sepolia.js" ;
7+ import { ZERO_ADDRESS } from "../../constants/addresses.js" ;
58import { type ThirdwebContract , getContract } from "../../contract/contract.js" ;
9+ import { getNonce } from "../../extensions/erc4337/__generated__/IEntryPoint/read/getNonce.js" ;
610import { encodeSingleInitMSA } from "../../extensions/erc7579/__generated__/Bootstrap/write/singleInitMSA.js" ;
11+ import { execute } from "../../extensions/erc7579/__generated__/IERC7579Account/write/execute.js" ;
712import { sendTransaction } from "../../transaction/actions/send-transaction.js" ;
813import { prepareContractCall } from "../../transaction/prepare-contract-call.js" ;
914import { prepareTransaction } from "../../transaction/prepare-transaction.js" ;
@@ -14,6 +19,7 @@ import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js
1419import { keccak256 } from "../../utils/hashing/keccak256.js" ;
1520import type { Account , Wallet } from "../interfaces/wallet.js" ;
1621import { ENTRYPOINT_ADDRESS_v0_7 } from "./lib/constants.js" ;
22+ import { generateRandomUint192 } from "./lib/utils.js" ;
1723import { smartWallet } from "./smart-wallet.js" ;
1824let wallet : Wallet ;
1925let smartAccount : Account ;
@@ -38,6 +44,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
3844 // personalAccount = await generateAccount({
3945 // client,
4046 // });
47+ const VALIDATOR_ADDRESS = "0x6DF8ea6FF6Ca55f367CDA45510CA40dC78993DEC" ;
4148 wallet = smartWallet ( {
4249 chain,
4350 gasless : true ,
@@ -53,9 +60,9 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
5360 encodeAbiParameters (
5461 [ { type : "address" } , { type : "bytes" } ] ,
5562 [
56- "0x1E919660050C68BFEf868945Cf5f9a26ad7E360b " , // bootstrap
63+ "0xedd4503de72bac321dfeb65f1373d2def17403fc " , // bootstrap
5764 encodeSingleInitMSA ( {
58- validator : "0x11D02847245Df7cF19f48C8907ace59289D8aCEe" , // mock validator
65+ validator : VALIDATOR_ADDRESS , // simple validator
5966 data : "0x" ,
6067 } ) ,
6168 ] ,
@@ -73,16 +80,50 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
7380 encodeAbiParameters (
7481 [ { type : "address" } , { type : "bytes" } ] ,
7582 [
76- "0x1E919660050C68BFEf868945Cf5f9a26ad7E360b " , // bootstrap
83+ "0xedd4503de72bac321dfeb65f1373d2def17403fc " , // bootstrap
7784 encodeSingleInitMSA ( {
78- validator : "0x11D02847245Df7cF19f48C8907ace59289D8aCEe" , // mock validator
85+ validator : VALIDATOR_ADDRESS , // simple validator
7986 data : "0x" ,
8087 } ) ,
8188 ] ,
8289 ) ,
8390 ] ,
8491 } ) ;
8592 } ,
93+ execute ( accountContract , transaction ) {
94+ return execute ( {
95+ contract : accountContract ,
96+ async asyncParams ( ) {
97+ return {
98+ mode : stringToHex ( "" , { size : 32 } ) , // single execution
99+ executionCalldata : encodePacked (
100+ [ "address" , "uint256" , "bytes" ] ,
101+ [
102+ transaction . to || ZERO_ADDRESS ,
103+ transaction . value || 0n ,
104+ transaction . data || "0x" ,
105+ ] ,
106+ ) ,
107+ } ;
108+ } ,
109+ } ) ;
110+ } ,
111+ async getAccountNonce ( accountContract ) {
112+ const nonce = await getNonce ( {
113+ contract : getContract ( {
114+ address : ENTRYPOINT_ADDRESS_v0_7 ,
115+ chain,
116+ client,
117+ } ) ,
118+ key : generateRandomUint192 ( ) ,
119+ sender : accountContract . address ,
120+ } ) ;
121+ // FIXME - only for modular accounts to pass validator in
122+ const withValidator = `${ VALIDATOR_ADDRESS } ${ toHex ( nonce ) . slice ( 42 ) } ` ;
123+ console . log ( "DEBUG withValidator" , withValidator ) ;
124+ console . log ( "DEBUG withValidator" , withValidator . length ) ;
125+ return Hex . toBigInt ( withValidator as Hex . Hex ) ;
126+ } ,
86127 } ,
87128 } ) ;
88129 smartAccount = await wallet . connect ( {
@@ -101,7 +142,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
101142 expect ( smartWalletAddress ) . toHaveLength ( 42 ) ;
102143
103144 // const d = decodeErrorResult({
104- // data: "0xb927fe5e0000000000000000000000000000000000000000db72e07d8a92f3d9d30e3843 ",
145+ // data: "0x48c9cedab61d27f600000000000000000000000000000000000000000000000000000000 ",
105146 // abi: await resolveContractAbi({
106147 // address: smartWalletAddress,
107148 // client,
0 commit comments