@@ -18,6 +18,7 @@ import ServicesClient from '../clients/servicesClient';
1818import basicContractJson from '../contracts/Basic.json' ;
1919import parentContractJson from '../contracts/Parent.json' ;
2020import reverterContractJson from '../contracts/Reverter.json' ;
21+ import Assertions from '../helpers/assertions' ;
2122import { Utils } from '../helpers/utils' ;
2223import { AliasAccount } from '../types/AliasAccount' ;
2324
@@ -51,6 +52,20 @@ describe('@debug API Acceptance Tests', function () {
5152 const DEBUG_TRACE_BLOCK_BY_NUMBER = 'debug_traceBlockByNumber' ;
5253 const DEBUG_TRACE_TRANSACTION = 'debug_traceTransaction' ;
5354
55+ const TRACER_CONFIGS = {
56+ CALL_TRACER_TOP_ONLY_FALSE : { tracer : TracerType . CallTracer , onlyTopCall : false } ,
57+ CALL_TRACER_TOP_ONLY : { tracer : TracerType . CallTracer , onlyTopCall : true } ,
58+ PRESTATE_TRACER : { tracer : TracerType . PrestateTracer } ,
59+ PRESTATE_TRACER_TOP_ONLY : { tracer : TracerType . PrestateTracer , onlyTopCall : true } ,
60+ PRESTATE_TRACER_TOP_ONLY_FALSE : { tracer : TracerType . PrestateTracer , onlyTopCall : false } ,
61+ OPCODE_LOGGER : { tracer : TracerType . OpcodeLogger } ,
62+ OPCODE_WITH_MEMORY : { tracer : TracerType . OpcodeLogger , enableMemory : true } ,
63+ OPCODE_WITH_MEMORY_AND_STACK : { tracer : TracerType . OpcodeLogger , enableMemory : true , enableStack : true } ,
64+ OPCODE_WITH_STACK : { tracer : TracerType . OpcodeLogger , disableStack : true } ,
65+ OPCODE_WITH_STORAGE : { tracer : TracerType . OpcodeLogger , disableStorage : true } ,
66+ OPCODE_WITH_MEMORY_AND_STORAGE : { tracer : TracerType . OpcodeLogger , enableMemory : true , disableStorage : true } ,
67+ } ;
68+
5469 before ( async ( ) => {
5570 requestId = Utils . generateRequestId ( ) ;
5671 const initialAccount : AliasAccount = global . accounts [ 0 ] ;
@@ -130,10 +145,12 @@ describe('@debug API Acceptance Tests', function () {
130145 const txTrace = result . find ( ( trace ) => trace . txHash === transactionHash ) ;
131146 expect ( txTrace ) . to . exist ;
132147 expect ( txTrace . result ) . to . exist ;
133- expect ( txTrace . result . type ) . to . equal ( 'CALL' ) ;
134- expect ( txTrace . result . from . toLowerCase ( ) ) . to . equal ( accounts [ 0 ] . address . toLowerCase ( ) ) ;
135- expect ( txTrace . result . to . toLowerCase ( ) ) . to . equal ( basicContractAddress . toLowerCase ( ) ) ;
136- expect ( txTrace . result . input ) . to . equal ( BASIC_CONTRACT_PING_CALL_DATA ) ;
148+ Assertions . validateCallTracerResult (
149+ txTrace . result ,
150+ BASIC_CONTRACT_PING_CALL_DATA ,
151+ accounts [ 0 ] . address ,
152+ basicContractAddress ,
153+ ) ;
137154 } ) ;
138155
139156 it ( '@release should trace a block containing a failing transaction using CallTracer' , async function ( ) {
@@ -168,12 +185,12 @@ describe('@debug API Acceptance Tests', function () {
168185
169186 // Find our transaction in the result
170187 const txTrace = result . find ( ( trace ) => trace . txHash === transactionHash ) ;
171- expect ( txTrace ) . to . exist ;
172- expect ( txTrace . result ) . to . exist ;
173- expect ( txTrace . result . type ) . to . equal ( 'CALL' ) ;
174- expect ( txTrace . result . from . toLowerCase ( ) ) . to . equal ( accounts [ 0 ] . address . toLowerCase ( ) ) ;
175- expect ( txTrace . result . to . toLowerCase ( ) ) . to . equal ( reverterContractAddress . toLowerCase ( ) ) ;
176- expect ( txTrace . result . input ) . to . equal ( PURE_METHOD_CALL_DATA ) ;
188+ Assertions . validateCallTracerResult (
189+ txTrace . result ,
190+ PURE_METHOD_CALL_DATA ,
191+ accounts [ 0 ] . address ,
192+ reverterContractAddress ,
193+ ) ;
177194 expect ( txTrace . result . error ) . to . exist ; // There should be an error field for the reverted transaction
178195 expect ( txTrace . result . revertReason ) . to . exist ; // There should be a revert reason
179196 } ) ;
@@ -203,8 +220,11 @@ describe('@debug API Acceptance Tests', function () {
203220 const blockNumber = receipt . blockNumber ;
204221
205222 // Call debug_traceBlockByNumber with PrestateTracer
206- const tracerConfig = { tracer : TracerType . PrestateTracer } ;
207- const result = await relay . call ( DEBUG_TRACE_BLOCK_BY_NUMBER , [ blockNumber , tracerConfig ] , requestId ) ;
223+ const result = await relay . call (
224+ DEBUG_TRACE_BLOCK_BY_NUMBER ,
225+ [ blockNumber , TRACER_CONFIGS . PRESTATE_TRACER ] ,
226+ requestId ,
227+ ) ;
208228
209229 expect ( result ) . to . be . an ( 'array' ) ;
210230 expect ( result . length ) . to . be . at . least ( 1 ) ;
@@ -221,10 +241,7 @@ describe('@debug API Acceptance Tests', function () {
221241 // For each address in the result, check it has the expected fields
222242 for ( const address of keys ) {
223243 const state = txTrace . result [ address ] ;
224- expect ( state ) . to . have . property ( 'balance' ) ;
225- expect ( state ) . to . have . property ( 'nonce' ) ;
226- expect ( state ) . to . have . property ( 'code' ) ;
227- expect ( state ) . to . have . property ( 'storage' ) ;
244+ Assertions . validatePrestateTracerResult ( state ) ;
228245 }
229246 } ) ;
230247
@@ -251,14 +268,16 @@ describe('@debug API Acceptance Tests', function () {
251268 const blockNumber = receipt . blockNumber ;
252269
253270 // First trace with onlyTopCall=false (default)
254- const fullTracerConfig = { tracer : TracerType . PrestateTracer , onlyTopCall : false } ;
255- const fullResult = await relay . call ( DEBUG_TRACE_BLOCK_BY_NUMBER , [ blockNumber , fullTracerConfig ] , requestId ) ;
271+ const fullResult = await relay . call (
272+ DEBUG_TRACE_BLOCK_BY_NUMBER ,
273+ [ blockNumber , TRACER_CONFIGS . PRESTATE_TRACER_TOP_ONLY_FALSE ] ,
274+ requestId ,
275+ ) ;
256276
257277 // Then trace with onlyTopCall=true
258- const topCallTracerConfig = { tracer : TracerType . PrestateTracer , onlyTopCall : true } ;
259278 const topCallResult = await relay . call (
260279 DEBUG_TRACE_BLOCK_BY_NUMBER ,
261- [ blockNumber , topCallTracerConfig ] ,
280+ [ blockNumber , TRACER_CONFIGS . PRESTATE_TRACER_TOP_ONLY ] ,
262281 requestId ,
263282 ) ;
264283
@@ -290,10 +309,7 @@ describe('@debug API Acceptance Tests', function () {
290309 // Each address should have the standard fields
291310 for ( const address of topCallAddresses ) {
292311 const state = topCallTxTrace . result [ address ] ;
293- expect ( state ) . to . have . property ( 'balance' ) ;
294- expect ( state ) . to . have . property ( 'nonce' ) ;
295- expect ( state ) . to . have . property ( 'code' ) ;
296- expect ( state ) . to . have . property ( 'storage' ) ;
312+ Assertions . validatePrestateTracerResult ( state ) ;
297313 }
298314 } ) ;
299315
@@ -325,10 +341,9 @@ describe('@debug API Acceptance Tests', function () {
325341
326342 if ( ! hasTransactions ) {
327343 // Found a block without transactions
328- const tracerConfig = { tracer : TracerType . CallTracer , onlyTopCall : false } ;
329344 const result = await relay . call (
330345 DEBUG_TRACE_BLOCK_BY_NUMBER ,
331- [ numberTo0x ( blockNumberToTest ) , tracerConfig ] ,
346+ [ numberTo0x ( blockNumberToTest ) , TRACER_CONFIGS . CALL_TRACER_TOP_ONLY_FALSE ] ,
332347 requestId ,
333348 ) ;
334349
@@ -348,12 +363,10 @@ describe('@debug API Acceptance Tests', function () {
348363 ConfigServiceTestHelper . dynamicOverride ( 'DEBUG_API_ENABLED' , false ) ;
349364
350365 try {
351- const tracerConfig = { tracer : TracerType . CallTracer , onlyTopCall : false } ;
352-
353366 // Should return UNSUPPORTED_METHOD error
354367 await relay . callFailing (
355368 DEBUG_TRACE_BLOCK_BY_NUMBER ,
356- [ numberTo0x ( deploymentBlockNumber ) , tracerConfig ] ,
369+ [ numberTo0x ( deploymentBlockNumber ) , TRACER_CONFIGS . CALL_TRACER_TOP_ONLY_FALSE ] ,
357370 predefined . UNSUPPORTED_METHOD ,
358371 requestId ,
359372 ) ;
@@ -364,12 +377,10 @@ describe('@debug API Acceptance Tests', function () {
364377 } ) ;
365378
366379 it ( 'should fail with INVALID_PARAMETER when given an invalid block number' , async function ( ) {
367- const tracerConfig = { tracer : TracerType . CallTracer , onlyTopCall : false } ;
368-
369380 // Invalid block number format
370381 await relay . callFailing (
371382 DEBUG_TRACE_BLOCK_BY_NUMBER ,
372- [ 'invalidBlockNumber' , tracerConfig ] ,
383+ [ 'invalidBlockNumber' , TRACER_CONFIGS . CALL_TRACER_TOP_ONLY_FALSE ] ,
373384 predefined . INVALID_PARAMETER (
374385 '0' ,
375386 'Expected 0x prefixed hexadecimal block number, or the string "latest", "earliest" or "pending"' ,
@@ -412,9 +423,8 @@ describe('@debug API Acceptance Tests', function () {
412423 // @ts -ignore
413424 createChildTx = await parentContract . createChild ( 1 ) ;
414425
415- const receipt = await relay . pollForValidTransactionReceipt ( createChildTx . hash ) ;
416- console . log ( createChildTx . hash ) ;
417- console . log ( 'receipt' , receipt ) ;
426+ await relay . pollForValidTransactionReceipt ( createChildTx . hash ) ;
427+
418428 // Get contract result details from mirror node
419429 mirrorContractDetails = await mirrorNode . get ( `/contracts/results/${ createChildTx . hash } ` , requestId ) ;
420430 mirrorContractDetails . from = accounts [ 0 ] . address ;
@@ -423,41 +433,35 @@ describe('@debug API Acceptance Tests', function () {
423433 describe ( 'Call Tracer' , ( ) => {
424434 it ( 'should trace a transaction using CallTracer with onlyTopCall=false' , async function ( ) {
425435 // Call debug_traceTransaction with CallTracer (default config)
426- const tracerConfig = { tracer : TracerType . CallTracer , tracerConfig : { onlyTopCall : false } } ;
427- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
436+ const result = await relay . call (
437+ DEBUG_TRACE_TRANSACTION ,
438+ [ createChildTx . hash , TRACER_CONFIGS . CALL_TRACER_TOP_ONLY_FALSE ] ,
439+ requestId ,
440+ ) ;
428441
429- console . log ( 'result' , result ) ;
430- expect ( result ) . to . be . an ( 'object' ) ;
431- expect ( result ) . to . have . property ( 'type' , 'CALL' ) ;
432- expect ( result ) . to . have . property ( 'from' ) ;
433- expect ( result . from . toLowerCase ( ) ) . to . equal ( accounts [ 0 ] . address . toLowerCase ( ) ) ;
434- expect ( result ) . to . have . property ( 'to' ) ;
435- expect ( result . to . toLowerCase ( ) ) . to . equal ( parentContractAddress . toLowerCase ( ) ) ;
436- expect ( result ) . to . have . property ( 'value' ) ;
437- expect ( result ) . to . have . property ( 'gas' ) ;
438- expect ( result ) . to . have . property ( 'gasUsed' ) ;
439- expect ( result ) . to . have . property ( 'input' , PARENT_CONTRACT_CREATE_CHILD_CALL_DATA ) ;
440- expect ( result ) . to . have . property ( 'output' ) ;
442+ Assertions . validateCallTracerResult (
443+ result ,
444+ PARENT_CONTRACT_CREATE_CHILD_CALL_DATA ,
445+ accounts [ 0 ] . address ,
446+ parentContractAddress ,
447+ ) ;
441448 expect ( result ) . to . have . property ( 'calls' ) ;
442449 } ) ;
443450
444451 it ( 'should trace a transaction using CallTracer with onlyTopCall=true' , async function ( ) {
445452 // Call debug_traceTransaction with CallTracer (default config)
446- const tracerConfig = { tracer : TracerType . CallTracer , tracerConfig : { onlyTopCall : true } } ;
447- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
453+ const result = await relay . call (
454+ DEBUG_TRACE_TRANSACTION ,
455+ [ createChildTx . hash , TRACER_CONFIGS . CALL_TRACER_TOP_ONLY ] ,
456+ requestId ,
457+ ) ;
448458
449- console . log ( 'result 2' , result ) ;
450- expect ( result ) . to . be . an ( 'object' ) ;
451- expect ( result ) . to . have . property ( 'type' , 'CALL' ) ;
452- expect ( result ) . to . have . property ( 'from' ) ;
453- expect ( result . from . toLowerCase ( ) ) . to . equal ( accounts [ 0 ] . address . toLowerCase ( ) ) ;
454- expect ( result ) . to . have . property ( 'to' ) ;
455- expect ( result . to . toLowerCase ( ) ) . to . equal ( parentContractAddress . toLowerCase ( ) ) ;
456- expect ( result ) . to . have . property ( 'value' ) ;
457- expect ( result ) . to . have . property ( 'gas' ) ;
458- expect ( result ) . to . have . property ( 'gasUsed' ) ;
459- expect ( result ) . to . have . property ( 'input' , PARENT_CONTRACT_CREATE_CHILD_CALL_DATA ) ;
460- expect ( result ) . to . have . property ( 'output' ) ;
459+ Assertions . validateCallTracerResult (
460+ result ,
461+ PARENT_CONTRACT_CREATE_CHILD_CALL_DATA ,
462+ accounts [ 0 ] . address ,
463+ parentContractAddress ,
464+ ) ;
461465 expect ( result ) . to . not . have . property ( 'calls' ) ;
462466 } ) ;
463467 } ) ;
@@ -467,12 +471,7 @@ describe('@debug API Acceptance Tests', function () {
467471 const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash ] , requestId ) ;
468472
469473 // Validate response structure for OpcodeLogger
470- expect ( result ) . to . be . an ( 'object' ) ;
471- expect ( result ) . to . have . property ( 'gas' ) ;
472- expect ( result ) . to . have . property ( 'failed' ) ;
473- expect ( result ) . to . have . property ( 'returnValue' ) ;
474- expect ( result ) . to . have . property ( 'structLogs' ) ;
475- expect ( result . structLogs ) . to . be . an ( 'array' ) ;
474+ Assertions . validateOpcodeLoggerResult ( result ) ;
476475
477476 // Check that structLogs contains opcode information
478477 if ( result . structLogs . length > 0 ) {
@@ -486,23 +485,21 @@ describe('@debug API Acceptance Tests', function () {
486485 } ) ;
487486
488487 it ( '@release should trace a successful transaction using OpcodeLogger explicitly' , async function ( ) {
489- const tracerConfig = { tracer : TracerType . OpcodeLogger } ;
490- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
488+ const result = await relay . call (
489+ DEBUG_TRACE_TRANSACTION ,
490+ [ createChildTx . hash , TRACER_CONFIGS . OPCODE_LOGGER ] ,
491+ requestId ,
492+ ) ;
491493
492- expect ( result ) . to . be . an ( 'object' ) ;
493- expect ( result ) . to . have . property ( 'gas' ) ;
494- expect ( result ) . to . have . property ( 'failed' ) ;
495- expect ( result ) . to . have . property ( 'returnValue' ) ;
496- expect ( result ) . to . have . property ( 'structLogs' ) ;
497- expect ( result . structLogs ) . to . be . an ( 'array' ) ;
494+ Assertions . validateOpcodeLoggerResult ( result ) ;
498495 } ) ;
499496
500497 it ( '@release should trace using OpcodeLogger with custom config (enableMemory=true)' , async function ( ) {
501- const tracerConfig = {
502- tracer : TracerType . OpcodeLogger ,
503- tracerConfig : { enableMemory : true } ,
504- } ;
505- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
498+ const result = await relay . call (
499+ DEBUG_TRACE_TRANSACTION ,
500+ [ createChildTx . hash , TRACER_CONFIGS . OPCODE_WITH_MEMORY ] ,
501+ requestId ,
502+ ) ;
506503
507504 expect ( result ) . to . be . an ( 'object' ) ;
508505 expect ( result ) . to . have . property ( 'structLogs' ) ;
@@ -515,11 +512,11 @@ describe('@debug API Acceptance Tests', function () {
515512 } ) ;
516513
517514 it ( '@release should trace using OpcodeLogger with custom config (disableStack=true)' , async function ( ) {
518- const tracerConfig = {
519- tracer : TracerType . OpcodeLogger ,
520- tracerConfig : { disableStack : true } ,
521- } ;
522- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
515+ const result = await relay . call (
516+ DEBUG_TRACE_TRANSACTION ,
517+ [ createChildTx . hash , TRACER_CONFIGS . OPCODE_WITH_STACK ] ,
518+ requestId ,
519+ ) ;
523520
524521 expect ( result ) . to . be . an ( 'object' ) ;
525522 expect ( result ) . to . have . property ( 'structLogs' ) ;
@@ -532,11 +529,11 @@ describe('@debug API Acceptance Tests', function () {
532529 } ) ;
533530
534531 it ( '@release should trace using OpcodeLogger with custom config (disableStorage=true)' , async function ( ) {
535- const tracerConfig = {
536- tracer : TracerType . OpcodeLogger ,
537- tracerConfig : { disableStorage : true } ,
538- } ;
539- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
532+ const result = await relay . call (
533+ DEBUG_TRACE_TRANSACTION ,
534+ [ createChildTx . hash , TRACER_CONFIGS . OPCODE_WITH_STORAGE ] ,
535+ requestId ,
536+ ) ;
540537
541538 expect ( result ) . to . be . an ( 'object' ) ;
542539 expect ( result ) . to . have . property ( 'structLogs' ) ;
@@ -549,11 +546,11 @@ describe('@debug API Acceptance Tests', function () {
549546 } ) ;
550547
551548 it ( '@release should trace using OpcodeLogger with custom config (enableMemory=true, disableStorage=true)' , async function ( ) {
552- const tracerConfig = {
553- tracer : TracerType . OpcodeLogger ,
554- tracerConfig : { enableMemory : true , disableStorage : true } ,
555- } ;
556- const result = await relay . call ( DEBUG_TRACE_TRANSACTION , [ createChildTx . hash , tracerConfig ] , requestId ) ;
549+ const result = await relay . call (
550+ DEBUG_TRACE_TRANSACTION ,
551+ [ createChildTx . hash , TRACER_CONFIGS . OPCODE_WITH_MEMORY_AND_STORAGE ] ,
552+ requestId ,
553+ ) ;
557554
558555 expect ( result ) . to . be . an ( 'object' ) ;
559556 expect ( result ) . to . have . property ( 'structLogs' ) ;
@@ -590,23 +587,18 @@ describe('@debug API Acceptance Tests', function () {
590587
591588 it ( 'should fail with RESOURCE_NOT_FOUND for non-existent transaction hash with tracer' , async function ( ) {
592589 const nonExistentHash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdee' ;
593- const tracer = {
594- tracer : TracerType . CallTracer ,
595- tracerConfig : { onlyTopCall : true } ,
596- } ;
597590 await relay . callFailing (
598591 DEBUG_TRACE_TRANSACTION ,
599- [ nonExistentHash , tracer ] ,
592+ [ nonExistentHash , TRACER_CONFIGS . CALL_TRACER_TOP_ONLY ] ,
600593 predefined . RESOURCE_NOT_FOUND ( `Failed to retrieve contract results for transaction ${ nonExistentHash } ` ) ,
601594 requestId ,
602595 ) ;
603596 } ) ;
604597
605598 it ( 'should fail with INVALID_PARAMETER when using PrestateTracer' , async function ( ) {
606- const tracerConfig = { tracer : TracerType . PrestateTracer } ;
607599 await relay . callFailing (
608600 DEBUG_TRACE_TRANSACTION ,
609- [ createChildTx . hash , tracerConfig ] ,
601+ [ createChildTx . hash , TRACER_CONFIGS . PRESTATE_TRACER ] ,
610602 predefined . INVALID_PARAMETER ( 1 , 'Prestate tracer is not yet supported on debug_traceTransaction' ) ,
611603 requestId ,
612604 ) ;
@@ -688,7 +680,7 @@ describe('@debug API Acceptance Tests', function () {
688680 ConfigServiceTestHelper . dynamicOverride ( 'DEBUG_API_ENABLED' , false ) ;
689681
690682 try {
691- const tracerConfig = { tracer : TracerType . CallTracer } ;
683+ const tracerConfig = { tracer : TracerType . CallTracer , tracerConfig : { onlyTopCall : false } } ;
692684
693685 // Should return UNSUPPORTED_METHOD error
694686 await relay . callFailing (
0 commit comments