Skip to content

Commit ef27bb7

Browse files
test: add swaps edge case where we end up with all positive balance changes
1 parent 9839778 commit ef27bb7

18 files changed

Lines changed: 830 additions & 5078 deletions

packages/snap/src/core/services/transactions/utils/mapRpcTransaction.test.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { EXPECTED_SEND_USDC_TRANSFER_TO_SELF_2_DATA } from '../../../test/mocks/
1212
import { EXPECTED_SPAM_TRANSACTION_DATA } from '../../../test/mocks/transactions-data/spam';
1313
import { EXPECTED_SPAM_TRANSACTION_DATA_2 } from '../../../test/mocks/transactions-data/spam-2';
1414
import { EXPECTED_SWAP_A16Z_USDT_SOL_DATA } from '../../../test/mocks/transactions-data/swap-a16z-usdt-sol';
15+
import { EXPECTED_SWAP_SOL_TO_OBRIC_DATA } from '../../../test/mocks/transactions-data/swap-sol-to-obric';
1516
import { EXPECTED_SWAP_SOL_TO_SAHUR_DATA } from '../../../test/mocks/transactions-data/swap-sol-to-sahur';
17+
import { EXPECTED_SWAP_SOL_TO_USDC_DATA } from '../../../test/mocks/transactions-data/swap-sol-to-usdc';
1618
import { EXPECTED_SWAP_TRUMP_TO_JUP_DATA } from '../../../test/mocks/transactions-data/swap-trump-to-jup';
1719
import { EXPECTED_SWAP_USDC_TO_COBIE_DATA } from '../../../test/mocks/transactions-data/swap-usdc-to-cobie';
1820
import { EXPECTED_SWAP_USDC_TO_JUP_DATA } from '../../../test/mocks/transactions-data/swap-usdc-to-jup';
@@ -939,6 +941,130 @@ describe('mapRpcTransaction', () => {
939941
});
940942
});
941943

944+
// TODO: An interesting edge case that our current mapping logic doesn't handle well
945+
// We end this transaction with more of all assets than we started with meaning
946+
// we think it's a receive transaction but it's not, it's actually a Swap.
947+
// https://solscan.io/tx/2m8z8uPZyoZwQpissDbhSfW5XDTFmpc7cSFithc5e1w8iCwFcvVkxHeaVhgFSdgUPb5cebbKGjuu48JMLPjfEATr
948+
it.skip('maps swaps - #6 SOL -> USDC', () => {
949+
const result = mapRpcTransaction({
950+
scope: Network.Mainnet,
951+
address: asAddress('3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c'),
952+
transactionData: EXPECTED_SWAP_SOL_TO_USDC_DATA,
953+
});
954+
955+
expect(result).toStrictEqual({
956+
id: '2X4vKsDS56avumw6jh6Z5wj28GNvK5UkMfY1Ta2Mtouic886EGAraa1gsCJ5rkXyHCeL9p2wHRty3QHAhjf352Dp',
957+
account: 'FQT9SSwEZ6UUQxsmTzgt5JzjrS4M5zm13M1QiYF8TEo6',
958+
timestamp: 1748539118,
959+
chain: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
960+
status: 'confirmed',
961+
type: 'swap',
962+
from: [
963+
{
964+
address: '3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c',
965+
asset: {
966+
fungible: true,
967+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
968+
unit: 'SOL',
969+
amount: '0.00099125',
970+
},
971+
},
972+
],
973+
to: [
974+
{
975+
address: '3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c',
976+
asset: {
977+
fungible: true,
978+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
979+
unit: '',
980+
amount: '0.167225',
981+
},
982+
},
983+
],
984+
fees: [
985+
{
986+
type: 'base',
987+
asset: {
988+
fungible: true,
989+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
990+
unit: 'SOL',
991+
amount: '0.000005',
992+
},
993+
},
994+
{
995+
type: 'priority',
996+
asset: {
997+
fungible: true,
998+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
999+
unit: 'SOL',
1000+
amount: '0.000010072',
1001+
},
1002+
},
1003+
],
1004+
events: [{ status: 'confirmed', timestamp: 1748539118 }],
1005+
});
1006+
});
1007+
1008+
it.skip('maps swaps - #7 SOL -> OBRIC', () => {
1009+
const result = mapRpcTransaction({
1010+
scope: Network.Mainnet,
1011+
address: asAddress('3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c'),
1012+
transactionData: EXPECTED_SWAP_SOL_TO_OBRIC_DATA,
1013+
});
1014+
1015+
expect(result).toStrictEqual({
1016+
id: '28rWme56aMyaP8oX18unFeZg65iyDEhjLhvMBpxyFgKcn38P37ZRsssSZoHDCCr5xUfwfpqsVSSBoShLitHQLdrr',
1017+
account: '3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c',
1018+
timestamp: 1748545222,
1019+
chain: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
1020+
status: 'confirmed',
1021+
type: 'swap',
1022+
from: [
1023+
{
1024+
address: '3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c',
1025+
asset: {
1026+
fungible: true,
1027+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
1028+
unit: 'SOL',
1029+
amount: '0.99125',
1030+
},
1031+
},
1032+
],
1033+
to: [
1034+
{
1035+
address: '3xTPAZxmpwd8GrNEKApaTw6VH4jqJ31WFXUvQzgwhR7c',
1036+
asset: {
1037+
fungible: true,
1038+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
1039+
unit: '',
1040+
amount: '0.005903984',
1041+
},
1042+
},
1043+
],
1044+
fees: [
1045+
{
1046+
type: 'base',
1047+
asset: {
1048+
fungible: true,
1049+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
1050+
unit: 'SOL',
1051+
amount: '0.000005',
1052+
},
1053+
},
1054+
{
1055+
type: 'priority',
1056+
asset: {
1057+
fungible: true,
1058+
type: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
1059+
unit: 'SOL',
1060+
amount: '0.00001212',
1061+
},
1062+
},
1063+
],
1064+
events: [{ status: 'confirmed', timestamp: 1748545222 }],
1065+
});
1066+
});
1067+
9421068
it('maps swaps - failure', () => {
9431069
const result = mapRpcTransaction({
9441070
scope: Network.Mainnet,

0 commit comments

Comments
 (0)