@@ -68,6 +68,7 @@ import type {
68
68
InternalAccount ,
69
69
PublishHook ,
70
70
GasFeeToken ,
71
+ SimulationData ,
71
72
} from './types' ;
72
73
import {
73
74
GasFeeEstimateType ,
@@ -78,6 +79,7 @@ import {
78
79
TransactionType ,
79
80
WalletDevice ,
80
81
} from './types' ;
82
+ import { getBalanceChanges } from './utils/balance-changes' ;
81
83
import { addTransactionBatch } from './utils/batch' ;
82
84
import { DELEGATION_PREFIX , getDelegationAddress } from './utils/eip7702' ;
83
85
import { addGasBuffer , estimateGas , updateGas } from './utils/gas' ;
@@ -87,8 +89,6 @@ import {
87
89
getTransactionLayer1GasFee ,
88
90
updateTransactionLayer1GasFee ,
89
91
} from './utils/layer1-gas-fee-flow' ;
90
- import type { GetSimulationDataResult } from './utils/simulation' ;
91
- import { getSimulationData } from './utils/simulation' ;
92
92
import {
93
93
updatePostTransactionBalance ,
94
94
updateSwapsTransaction ,
@@ -100,6 +100,7 @@ import {
100
100
buildCustomNetworkClientConfiguration ,
101
101
buildMockGetNetworkClientById ,
102
102
} from '../../network-controller/tests/helpers' ;
103
+ import { getGasFeeTokens } from './utils/gas-fee-tokens' ;
103
104
104
105
type UnrestrictedMessenger = Messenger <
105
106
TransactionControllerActions | AllowedActions ,
@@ -128,8 +129,9 @@ jest.mock('./utils/batch');
128
129
jest . mock ( './utils/gas' ) ;
129
130
jest . mock ( './utils/gas-fees' ) ;
130
131
jest . mock ( './utils/gas-flow' ) ;
132
+ jest . mock ( './utils/gas-fee-tokens' ) ;
131
133
jest . mock ( './utils/layer1-gas-fee-flow' ) ;
132
- jest . mock ( './utils/simulation ' ) ;
134
+ jest . mock ( './utils/balance-changes ' ) ;
133
135
jest . mock ( './utils/swaps' ) ;
134
136
jest . mock ( 'uuid' ) ;
135
137
@@ -453,27 +455,24 @@ const TRANSACTION_META_2_MOCK = {
453
455
} ,
454
456
} as TransactionMeta ;
455
457
456
- const SIMULATION_DATA_RESULT_MOCK : GetSimulationDataResult = {
457
- gasFeeTokens : [ ] ,
458
- simulationData : {
459
- nativeBalanceChange : {
460
- previousBalance : '0x0' ,
461
- newBalance : '0x1' ,
462
- difference : '0x1' ,
458
+ const SIMULATION_DATA_RESULT_MOCK : SimulationData = {
459
+ nativeBalanceChange : {
460
+ previousBalance : '0x0' ,
461
+ newBalance : '0x1' ,
462
+ difference : '0x1' ,
463
+ isDecrease : false ,
464
+ } ,
465
+ tokenBalanceChanges : [
466
+ {
467
+ address : '0x123' ,
468
+ standard : SimulationTokenStandard . erc721 ,
469
+ id : '0x456' ,
470
+ previousBalance : '0x1' ,
471
+ newBalance : '0x3' ,
472
+ difference : '0x2' ,
463
473
isDecrease : false ,
464
474
} ,
465
- tokenBalanceChanges : [
466
- {
467
- address : '0x123' ,
468
- standard : SimulationTokenStandard . erc721 ,
469
- id : '0x456' ,
470
- previousBalance : '0x1' ,
471
- newBalance : '0x3' ,
472
- difference : '0x2' ,
473
- isDecrease : false ,
474
- } ,
475
- ] ,
476
- } ,
475
+ ] ,
477
476
} ;
478
477
479
478
const GAS_FEE_TOKEN_MOCK : GasFeeToken = {
@@ -523,7 +522,8 @@ describe('TransactionController', () => {
523
522
) ;
524
523
const testGasFeeFlowClassMock = jest . mocked ( TestGasFeeFlow ) ;
525
524
const gasFeePollerClassMock = jest . mocked ( GasFeePoller ) ;
526
- const getSimulationDataMock = jest . mocked ( getSimulationData ) ;
525
+ const getBalanceChangesMock = jest . mocked ( getBalanceChanges ) ;
526
+ const getGasFeeTokensMock = jest . mocked ( getGasFeeTokens ) ;
527
527
const getTransactionLayer1GasFeeMock = jest . mocked (
528
528
getTransactionLayer1GasFee ,
529
529
) ;
@@ -2168,7 +2168,7 @@ describe('TransactionController', () => {
2168
2168
2169
2169
describe ( 'updates simulation data' , ( ) => {
2170
2170
it ( 'by default' , async ( ) => {
2171
- getSimulationDataMock . mockResolvedValueOnce (
2171
+ getBalanceChangesMock . mockResolvedValueOnce (
2172
2172
SIMULATION_DATA_RESULT_MOCK ,
2173
2173
) ;
2174
2174
@@ -2186,27 +2186,23 @@ describe('TransactionController', () => {
2186
2186
2187
2187
await flushPromises ( ) ;
2188
2188
2189
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 1 ) ;
2190
- expect ( getSimulationDataMock ) . toHaveBeenCalledWith (
2191
- {
2192
- chainId : MOCK_NETWORK . chainId ,
2193
- data : undefined ,
2194
- from : ACCOUNT_MOCK ,
2195
- to : ACCOUNT_MOCK ,
2196
- value : '0x0' ,
2197
- } ,
2198
- {
2199
- blockTime : undefined ,
2200
- } ,
2201
- ) ;
2189
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 1 ) ;
2190
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledWith ( {
2191
+ blockTime : undefined ,
2192
+ chainId : MOCK_NETWORK . chainId ,
2193
+ data : undefined ,
2194
+ from : ACCOUNT_MOCK ,
2195
+ to : ACCOUNT_MOCK ,
2196
+ value : '0x0' ,
2197
+ } ) ;
2202
2198
2203
2199
expect ( controller . state . transactions [ 0 ] . simulationData ) . toStrictEqual (
2204
- SIMULATION_DATA_RESULT_MOCK . simulationData ,
2200
+ SIMULATION_DATA_RESULT_MOCK ,
2205
2201
) ;
2206
2202
} ) ;
2207
2203
2208
2204
it ( 'with error if simulation disabled' , async ( ) => {
2209
- getSimulationDataMock . mockResolvedValueOnce (
2205
+ getBalanceChangesMock . mockResolvedValueOnce (
2210
2206
SIMULATION_DATA_RESULT_MOCK ,
2211
2207
) ;
2212
2208
@@ -2224,7 +2220,7 @@ describe('TransactionController', () => {
2224
2220
} ,
2225
2221
) ;
2226
2222
2227
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 0 ) ;
2223
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 0 ) ;
2228
2224
expect ( controller . state . transactions [ 0 ] . simulationData ) . toStrictEqual ( {
2229
2225
error : {
2230
2226
code : SimulationErrorCode . Disabled ,
@@ -2235,7 +2231,7 @@ describe('TransactionController', () => {
2235
2231
} ) ;
2236
2232
2237
2233
it ( 'unless approval not required' , async ( ) => {
2238
- getSimulationDataMock . mockResolvedValueOnce (
2234
+ getBalanceChangesMock . mockResolvedValueOnce (
2239
2235
SIMULATION_DATA_RESULT_MOCK ,
2240
2236
) ;
2241
2237
@@ -2249,12 +2245,12 @@ describe('TransactionController', () => {
2249
2245
{ requireApproval : false , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
2250
2246
) ;
2251
2247
2252
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 0 ) ;
2248
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 0 ) ;
2253
2249
expect ( controller . state . transactions [ 0 ] . simulationData ) . toBeUndefined ( ) ;
2254
2250
} ) ;
2255
2251
2256
2252
it ( 'with sender code if type 4' , async ( ) => {
2257
- getSimulationDataMock . mockResolvedValueOnce (
2253
+ getBalanceChangesMock . mockResolvedValueOnce (
2258
2254
SIMULATION_DATA_RESULT_MOCK ,
2259
2255
) ;
2260
2256
@@ -2277,20 +2273,17 @@ describe('TransactionController', () => {
2277
2273
2278
2274
await flushPromises ( ) ;
2279
2275
2280
- expect ( getSimulationDataMock ) . toHaveBeenCalledWith ( expect . any ( Object ) , {
2281
- senderCode : DELEGATION_PREFIX + ACCOUNT_2_MOCK . slice ( 2 ) ,
2282
- } ) ;
2276
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledWith (
2277
+ expect . objectContaining ( {
2278
+ senderCode : DELEGATION_PREFIX + ACCOUNT_2_MOCK . slice ( 2 ) ,
2279
+ } ) ,
2280
+ ) ;
2283
2281
} ) ;
2284
2282
} ) ;
2285
2283
2286
2284
describe ( 'updates gas fee tokens' , ( ) => {
2287
2285
it ( 'by default' , async ( ) => {
2288
- getSimulationDataMock . mockResolvedValueOnce ( {
2289
- gasFeeTokens : [ GAS_FEE_TOKEN_MOCK ] ,
2290
- simulationData : {
2291
- tokenBalanceChanges : [ ] ,
2292
- } ,
2293
- } ) ;
2286
+ getGasFeeTokensMock . mockResolvedValueOnce ( [ GAS_FEE_TOKEN_MOCK ] ) ;
2294
2287
2295
2288
const { controller } = setupController ( ) ;
2296
2289
@@ -2312,12 +2305,7 @@ describe('TransactionController', () => {
2312
2305
} ) ;
2313
2306
2314
2307
it ( 'unless approval not required' , async ( ) => {
2315
- getSimulationDataMock . mockResolvedValueOnce ( {
2316
- gasFeeTokens : [ GAS_FEE_TOKEN_MOCK ] ,
2317
- simulationData : {
2318
- tokenBalanceChanges : [ ] ,
2319
- } ,
2320
- } ) ;
2308
+ getGasFeeTokensMock . mockResolvedValueOnce ( [ GAS_FEE_TOKEN_MOCK ] ) ;
2321
2309
2322
2310
const { controller } = setupController ( ) ;
2323
2311
@@ -2329,7 +2317,7 @@ describe('TransactionController', () => {
2329
2317
{ requireApproval : false , networkClientId : NETWORK_CLIENT_ID_MOCK } ,
2330
2318
) ;
2331
2319
2332
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 0 ) ;
2320
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 0 ) ;
2333
2321
expect ( controller . state . transactions [ 0 ] . gasFeeTokens ) . toBeUndefined ( ) ;
2334
2322
} ) ;
2335
2323
} ) ;
@@ -6837,7 +6825,7 @@ describe('TransactionController', () => {
6837
6825
updateToInitialState : true ,
6838
6826
} ) ;
6839
6827
6840
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 0 ) ;
6828
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 0 ) ;
6841
6829
6842
6830
shouldResimulateMock . mockReturnValueOnce ( {
6843
6831
blockTime : 123 ,
@@ -6848,17 +6836,13 @@ describe('TransactionController', () => {
6848
6836
6849
6837
await flushPromises ( ) ;
6850
6838
6851
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 1 ) ;
6852
- expect ( getSimulationDataMock ) . toHaveBeenCalledWith (
6853
- {
6854
- from : ACCOUNT_MOCK ,
6855
- to : ACCOUNT_2_MOCK ,
6856
- value : TRANSACTION_META_MOCK . txParams . value ,
6857
- } ,
6858
- {
6859
- blockTime : 123 ,
6860
- } ,
6861
- ) ;
6839
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 1 ) ;
6840
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledWith ( {
6841
+ blockTime : 123 ,
6842
+ from : ACCOUNT_MOCK ,
6843
+ to : ACCOUNT_2_MOCK ,
6844
+ value : TRANSACTION_META_MOCK . txParams . value ,
6845
+ } ) ;
6862
6846
} ) ;
6863
6847
6864
6848
it ( 'does not trigger simulation loop' , async ( ) => {
@@ -6876,7 +6860,7 @@ describe('TransactionController', () => {
6876
6860
updateToInitialState : true ,
6877
6861
} ) ;
6878
6862
6879
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 0 ) ;
6863
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 0 ) ;
6880
6864
6881
6865
shouldResimulateMock . mockReturnValue ( {
6882
6866
blockTime : 123 ,
@@ -6887,17 +6871,13 @@ describe('TransactionController', () => {
6887
6871
6888
6872
await flushPromises ( ) ;
6889
6873
6890
- expect ( getSimulationDataMock ) . toHaveBeenCalledTimes ( 1 ) ;
6891
- expect ( getSimulationDataMock ) . toHaveBeenCalledWith (
6892
- {
6893
- from : ACCOUNT_MOCK ,
6894
- to : ACCOUNT_2_MOCK ,
6895
- value : TRANSACTION_META_MOCK . txParams . value ,
6896
- } ,
6897
- {
6898
- blockTime : 123 ,
6899
- } ,
6900
- ) ;
6874
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledTimes ( 1 ) ;
6875
+ expect ( getBalanceChangesMock ) . toHaveBeenCalledWith ( {
6876
+ blockTime : 123 ,
6877
+ from : ACCOUNT_MOCK ,
6878
+ to : ACCOUNT_2_MOCK ,
6879
+ value : TRANSACTION_META_MOCK . txParams . value ,
6880
+ } ) ;
6901
6881
} ) ;
6902
6882
} ) ;
6903
6883
0 commit comments