@@ -61,6 +61,28 @@ describe('Debug API Test Suite', async function () {
61
61
const CONTRACTS_RESULTS_BY_NON_EXISTENT_HASH = `contracts/results/${ nonExistentTransactionHash } ` ;
62
62
const CONTRACT_RESULTS_BY_ACTIONS_NON_EXISTENT_HASH = `contracts/results/${ nonExistentTransactionHash } /actions` ;
63
63
64
+ // Helper to reduce repetition when creating CREATE actions for tests
65
+ const makeCreateAction = ( overrides : Partial < any > = { } ) => ( {
66
+ call_depth : 0 ,
67
+ call_operation_type : 'CREATE' ,
68
+ call_type : 'CREATE' ,
69
+ caller : '0.0.1016' ,
70
+ caller_type : 'ACCOUNT' ,
71
+ from : senderAddress ,
72
+ gas : 247000 ,
73
+ gas_used : 77324 ,
74
+ index : 0 ,
75
+ input : '0x' ,
76
+ recipient : '0.0.1033' ,
77
+ recipient_type : 'CONTRACT' ,
78
+ result_data : '0x' ,
79
+ result_data_type : 'OUTPUT' ,
80
+ timestamp : '1696438011.462526383' ,
81
+ to : contractAddress ,
82
+ value : 0 ,
83
+ ...overrides ,
84
+ } ) ;
85
+
64
86
const opcodeLoggerConfigs = [
65
87
{
66
88
disableStack : true ,
@@ -199,44 +221,19 @@ describe('Debug API Test Suite', async function () {
199
221
200
222
const contractsResultsActionsResult = {
201
223
actions : [
202
- {
203
- call_depth : 0 ,
204
- call_operation_type : 'CREATE' ,
205
- call_type : 'CREATE' ,
206
- caller : '0.0.1016' ,
207
- caller_type : 'ACCOUNT' ,
208
- from : '0x00000000000000000000000000000000000003f8' ,
209
- gas : 247000 ,
210
- gas_used : 77324 ,
211
- index : 0 ,
212
- input : '0x' ,
213
- recipient : '0.0.1033' ,
214
- recipient_type : 'CONTRACT' ,
215
- result_data : '0x' ,
216
- result_data_type : 'OUTPUT' ,
217
- timestamp : '1696438011.462526383' ,
218
- to : '0x0000000000000000000000000000000000000409' ,
219
- value : 0 ,
220
- } ,
221
- {
224
+ makeCreateAction ( { index : 0 } ) ,
225
+ makeCreateAction ( {
222
226
call_depth : 1 ,
223
- call_operation_type : 'CREATE' ,
224
- call_type : 'CREATE' ,
225
227
caller : '0.0.1033' ,
226
228
caller_type : 'CONTRACT' ,
227
- from : '0x0000000000000000000000000000000000000409' ,
229
+ from : contractAddress ,
228
230
gas : 189733 ,
229
231
gas_used : 75 ,
230
232
index : 1 ,
231
- input : '0x' ,
232
233
recipient : '0.0.1034' ,
233
234
recipient_type : 'CONTRACT' ,
234
- result_data : '0x' ,
235
- result_data_type : 'OUTPUT' ,
236
- timestamp : '1696438011.462526383' ,
237
- to : '0x000000000000000000000000000000000000040a' ,
238
- value : 0 ,
239
- } ,
235
+ to : contractAddress2 ,
236
+ } ) ,
240
237
] ,
241
238
} ;
242
239
@@ -284,7 +281,7 @@ describe('Debug API Test Suite', async function () {
284
281
} ) ;
285
282
286
283
this . beforeEach ( ( ) => {
287
- cacheService . clear ( requestDetails ) ;
284
+ cacheService . clear ( ) ;
288
285
} ) ;
289
286
290
287
describe ( 'debug_traceTransaction' , async function ( ) {
@@ -640,6 +637,45 @@ describe('Debug API Test Suite', async function () {
640
637
expect ( address ) . to . eq ( accountAddress ) ;
641
638
} ) ;
642
639
} ) ;
640
+
641
+ describe ( 'formatActionsResult with CREATE actions' , async function ( ) {
642
+ it ( 'should handle CREATE with to=null and return expected fields' , async function ( ) {
643
+ const createActionWithNullTo = {
644
+ actions : [ makeCreateAction ( { to : null , input : '0x608060405234801561001057600080fd5b50' , index : 0 } ) ] ,
645
+ } ;
646
+
647
+ restMock . onGet ( SENDER_BY_ADDRESS ) . reply ( 200 , JSON . stringify ( accountsResult ) ) ;
648
+
649
+ const result = await debugService . formatActionsResult ( createActionWithNullTo . actions , requestDetails ) ;
650
+
651
+ expect ( result ) . to . be . an ( 'array' ) . with . lengthOf ( 1 ) ;
652
+ expect ( result [ 0 ] ) . to . have . property ( 'type' , 'CREATE' ) ;
653
+ expect ( result [ 0 ] ) . to . have . property ( 'from' , '0xc37f417fa09933335240fca72dd257bfbde9c275' ) ;
654
+ expect ( result [ 0 ] ) . to . have . property ( 'to' , null ) ;
655
+ expect ( result [ 0 ] ) . to . have . property ( 'input' , '0x608060405234801561001057600080fd5b50' ) ;
656
+ } ) ;
657
+
658
+ it ( 'should handle CREATE with to=null and skip getContract call' , async function ( ) {
659
+ const createActionWithNullTo = {
660
+ actions : [ makeCreateAction ( { to : null , input : '0x608060405234801561001057600080fd5b50' , index : 1 } ) ] ,
661
+ } ;
662
+
663
+ restMock . onGet ( SENDER_BY_ADDRESS ) . reply ( 200 , JSON . stringify ( accountsResult ) ) ;
664
+ // No mock for getContract call - should not be called
665
+ const getContractSpy = sinon . spy ( mirrorNodeInstance , 'getContract' ) ;
666
+ const result = await debugService . formatActionsResult ( createActionWithNullTo . actions , requestDetails ) ;
667
+
668
+ expect ( result ) . to . be . an ( 'array' ) . with . lengthOf ( 1 ) ;
669
+ expect ( result [ 0 ] ) . to . have . property ( 'type' , 'CREATE' ) ;
670
+ expect ( result [ 0 ] ) . to . have . property ( 'to' , null ) ;
671
+ expect ( result [ 0 ] ) . to . have . property ( 'input' , '0x608060405234801561001057600080fd5b50' ) ;
672
+ expect ( result [ 0 ] ) . to . have . property ( 'output' , '0x' ) ;
673
+ // Ensure getContract was never invoked with a null/undefined id (i.e., for 'to')
674
+ const calledWithNullId = getContractSpy . getCalls ( ) . some ( ( c ) => c . args [ 0 ] == null ) ;
675
+ expect ( calledWithNullId ) . to . be . false ;
676
+ getContractSpy . restore ( ) ;
677
+ } ) ;
678
+ } ) ;
643
679
} ) ;
644
680
} ) ;
645
681
} ) ;
@@ -710,7 +746,7 @@ describe('Debug API Test Suite', async function () {
710
746
sinon . restore ( ) ;
711
747
restMock . reset ( ) ;
712
748
web3Mock . reset ( ) ;
713
- cacheService . clear ( requestDetails ) ;
749
+ cacheService . clear ( ) ;
714
750
} ) ;
715
751
716
752
withOverriddenEnvsInMochaTest ( { DEBUG_API_ENABLED : undefined } , ( ) => {
@@ -894,44 +930,25 @@ describe('Debug API Test Suite', async function () {
894
930
const accountAddress = '0x00000000000000000000000000000000000003f8' ;
895
931
896
932
const actionsResponseMock = [
897
- {
898
- call_depth : 0 ,
899
- call_operation_type : 'CREATE' ,
900
- call_type : 'CREATE' ,
933
+ makeCreateAction ( {
901
934
caller : accountId ,
902
935
caller_type : 'ACCOUNT' ,
903
936
from : accountAddress ,
904
- gas : 247000 ,
905
- gas_used : 77324 ,
906
- index : 0 ,
907
- input : '0x' ,
908
937
recipient : contractId ,
909
- recipient_type : 'CONTRACT' ,
910
- result_data : '0x' ,
911
- result_data_type : 'OUTPUT' ,
912
- timestamp : mockTimestamp ,
913
938
to : contractAddress ,
914
- value : 0 ,
915
- } ,
916
- {
939
+ timestamp : mockTimestamp ,
940
+ index : 0 ,
941
+ } ) ,
942
+ makeCreateAction ( {
917
943
call_depth : 1 ,
918
- call_operation_type : 'CREATE' ,
919
- call_type : 'CREATE' ,
920
944
caller : contractId ,
921
945
caller_type : 'CONTRACT' ,
922
946
from : contractAddress ,
923
- gas : 189733 ,
924
- gas_used : 75 ,
925
- index : 1 ,
926
- input : '0x' ,
927
947
recipient : '0.0.1034' ,
928
- recipient_type : 'CONTRACT' ,
929
- result_data : '0x' ,
930
- result_data_type : 'OUTPUT' ,
931
- timestamp : mockTimestamp ,
932
948
to : '0x000000000000000000000000000000000000040a' ,
933
- value : 0 ,
934
- } ,
949
+ timestamp : mockTimestamp ,
950
+ index : 1 ,
951
+ } ) ,
935
952
] ;
936
953
937
954
const contractEntityMock = {
@@ -999,7 +1016,7 @@ describe('Debug API Test Suite', async function () {
999
1016
sinon . restore ( ) ;
1000
1017
restMock . reset ( ) ;
1001
1018
web3Mock . reset ( ) ;
1002
- cacheService . clear ( requestDetails ) ;
1019
+ cacheService . clear ( ) ;
1003
1020
} ) ;
1004
1021
1005
1022
withOverriddenEnvsInMochaTest ( { DEBUG_API_ENABLED : true } , ( ) => {
0 commit comments