1- import { jsonRpcErrors , getByteCode , visit , createEnv } from './util.ts'
1+ import {
2+ jsonRpcErrors ,
3+ getByteCode ,
4+ visit ,
5+ createEnv ,
6+ deployFactory ,
7+ } from './util.ts'
28import { afterEach , describe , expect , inject , test } from 'vitest'
39import fs from 'node:fs'
410import { fail } from 'node:assert'
511
6- import { encodeFunctionData , Hex , parseEther , decodeEventLog } from 'viem'
12+ import { encodeFunctionData , parseEther , decodeEventLog } from 'viem'
713import { ErrorsAbi } from '../abi/Errors.ts'
814import { EventExampleAbi } from '../abi/EventExample.ts'
915import { TracingCallerAbi } from '../abi/TracingCaller.ts'
@@ -15,78 +21,36 @@ afterEach(() => {
1521
1622const envs = await Promise . all ( inject ( 'envs' ) . map ( createEnv ) )
1723for ( const env of envs ) {
18- describe ( `${ env . serverWallet . chain . name } ` , ( ) => {
19- const getErrorTesterAddr = ( ( ) => {
20- let contractAddress : Hex = '0x'
21- return async ( ) => {
22- if ( contractAddress !== '0x' ) {
23- return contractAddress
24- }
25- const hash = await env . serverWallet . deployContract ( {
26- abi : ErrorsAbi ,
27- bytecode : getByteCode ( 'Errors' , env . evm ) ,
28- } )
29- const deployReceipt =
30- await env . serverWallet . waitForTransactionReceipt ( { hash } )
31- contractAddress = deployReceipt . contractAddress !
32- return contractAddress
33- }
34- } ) ( )
24+ const [ getErrorTesterAddr ] = deployFactory ( env , ( ) =>
25+ env . serverWallet . deployContract ( {
26+ abi : ErrorsAbi ,
27+ bytecode : getByteCode ( 'Errors' , env . evm ) ,
28+ } )
29+ )
3530
36- const getEventExampleAddr = ( ( ) => {
37- let contractAddress : Hex = '0x'
38- return async ( ) => {
39- if ( contractAddress !== '0x' ) {
40- return contractAddress
41- }
42- const hash = await env . serverWallet . deployContract ( {
43- abi : EventExampleAbi ,
44- bytecode : getByteCode ( 'EventExample' , env . evm ) ,
45- } )
46- const deployReceipt =
47- await env . serverWallet . waitForTransactionReceipt ( { hash } )
48- contractAddress = deployReceipt . contractAddress !
49- return contractAddress
50- }
51- } ) ( )
52-
53- const getTracingExampleAddrs = ( ( ) => {
54- let callerAddr : Hex = '0x'
55- let calleeAddr : Hex = '0x'
56- return async ( ) => {
57- if ( callerAddr !== '0x' ) {
58- return [ callerAddr , calleeAddr ]
59- }
60- calleeAddr = await ( async ( ) => {
61- const hash = await env . serverWallet . deployContract ( {
62- abi : TracingCalleeAbi ,
63- bytecode : getByteCode ( 'TracingCallee' , env . evm ) ,
64- } )
65- const receipt =
66- await env . serverWallet . waitForTransactionReceipt ( {
67- hash,
68- } )
69- return receipt . contractAddress !
70- } ) ( )
71-
72- callerAddr = await ( async ( ) => {
73- const hash = await env . serverWallet . deployContract ( {
74- abi : TracingCallerAbi ,
75- args : [ calleeAddr ] ,
76- bytecode : getByteCode ( 'TracingCaller' , env . evm ) ,
77- value : parseEther ( '10' ) ,
78- } )
79- const receipt =
80- await env . serverWallet . waitForTransactionReceipt ( {
81- hash,
82- } )
83- return receipt . contractAddress !
84- } ) ( )
85-
86- return [ callerAddr , calleeAddr ]
87- }
88- } ) ( )
31+ const [ getEventExampleAddr ] = deployFactory ( env , async ( ) =>
32+ env . serverWallet . deployContract ( {
33+ abi : EventExampleAbi ,
34+ bytecode : getByteCode ( 'EventExample' , env . evm ) ,
35+ } )
36+ )
8937
38+ const [ getTracingCalleeAddr ] = deployFactory ( env , async ( ) =>
39+ env . serverWallet . deployContract ( {
40+ abi : TracingCalleeAbi ,
41+ bytecode : getByteCode ( 'TracingCallee' , env . evm ) ,
42+ } )
43+ )
44+
45+ const [ getTracingCallerAddr ] = deployFactory ( env , async ( ) =>
46+ env . serverWallet . deployContract ( {
47+ abi : TracingCallerAbi ,
48+ args : [ await getTracingCalleeAddr ( ) ] ,
49+ bytecode : getByteCode ( 'TracingCaller' , env . evm ) ,
50+ value : parseEther ( '10' ) ,
51+ } )
52+ )
53+ describe ( `${ env . serverWallet . chain . name } ` , ( ) => {
9054 test ( 'triggerAssertError' , async ( ) => {
9155 try {
9256 await env . accountWallet . readContract ( {
@@ -390,7 +354,8 @@ for (const env of envs) {
390354 } )
391355
392356 test ( 'tracing' , async ( ) => {
393- let [ callerAddr , calleeAddr ] = await getTracingExampleAddrs ( )
357+ const calleeAddr = await getTracingCalleeAddr ( )
358+ const callerAddr = await getTracingCallerAddr ( )
394359
395360 const receipt = await ( async ( ) => {
396361 const { request } = await env . serverWallet . simulateContract ( {
0 commit comments