@@ -657,11 +657,6 @@ describe('TransactionController', () => {
657
657
( controller as any ) . update ( ( ) => state ) ;
658
658
}
659
659
660
- multichainTrackingHelperClassMock . mock . calls [ 0 ] [ 0 ] . createIncomingTransactionHelper (
661
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
662
- { } as any ,
663
- ) ;
664
-
665
660
multichainTrackingHelperClassMock . mock . calls [ 0 ] [ 0 ] . createPendingTransactionTracker (
666
661
// eslint-disable-next-line @typescript-eslint/no-explicit-any
667
662
{ } as any ,
@@ -777,6 +772,8 @@ describe('TransactionController', () => {
777
772
}
778
773
779
774
beforeEach ( ( ) => {
775
+ jest . resetAllMocks ( ) ;
776
+
780
777
jest . spyOn ( Date , 'now' ) . mockImplementation ( ( ) => {
781
778
timeCounter += 1 ;
782
779
return timeCounter ;
@@ -2613,21 +2610,6 @@ describe('TransactionController', () => {
2613
2610
expect ( controller . state . transactions ) . toHaveLength ( 1 ) ;
2614
2611
expect ( controller . state . transactions [ 0 ] . id ) . toBe ( '4' ) ;
2615
2612
} ) ;
2616
- } ) ;
2617
-
2618
- describe ( 'handleMethodData' , ( ) => {
2619
- it ( 'invokes helper' , async ( ) => {
2620
- const { controller } = setupController ( ) ;
2621
-
2622
- methodDataHelperMock . lookup . mockResolvedValueOnce ( METHOD_DATA_MOCK ) ;
2623
-
2624
- const result = await controller . handleMethodData (
2625
- 'mockMethodData' ,
2626
- NETWORK_CLIENT_ID_MOCK ,
2627
- ) ;
2628
-
2629
- expect ( result ) . toStrictEqual ( METHOD_DATA_MOCK ) ;
2630
- } ) ;
2631
2613
2632
2614
it ( 'updates state when helper emits update event' , async ( ) => {
2633
2615
const { controller } = setupController ( ) ;
@@ -4106,41 +4088,13 @@ describe('TransactionController', () => {
4106
4088
4107
4089
// TODO: Replace `any` with type
4108
4090
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4109
- await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( {
4110
- added : [ TRANSACTION_META_MOCK , TRANSACTION_META_2_MOCK ] ,
4111
- updated : [ ] ,
4112
- } ) ;
4113
-
4114
- expect ( controller . state . transactions ) . toStrictEqual ( [
4115
- { ...TRANSACTION_META_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4116
- { ...TRANSACTION_META_2_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4091
+ await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( [
4092
+ TRANSACTION_META_MOCK ,
4093
+ TRANSACTION_META_2_MOCK ,
4117
4094
] ) ;
4118
- } ) ;
4119
-
4120
- it ( 'updates existing transactions in state' , async ( ) => {
4121
- const { controller } = setupController ( {
4122
- options : {
4123
- state : {
4124
- transactions : [ TRANSACTION_META_MOCK , TRANSACTION_META_2_MOCK ] ,
4125
- } ,
4126
- } ,
4127
- } ) ;
4128
-
4129
- const updatedTransaction = {
4130
- ...TRANSACTION_META_MOCK ,
4131
- networkClientId : NETWORK_CLIENT_ID_MOCK ,
4132
- status : 'failed' ,
4133
- } ;
4134
-
4135
- // TODO: Replace `any` with type
4136
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4137
- await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( {
4138
- added : [ ] ,
4139
- updated : [ updatedTransaction ] ,
4140
- } ) ;
4141
4095
4142
4096
expect ( controller . state . transactions ) . toStrictEqual ( [
4143
- updatedTransaction ,
4097
+ { ... TRANSACTION_META_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4144
4098
{ ...TRANSACTION_META_2_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4145
4099
] ) ;
4146
4100
} ) ;
@@ -4152,58 +4106,74 @@ describe('TransactionController', () => {
4152
4106
4153
4107
// TODO: Replace `any` with type
4154
4108
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4155
- await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( {
4156
- added : [ TRANSACTION_META_MOCK , TRANSACTION_META_2_MOCK ] ,
4157
- updated : [ ] ,
4158
- } ) ;
4109
+ await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( [
4110
+ TRANSACTION_META_MOCK ,
4111
+ TRANSACTION_META_2_MOCK ,
4112
+ ] ) ;
4159
4113
4160
4114
expect ( controller . state . transactions ) . toStrictEqual ( [
4161
4115
{ ...TRANSACTION_META_2_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4162
4116
] ) ;
4163
4117
} ) ;
4164
- } ) ;
4165
4118
4166
- describe ( 'on incoming transaction helper lastFetchedBlockNumbers event' , ( ) => {
4167
- it ( 'updates state' , async ( ) => {
4168
- const { controller } = setupController ( ) ;
4119
+ it ( 'publishes TransactionController:incomingTransactionsReceived' , async ( ) => {
4120
+ const listener = jest . fn ( ) ;
4169
4121
4170
- const lastFetchedBlockNumbers = {
4171
- key : 234 ,
4172
- } ;
4122
+ const { messenger } = setupController ( ) ;
4123
+ messenger . subscribe (
4124
+ 'TransactionController:incomingTransactionsReceived' ,
4125
+ listener ,
4126
+ ) ;
4173
4127
4174
4128
// TODO: Replace `any` with type
4175
4129
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4176
- await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 1 ] [ 1 ] ( {
4177
- lastFetchedBlockNumbers ,
4178
- blockNumber : 123 ,
4179
- } ) ;
4130
+ await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( [
4131
+ TRANSACTION_META_MOCK ,
4132
+ TRANSACTION_META_2_MOCK ,
4133
+ ] ) ;
4180
4134
4181
- expect ( controller . state . lastFetchedBlockNumbers ) . toStrictEqual (
4182
- lastFetchedBlockNumbers ,
4183
- ) ;
4135
+ expect ( listener ) . toHaveBeenCalledTimes ( 1 ) ;
4136
+ expect ( listener ) . toHaveBeenCalledWith ( [
4137
+ { ...TRANSACTION_META_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4138
+ { ...TRANSACTION_META_2_MOCK , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
4139
+ ] ) ;
4184
4140
} ) ;
4185
4141
4186
- it ( 'publishes TransactionController:incomingTransactionBlockReceived' , async ( ) => {
4187
- const blockNumber = 123 ;
4142
+ it ( 'does not publish TransactionController:incomingTransactionsReceived if no new transactions' , async ( ) => {
4188
4143
const listener = jest . fn ( ) ;
4189
4144
4190
4145
const { messenger } = setupController ( ) ;
4146
+
4191
4147
messenger . subscribe (
4192
- 'TransactionController:incomingTransactionBlockReceived ' ,
4148
+ 'TransactionController:incomingTransactionsReceived ' ,
4193
4149
listener ,
4194
4150
) ;
4195
4151
4196
4152
// TODO: Replace `any` with type
4197
4153
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4198
- await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 1 ] [ 1 ] ( {
4199
- lastFetchedBlockNumbers : {
4200
- key : 234 ,
4154
+ await ( incomingTransactionHelperMock . hub . on as any ) . mock . calls [ 0 ] [ 1 ] ( [ ] ) ;
4155
+
4156
+ expect ( listener ) . toHaveBeenCalledTimes ( 0 ) ;
4157
+ } ) ;
4158
+ } ) ;
4159
+
4160
+ describe ( 'on incoming transaction helper updateCache call' , ( ) => {
4161
+ it ( 'updates state' , async ( ) => {
4162
+ const { controller } = setupController ( ) ;
4163
+ const key = 'testKey' ;
4164
+ const value = 123 ;
4165
+
4166
+ // TODO: Replace `any` with type
4167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4168
+ incomingTransactionHelperClassMock . mock . calls [ 0 ] [ 0 ] . updateCache (
4169
+ ( cache ) => {
4170
+ cache [ key ] = value ;
4201
4171
} ,
4202
- blockNumber,
4203
- } ) ;
4172
+ ) ;
4204
4173
4205
- expect ( listener ) . toHaveBeenCalledTimes ( 1 ) ;
4206
- expect ( listener ) . toHaveBeenCalledWith ( blockNumber ) ;
4174
+ expect ( controller . state . lastFetchedBlockNumbers ) . toStrictEqual ( {
4175
+ [ key ] : value ,
4176
+ } ) ;
4207
4177
} ) ;
4208
4178
} ) ;
4209
4179
0 commit comments