@@ -13,10 +13,8 @@ import { type Fr } from '@aztec/foundation/fields';
13
13
import { type DebugLogger } from '@aztec/foundation/log' ;
14
14
import { openTmpStore } from '@aztec/kv-store/utils' ;
15
15
import {
16
- type PublicExecutionResult ,
17
- PublicExecutionResultBuilder ,
18
- type PublicExecutor ,
19
16
PublicProcessor ,
17
+ PublicTxSimulator ,
20
18
type SimulationProvider ,
21
19
WASMSimulator ,
22
20
type WorldStateDB ,
@@ -25,10 +23,12 @@ import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
25
23
import { MerkleTrees } from '@aztec/world-state' ;
26
24
import { NativeWorldStateService } from '@aztec/world-state/native' ;
27
25
26
+ import { jest } from '@jest/globals' ;
28
27
import * as fs from 'fs/promises' ;
29
28
import { type MockProxy , mock } from 'jest-mock-extended' ;
30
29
31
30
import { TestCircuitProver } from '../../../bb-prover/src/test/test_circuit_prover.js' ;
31
+ import { AvmFinalizedCallResult } from '../../../simulator/src/avm/avm_contract_call_result.js' ;
32
32
import { type AvmPersistableStateManager } from '../../../simulator/src/avm/journal/journal.js' ;
33
33
import { ProvingOrchestrator } from '../orchestrator/index.js' ;
34
34
import { MemoryProvingQueue } from '../prover-agent/memory-proving-queue.js' ;
@@ -37,7 +37,7 @@ import { getEnvironmentConfig, getSimulationProvider, makeGlobals } from './fixt
37
37
38
38
export class TestContext {
39
39
constructor (
40
- public publicExecutor : MockProxy < PublicExecutor > ,
40
+ public publicTxSimulator : PublicTxSimulator ,
41
41
public worldStateDB : MockProxy < WorldStateDB > ,
42
42
public publicProcessor : PublicProcessor ,
43
43
public simulationProvider : SimulationProvider ,
@@ -66,7 +66,6 @@ export class TestContext {
66
66
const directoriesToCleanup : string [ ] = [ ] ;
67
67
const globalVariables = makeGlobals ( blockNumber ) ;
68
68
69
- const publicExecutor = mock < PublicExecutor > ( ) ;
70
69
const worldStateDB = mock < WorldStateDB > ( ) ;
71
70
const telemetry = new NoopTelemetryClient ( ) ;
72
71
@@ -84,12 +83,13 @@ export class TestContext {
84
83
proverDb = await ws . getLatest ( ) ;
85
84
}
86
85
87
- const processor = PublicProcessor . create (
86
+ const publicTxSimulator = new PublicTxSimulator ( publicDb , worldStateDB , telemetry , globalVariables ) ;
87
+ const processor = new PublicProcessor (
88
88
publicDb ,
89
- publicExecutor ,
90
89
globalVariables ,
91
90
Header . empty ( ) ,
92
91
worldStateDB ,
92
+ publicTxSimulator ,
93
93
telemetry ,
94
94
) ;
95
95
@@ -124,7 +124,7 @@ export class TestContext {
124
124
agent . start ( queue ) ;
125
125
126
126
return new this (
127
- publicExecutor ,
127
+ publicTxSimulator ,
128
128
worldStateDB ,
129
129
processor ,
130
130
simulationProvider ,
@@ -154,25 +154,24 @@ export class TestContext {
154
154
) {
155
155
const defaultExecutorImplementation = (
156
156
_stateManager : AvmPersistableStateManager ,
157
- execution : PublicExecutionRequest ,
158
- _globalVariables : GlobalVariables ,
157
+ executionRequest : PublicExecutionRequest ,
159
158
allocatedGas : Gas ,
160
- _transactionFee ?: Fr ,
159
+ _transactionFee : Fr ,
160
+ _fnName : string ,
161
161
) => {
162
162
for ( const tx of txs ) {
163
163
const allCalls = tx . publicTeardownFunctionCall . isEmpty ( )
164
164
? tx . enqueuedPublicFunctionCalls
165
165
: [ ...tx . enqueuedPublicFunctionCalls , tx . publicTeardownFunctionCall ] ;
166
166
for ( const request of allCalls ) {
167
- if ( execution . callContext . equals ( request . callContext ) ) {
168
- const result = PublicExecutionResultBuilder . empty ( ) . build ( {
169
- endGasLeft : allocatedGas ,
170
- } ) ;
171
- return Promise . resolve ( result ) ;
167
+ if ( executionRequest . callContext . equals ( request . callContext ) ) {
168
+ return Promise . resolve (
169
+ new AvmFinalizedCallResult ( /*reverted=*/ false , /*output=*/ [ ] , /*gasLeft=*/ allocatedGas ) ,
170
+ ) ;
172
171
}
173
172
}
174
173
}
175
- throw new Error ( `Unexpected execution request: ${ execution } ` ) ;
174
+ throw new Error ( `Unexpected execution request: ${ executionRequest } ` ) ;
176
175
} ;
177
176
return await this . processPublicFunctionsWithMockExecutorImplementation (
178
177
txs ,
@@ -183,21 +182,36 @@ export class TestContext {
183
182
) ;
184
183
}
185
184
186
- public async processPublicFunctionsWithMockExecutorImplementation (
185
+ private async processPublicFunctionsWithMockExecutorImplementation (
187
186
txs : Tx [ ] ,
188
187
maxTransactions : number ,
189
188
txHandler ?: ProcessedTxHandler ,
190
189
txValidator ?: TxValidator < ProcessedTx > ,
191
190
executorMock ?: (
192
191
stateManager : AvmPersistableStateManager ,
193
- execution : PublicExecutionRequest ,
194
- globalVariables : GlobalVariables ,
192
+ executionRequest : PublicExecutionRequest ,
195
193
allocatedGas : Gas ,
196
- transactionFee ?: Fr ,
197
- ) => Promise < PublicExecutionResult > ,
194
+ transactionFee : Fr ,
195
+ fnName : string ,
196
+ ) => Promise < AvmFinalizedCallResult > ,
198
197
) {
198
+ // Mock the internal private function. Borrowed from https://stackoverflow.com/a/71033167
199
+ const simulateInternal : jest . SpiedFunction <
200
+ (
201
+ stateManager : AvmPersistableStateManager ,
202
+ executionResult : any ,
203
+ allocatedGas : Gas ,
204
+ transactionFee : any ,
205
+ fnName : any ,
206
+ ) => Promise < AvmFinalizedCallResult >
207
+ > = jest . spyOn (
208
+ this . publicTxSimulator as unknown as {
209
+ simulateEnqueuedCallInternal : PublicTxSimulator [ 'simulateEnqueuedCallInternal' ] ;
210
+ } ,
211
+ 'simulateEnqueuedCallInternal' ,
212
+ ) ;
199
213
if ( executorMock ) {
200
- this . publicExecutor . simulate . mockImplementation ( executorMock ) ;
214
+ simulateInternal . mockImplementation ( executorMock ) ;
201
215
}
202
216
return await this . publicProcessor . process ( txs , maxTransactions , txHandler , txValidator ) ;
203
217
}
0 commit comments