@@ -489,6 +489,100 @@ describe('Debug API Test Suite', async function () {
489
489
}
490
490
} ) ;
491
491
492
+ describe ( 'prestateTracer' , async function ( ) {
493
+ const prestateTracer : TracerType = TracerType . PrestateTracer ;
494
+ const mockPrestateResult = {
495
+ '0xc37f417fa09933335240fca72dd257bfbde9c275' : {
496
+ balance : '0x100000000' ,
497
+ nonce : 2 ,
498
+ code : '0x' ,
499
+ storage : { } ,
500
+ } ,
501
+ '0x637a6a8e5a69c087c24983b05261f63f64ed7e9b' : {
502
+ balance : '0x200000000' ,
503
+ nonce : 1 ,
504
+ code : '0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063' ,
505
+ storage : {
506
+ '0x0' : '0x1' ,
507
+ '0x1' : '0x2' ,
508
+ } ,
509
+ } ,
510
+ } ;
511
+
512
+ beforeEach ( ( ) => {
513
+ sinon . stub ( debugService , 'prestateTracer' ) . resolves ( mockPrestateResult ) ;
514
+ } ) ;
515
+
516
+ afterEach ( ( ) => {
517
+ sinon . restore ( ) ;
518
+ } ) ;
519
+
520
+ it ( 'should successfully trace transaction with prestateTracer' , async function ( ) {
521
+ const tracerObject = { tracer : prestateTracer } ;
522
+ const result = await debugService . traceTransaction ( transactionHash , tracerObject , requestDetails ) ;
523
+
524
+ expect ( result ) . to . deep . equal ( mockPrestateResult ) ;
525
+ expect ( result ) . to . be . an ( 'object' ) ;
526
+ expect ( Object . keys ( result ) ) . to . have . lengthOf ( 2 ) ;
527
+
528
+ for ( const address of Object . keys ( result ) ) {
529
+ expect ( result [ address ] ) . to . have . all . keys ( [ 'balance' , 'nonce' , 'code' , 'storage' ] ) ;
530
+ expect ( result [ address ] . nonce ) . to . be . a ( 'number' ) ;
531
+ expect ( result [ address ] . code ) . to . exist ;
532
+ expect ( result [ address ] . storage ) . to . be . an ( 'object' ) ;
533
+ }
534
+ } ) ;
535
+
536
+ it ( 'should trace transaction with prestateTracer and onlyTopCall=true' , async function ( ) {
537
+ const tracerObject = { tracer : prestateTracer , tracerConfig : { onlyTopCall : true } } ;
538
+ const result = await debugService . traceTransaction ( transactionHash , tracerObject , requestDetails ) ;
539
+
540
+ expect ( result ) . to . deep . equal ( mockPrestateResult ) ;
541
+
542
+ // Verify that prestateTracer was called with onlyTopCall=true
543
+ const prestateTracerStub = debugService . prestateTracer as sinon . SinonStub ;
544
+ expect ( prestateTracerStub . calledOnce ) . to . be . true ;
545
+ expect ( prestateTracerStub . calledWith ( transactionHash , true , requestDetails ) ) . to . be . true ;
546
+ } ) ;
547
+
548
+ it ( 'should trace transaction with prestateTracer and onlyTopCall=false (default)' , async function ( ) {
549
+ const tracerObject = { tracer : prestateTracer , tracerConfig : { onlyTopCall : false } } ;
550
+ const result = await debugService . traceTransaction ( transactionHash , tracerObject , requestDetails ) ;
551
+
552
+ expect ( result ) . to . deep . equal ( mockPrestateResult ) ;
553
+
554
+ // Verify that prestateTracer was called with onlyTopCall=false
555
+ const prestateTracerStub = debugService . prestateTracer as sinon . SinonStub ;
556
+ expect ( prestateTracerStub . calledOnce ) . to . be . true ;
557
+ expect ( prestateTracerStub . calledWith ( transactionHash , false , requestDetails ) ) . to . be . true ;
558
+ } ) ;
559
+
560
+ it ( 'should handle empty prestate result' , async function ( ) {
561
+ const emptyResult = { } ;
562
+ ( debugService . prestateTracer as sinon . SinonStub ) . resolves ( emptyResult ) ;
563
+
564
+ const tracerObject = { tracer : prestateTracer } ;
565
+ const result = await debugService . traceTransaction ( transactionHash , tracerObject , requestDetails ) ;
566
+
567
+ expect ( result ) . to . deep . equal ( emptyResult ) ;
568
+ expect ( result ) . to . be . an ( 'object' ) ;
569
+ expect ( Object . keys ( result ) ) . to . have . lengthOf ( 0 ) ;
570
+ } ) ;
571
+
572
+ it ( 'should propagate errors from prestateTracer' , async function ( ) {
573
+ const expectedError = predefined . RESOURCE_NOT_FOUND ( 'Failed to retrieve contract results' ) ;
574
+ ( debugService . prestateTracer as sinon . SinonStub ) . rejects ( expectedError ) ;
575
+
576
+ const tracerObject = { tracer : prestateTracer } ;
577
+
578
+ await RelayAssertions . assertRejection ( expectedError , debugService . traceTransaction , true , debugService , [
579
+ transactionHash ,
580
+ tracerObject ,
581
+ requestDetails ,
582
+ ] ) ;
583
+ } ) ;
584
+ } ) ;
585
+
492
586
describe ( 'Invalid scenarios' , async function ( ) {
493
587
let notFound : { _status : { messages : { message : string } [ ] } } ;
494
588
0 commit comments