@@ -25,6 +25,7 @@ import {
2525 type TransactionParams ,
2626 TransactionStatus ,
2727} from '@metamask/transaction-controller' ;
28+ import type { Hex } from '@metamask/utils' ;
2829import nock from 'nock' ;
2930import * as sinon from 'sinon' ;
3031
@@ -41,7 +42,7 @@ import {
4142 getDefaultSmartTransactionsControllerState ,
4243 type SmartTransactionsControllerMessenger ,
4344} from './SmartTransactionsController' ;
44- import type { SmartTransaction , UnsignedTransaction , Hex } from './types' ;
45+ import type { SmartTransaction , UnsignedTransaction } from './types' ;
4546import { SmartTransactionStatuses , ClientId } from './types' ;
4647import * as utils from './utils' ;
4748
@@ -1148,6 +1149,55 @@ describe('SmartTransactionsController', () => {
11481149 } ) ;
11491150 } ) ;
11501151 } ) ;
1152+
1153+ it ( 'fetches liveness using chainId directly when provided' , async ( ) => {
1154+ await withController ( async ( { controller } ) => {
1155+ nock ( SENTINEL_API_BASE_URL_MAP [ sepoliaChainIdDec ] )
1156+ . get ( `/network` )
1157+ . reply ( 200 , createSuccessLivenessApiResponse ( ) ) ;
1158+
1159+ expect (
1160+ controller . state . smartTransactionsState . livenessByChainId ,
1161+ ) . toStrictEqual ( {
1162+ [ ChainId . mainnet ] : true ,
1163+ [ ChainId . sepolia ] : true ,
1164+ } ) ;
1165+
1166+ const liveness = await controller . fetchLiveness ( {
1167+ chainId : ChainId . sepolia ,
1168+ } ) ;
1169+
1170+ expect ( liveness ) . toBe ( true ) ;
1171+ expect (
1172+ controller . state . smartTransactionsState . livenessByChainId ,
1173+ ) . toStrictEqual ( {
1174+ [ ChainId . mainnet ] : true ,
1175+ [ ChainId . sepolia ] : true ,
1176+ } ) ;
1177+ } ) ;
1178+ } ) ;
1179+
1180+ it ( 'prioritizes chainId over networkClientId when both are provided' , async ( ) => {
1181+ await withController ( async ( { controller } ) => {
1182+ // Mock sepolia (the chainId we're passing directly)
1183+ nock ( SENTINEL_API_BASE_URL_MAP [ sepoliaChainIdDec ] )
1184+ . get ( `/network` )
1185+ . reply ( 200 , createSuccessLivenessApiResponse ( ) ) ;
1186+
1187+ const liveness = await controller . fetchLiveness ( {
1188+ chainId : ChainId . sepolia ,
1189+ networkClientId : NetworkType . mainnet , // This should be ignored
1190+ } ) ;
1191+
1192+ expect ( liveness ) . toBe ( true ) ;
1193+ // Verify it used sepolia (from chainId), not mainnet (from networkClientId)
1194+ expect (
1195+ controller . state . smartTransactionsState . livenessByChainId [
1196+ ChainId . sepolia
1197+ ] ,
1198+ ) . toBe ( true ) ;
1199+ } ) ;
1200+ } ) ;
11511201 } ) ;
11521202
11531203 describe ( 'updateSmartTransaction' , ( ) => {
0 commit comments