@@ -17,7 +17,6 @@ import {
1717 type NetworkState ,
1818} from '@metamask/network-controller' ;
1919import type {
20- TransactionControllerConfirmExternalTransactionAction ,
2120 TransactionControllerGetNonceLockAction ,
2221 TransactionControllerGetTransactionsAction ,
2322 TransactionControllerUpdateTransactionAction ,
@@ -1225,301 +1224,6 @@ describe('SmartTransactionsController', () => {
12251224 ) ;
12261225 } ) ;
12271226
1228- it ( 'confirms a smart transaction that has status success' , async ( ) => {
1229- const { smartTransactionsState } =
1230- getDefaultSmartTransactionsControllerState ( ) ;
1231- const pendingStx = {
1232- ...createStateAfterPending ( ) [ 0 ] ,
1233- history : testHistory ,
1234- } ;
1235- const confirmExternalTransactionSpy = jest . fn ( ) ;
1236- const getRegularTransactionsSpy = jest . fn ( ) . mockImplementation ( ( ) => {
1237- return [ createTransactionMeta ( ) ] ;
1238- } ) ;
1239- await withController (
1240- {
1241- options : {
1242- state : {
1243- smartTransactionsState : {
1244- ...smartTransactionsState ,
1245- smartTransactions : {
1246- [ ChainId . mainnet ] : [ pendingStx ] as SmartTransaction [ ] ,
1247- } ,
1248- } ,
1249- } ,
1250- } ,
1251- confirmExternalTransaction : confirmExternalTransactionSpy ,
1252- getTransactions : getRegularTransactionsSpy ,
1253- } ,
1254- async ( { controller } ) => {
1255- const updateTransaction = {
1256- ...pendingStx ,
1257- statusMetadata : {
1258- ...pendingStx . statusMetadata ,
1259- minedHash : txHash ,
1260- } ,
1261- status : SmartTransactionStatuses . SUCCESS ,
1262- } ;
1263-
1264- controller . updateSmartTransaction (
1265- updateTransaction as SmartTransaction ,
1266- {
1267- networkClientId : NetworkType . mainnet ,
1268- } ,
1269- ) ;
1270- await flushPromises ( ) ;
1271-
1272- expect ( confirmExternalTransactionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1273- expect (
1274- controller . state . smartTransactionsState . smartTransactions [
1275- ChainId . mainnet
1276- ] ,
1277- ) . toStrictEqual ( [
1278- {
1279- ...updateTransaction ,
1280- confirmed : true ,
1281- } ,
1282- ] ) ;
1283- } ,
1284- ) ;
1285- } ) ;
1286-
1287- it ( 'confirms a smart transaction that was not found in the list of regular transactions' , async ( ) => {
1288- const { smartTransactionsState } =
1289- getDefaultSmartTransactionsControllerState ( ) ;
1290- const pendingStx = {
1291- ...createStateAfterPending ( ) [ 0 ] ,
1292- history : testHistory ,
1293- } ;
1294- const confirmExternalTransactionSpy = jest . fn ( ) ;
1295- const getRegularTransactionsSpy = jest . fn ( ) . mockImplementation ( ( ) => {
1296- return [ ] ;
1297- } ) ;
1298- await withController (
1299- {
1300- options : {
1301- state : {
1302- smartTransactionsState : {
1303- ...smartTransactionsState ,
1304- smartTransactions : {
1305- [ ChainId . mainnet ] : [ pendingStx ] as SmartTransaction [ ] ,
1306- } ,
1307- } ,
1308- } ,
1309- } ,
1310- confirmExternalTransaction : confirmExternalTransactionSpy ,
1311- getTransactions : getRegularTransactionsSpy ,
1312- } ,
1313- async ( { controller } ) => {
1314- const updateTransaction = {
1315- ...pendingStx ,
1316- statusMetadata : {
1317- ...pendingStx . statusMetadata ,
1318- minedHash : txHash ,
1319- } ,
1320- status : SmartTransactionStatuses . SUCCESS ,
1321- } ;
1322-
1323- controller . updateSmartTransaction (
1324- updateTransaction as SmartTransaction ,
1325- {
1326- networkClientId : NetworkType . mainnet ,
1327- } ,
1328- ) ;
1329- await flushPromises ( ) ;
1330-
1331- expect ( confirmExternalTransactionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1332- expect (
1333- controller . state . smartTransactionsState . smartTransactions [
1334- ChainId . mainnet
1335- ] ,
1336- ) . toStrictEqual ( [
1337- {
1338- ...updateTransaction ,
1339- confirmed : true ,
1340- } ,
1341- ] ) ;
1342- } ,
1343- ) ;
1344- } ) ;
1345-
1346- it ( 'confirms a smart transaction that does not have a minedHash' , async ( ) => {
1347- const { smartTransactionsState } =
1348- getDefaultSmartTransactionsControllerState ( ) ;
1349- const pendingStx = {
1350- ...createStateAfterPending ( ) [ 0 ] ,
1351- history : testHistory ,
1352- } ;
1353- const confirmExternalTransactionSpy = jest . fn ( ) ;
1354- const getRegularTransactionsSpy = jest . fn ( ) . mockImplementation ( ( ) => {
1355- return [ createTransactionMeta ( TransactionStatus . confirmed ) ] ;
1356- } ) ;
1357- await withController (
1358- {
1359- options : {
1360- state : {
1361- smartTransactionsState : {
1362- ...smartTransactionsState ,
1363- smartTransactions : {
1364- [ ChainId . mainnet ] : [ pendingStx ] as SmartTransaction [ ] ,
1365- } ,
1366- } ,
1367- } ,
1368- } ,
1369- confirmExternalTransaction : confirmExternalTransactionSpy ,
1370- getTransactions : getRegularTransactionsSpy ,
1371- } ,
1372- async ( { controller } ) => {
1373- const updateTransaction = {
1374- ...pendingStx ,
1375- statusMetadata : {
1376- ...pendingStx . statusMetadata ,
1377- minedHash : '' ,
1378- } ,
1379- status : SmartTransactionStatuses . SUCCESS ,
1380- } ;
1381-
1382- controller . updateSmartTransaction (
1383- updateTransaction as SmartTransaction ,
1384- {
1385- networkClientId : NetworkType . mainnet ,
1386- } ,
1387- ) ;
1388- await flushPromises ( ) ;
1389-
1390- expect ( confirmExternalTransactionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1391- expect (
1392- controller . state . smartTransactionsState . smartTransactions [
1393- ChainId . mainnet
1394- ] ,
1395- ) . toStrictEqual ( [
1396- {
1397- ...updateTransaction ,
1398- confirmed : true ,
1399- } ,
1400- ] ) ;
1401- } ,
1402- ) ;
1403- } ) ;
1404-
1405- it ( 'does not call the "confirmExternalTransaction" fn if a tx is already confirmed' , async ( ) => {
1406- const { smartTransactionsState } =
1407- getDefaultSmartTransactionsControllerState ( ) ;
1408- const pendingStx = {
1409- ...createStateAfterPending ( ) [ 0 ] ,
1410- history : testHistory ,
1411- } ;
1412- const confirmExternalTransactionSpy = jest . fn ( ) ;
1413- const getRegularTransactionsSpy = jest . fn ( ) . mockImplementation ( ( ) => {
1414- return [ createTransactionMeta ( TransactionStatus . confirmed ) ] ;
1415- } ) ;
1416- await withController (
1417- {
1418- options : {
1419- state : {
1420- smartTransactionsState : {
1421- ...smartTransactionsState ,
1422- smartTransactions : {
1423- [ ChainId . mainnet ] : [ pendingStx ] as SmartTransaction [ ] ,
1424- } ,
1425- } ,
1426- } ,
1427- } ,
1428- confirmExternalTransaction : confirmExternalTransactionSpy ,
1429- getTransactions : getRegularTransactionsSpy ,
1430- } ,
1431- async ( { controller } ) => {
1432- const updateTransaction = {
1433- ...pendingStx ,
1434- status : SmartTransactionStatuses . SUCCESS ,
1435- statusMetadata : {
1436- ...pendingStx . statusMetadata ,
1437- minedHash : txHash ,
1438- } ,
1439- } ;
1440-
1441- controller . updateSmartTransaction (
1442- updateTransaction as SmartTransaction ,
1443- {
1444- networkClientId : NetworkType . mainnet ,
1445- } ,
1446- ) ;
1447- await flushPromises ( ) ;
1448-
1449- expect ( confirmExternalTransactionSpy ) . not . toHaveBeenCalled ( ) ;
1450- expect (
1451- controller . state . smartTransactionsState . smartTransactions [
1452- ChainId . mainnet
1453- ] ,
1454- ) . toStrictEqual ( [
1455- {
1456- ...updateTransaction ,
1457- confirmed : true ,
1458- } ,
1459- ] ) ;
1460- } ,
1461- ) ;
1462- } ) ;
1463-
1464- it ( 'does not call the "confirmExternalTransaction" fn if a tx is already submitted' , async ( ) => {
1465- const { smartTransactionsState } =
1466- getDefaultSmartTransactionsControllerState ( ) ;
1467- const pendingStx = {
1468- ...createStateAfterPending ( ) [ 0 ] ,
1469- history : testHistory ,
1470- } ;
1471- const confirmExternalTransactionSpy = jest . fn ( ) ;
1472- const getRegularTransactionsSpy = jest . fn ( ) . mockImplementation ( ( ) => {
1473- return [ createTransactionMeta ( TransactionStatus . submitted ) ] ;
1474- } ) ;
1475- await withController (
1476- {
1477- options : {
1478- state : {
1479- smartTransactionsState : {
1480- ...smartTransactionsState ,
1481- smartTransactions : {
1482- [ ChainId . mainnet ] : [ pendingStx ] as SmartTransaction [ ] ,
1483- } ,
1484- } ,
1485- } ,
1486- } ,
1487- confirmExternalTransaction : confirmExternalTransactionSpy ,
1488- getTransactions : getRegularTransactionsSpy ,
1489- } ,
1490- async ( { controller } ) => {
1491- const updateTransaction = {
1492- ...pendingStx ,
1493- status : SmartTransactionStatuses . SUCCESS ,
1494- statusMetadata : {
1495- ...pendingStx . statusMetadata ,
1496- minedHash : txHash ,
1497- } ,
1498- } ;
1499-
1500- controller . updateSmartTransaction (
1501- updateTransaction as SmartTransaction ,
1502- {
1503- networkClientId : NetworkType . mainnet ,
1504- } ,
1505- ) ;
1506- await flushPromises ( ) ;
1507-
1508- expect ( confirmExternalTransactionSpy ) . not . toHaveBeenCalled ( ) ;
1509- expect (
1510- controller . state . smartTransactionsState . smartTransactions [
1511- ChainId . mainnet
1512- ] ,
1513- ) . toStrictEqual ( [
1514- {
1515- ...updateTransaction ,
1516- confirmed : true ,
1517- } ,
1518- ] ) ;
1519- } ,
1520- ) ;
1521- } ) ;
1522-
15231227 it ( 'calls updateTransaction when smart transaction is cancelled and returnTxHashAsap is true' , async ( ) => {
15241228 const mockUpdateTransaction = jest . fn ( ) ;
15251229 const defaultState = getDefaultSmartTransactionsControllerState ( ) ;
@@ -2691,7 +2395,6 @@ type WithControllerOptions = {
26912395 ConstructorParameters < typeof SmartTransactionsController > [ 0 ]
26922396 > ;
26932397 getNonceLock ?: TransactionControllerGetNonceLockAction [ 'handler' ] ;
2694- confirmExternalTransaction ?: TransactionControllerConfirmExternalTransactionAction [ 'handler' ] ;
26952398 getTransactions ?: TransactionControllerGetTransactionsAction [ 'handler' ] ;
26962399 updateTransaction ?: TransactionControllerUpdateTransactionAction [ 'handler' ] ;
26972400} ;
@@ -2719,7 +2422,6 @@ async function withController<ReturnValue>(
27192422 nextNonce : 42 ,
27202423 releaseLock : jest . fn ( ) ,
27212424 } ) ,
2722- confirmExternalTransaction = jest . fn ( ) ,
27232425 getTransactions = jest . fn ( ) ,
27242426 updateTransaction = jest . fn ( ) ,
27252427 } = rest ;
@@ -2792,10 +2494,6 @@ async function withController<ReturnValue>(
27922494 'TransactionController:getNonceLock' ,
27932495 getNonceLock ,
27942496 ) ;
2795- rootMessenger . registerActionHandler (
2796- 'TransactionController:confirmExternalTransaction' ,
2797- confirmExternalTransaction ,
2798- ) ;
27992497 rootMessenger . registerActionHandler (
28002498 'TransactionController:getTransactions' ,
28012499 getTransactions ,
@@ -2820,7 +2518,6 @@ async function withController<ReturnValue>(
28202518 'NetworkController:getNetworkClientById' ,
28212519 'NetworkController:getState' ,
28222520 'TransactionController:getNonceLock' ,
2823- 'TransactionController:confirmExternalTransaction' ,
28242521 'TransactionController:getTransactions' ,
28252522 'TransactionController:updateTransaction' ,
28262523 ] ,
0 commit comments