Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erokhinav committed Oct 9, 2024
1 parent 051d668 commit 8f00ddc
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/bath/bath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/tonkeeper/opentonapi/internal/g"
"os"
"sort"
"testing"

"github.com/stretchr/testify/require"
"github.com/tonkeeper/opentonapi/internal/g"
"github.com/tonkeeper/opentonapi/pkg/core"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/liteapi"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (m *mockInfoSource) JettonMastersForWallets(ctx context.Context, wallets []
return m.OnJettonMastersForWallets(ctx, wallets)
}

func (m *mockInfoSource) STONfiPools(ctx context.Context, pools []tongo.AccountID) (map[tongo.AccountID]core.STONfiPool, error) {
func (m *mockInfoSource) STONfiPools(ctx context.Context, pools []core.STONfiPoolID) (map[tongo.AccountID]core.STONfiPool, error) {
return map[tongo.AccountID]core.STONfiPool{}, nil
}

Expand Down Expand Up @@ -166,6 +166,16 @@ func TestFindActions(t *testing.T) {
tongo.MustParseBlockID("(0,8000000000000000,33600829)"),
// failed dedust swap
tongo.MustParseBlockID("(0,7000000000000000,45592983)"),
// stonfi v2 swap simple
tongo.MustParseBlockID("(0,6000000000000000,46034062)"),
tongo.MustParseBlockID("(0,e000000000000000,46027828)"),
tongo.MustParseBlockID("(0,9000000000000000,45998794)"),
tongo.MustParseBlockID("(0,6000000000000000,46034070)"),
tongo.MustParseBlockID("(0,6000000000000000,46034067)"),
// stonfi v2 swap with ref
tongo.MustParseBlockID("(0,2000000000000000,46145069)"),
tongo.MustParseBlockID("(0,6000000000000000,46151880)"),
tongo.MustParseBlockID("(0,2000000000000000,46145074)"),
}),
)

Expand Down Expand Up @@ -411,6 +421,16 @@ func TestFindActions(t *testing.T) {
hash: "887c7763f41ca4a4b9de28900ab514caabc0c27ed5b41d9918d60f5e7f4a9d96",
filenamePrefix: "failed-dedust-swap",
},
{
name: "stonfi v2 swap simple",
hash: "3fa256638e5f6cd356afa70eb37c89de80846973dea0c9c46adf4df5cca39a68",
filenamePrefix: "stonfi-v2-swap-simple",
},
{
name: "stonfi v2 swap with ref",
hash: "d70fddb4786c04932669bf589ee73c16293115a1927dfbee5b719304232e2e1b",
filenamePrefix: "stonfi-v2-swap-ref",
},
} {
t.Run(c.name, func(t *testing.T) {
trace, err := storage.GetTrace(context.Background(), tongo.MustParseHash(c.hash))
Expand Down
131 changes: 131 additions & 0 deletions pkg/bath/testdata/stonfi-v2-swap-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"Actions": [
{
"JettonSwap": {
"Dex": "stonfi",
"UserWallet": "0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80",
"Router": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46",
"In": {
"Amount": 793509017,
"IsTon": true,
"JettonMaster": "0:671963027f7f85659ab55b821671688601cdcf1ee674fc7fbbb1a776a18d34a3",
"JettonWallet": "0:433b0d3c9cb130afd4d35f25c388fb81a201d933fd51938d8ab3c87e15090fdf"
},
"Out": {
"Amount": 4165614,
"IsTon": false,
"JettonMaster": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe",
"JettonWallet": "0:40a0fe4e243dc71295bb6ea73491a3a020594c814ce2937219fd1a6fb308a4b5"
}
},
"Success": true,
"Type": "JettonSwap",
"BaseTransactions": [
"d5f3ba7bdec7c81c39f6944208ad4059990dea6279830b6add7e078789f0fa88",
"135f4d0e0ae8522e90d53f9df8704e10d5c52fcdc59c3b3d0f29d58c4d18c4c8",
"6a264b138e5aa033fa4da2434d10aa18ce1029c82e2bb364c37ee78142890f9a",
"2e29dd132181ab545786cf46b7a11f0a1ce6181e83d38cd7e3e4e286663a539e",
"44fb8b15c09564851dfa7518c0a0151e840fce72d25139afbfc720b1ad0302bd",
"f12140b774c67599c6c8f67880d05c9d4177df5af7ad5275a450be926e9c0993",
"3cb721a7b14724d8acc5fa82e0a735da50cf54bba25e32b4d0f2c142c782ce1e"
]
},
{
"SmartContractExec": {
"TonAttached": 36574051,
"Executor": "0:4e7714a51a18f18d5615c22e9b947c5f4b5b56b0e5deb0cac0d67a67ba259e38",
"Contract": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46",
"Operation": "StonfiPayVaultV2",
"Payload": "AdditionalInfo:\n Amount0Out: \"4174\"\n Amount1Out: \"0\"\n Token0Address: 0:40a0fe4e243dc71295bb6ea73491a3a020594c814ce2937219fd1a6fb308a4b5\n Token1Address: 0:433b0d3c9cb130afd4d35f25c388fb81a201d933fd51938d8ab3c87e15090fdf\nExcessesAddress: 0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80\nOwner: 0:b089166b7d44a530cd1dcfe1e6e0a5b522a685cf53f0c60dfeb748d00eddfaa8\nQueryId: 24196457155416\n"
},
"Success": true,
"Type": "SmartContractExec",
"BaseTransactions": [
"e7a1470824486dad13292d6f8dd495f1a041c5a5ca04e4e746af79b95df96f2e"
]
},
{
"SmartContractExec": {
"TonAttached": 29176851,
"Executor": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46",
"Contract": "0:65eb5db66adc1d34c70e482fa0f41f079a5da255479af2b378d1e7fb219db831",
"Operation": "StonfiDepositRefFeeV2",
"Payload": "ExcessesAddress: 0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80\nJettonAmount: \"4174\"\nQueryId: 24196457155416\n"
},
"Success": true,
"Type": "SmartContractExec",
"BaseTransactions": [
"be717a41e4e2c7870fe0c9104c4789766b382a62ab95dc403012e98609ed48d2"
]
},
{
"TonTransfer": {
"Amount": 26388041,
"Comment": null,
"EncryptedComment": null,
"Recipient": "0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80",
"Sender": "0:65eb5db66adc1d34c70e482fa0f41f079a5da255479af2b378d1e7fb219db831",
"Refund": null
},
"Success": true,
"Type": "TonTransfer",
"BaseTransactions": [
"066e82c2a58b9dacea02d83e6017f002bcd6818f2609e54c3bc319ddd5959a0b"
]
}
],
"Accounts": [
{
"Account": "0:1c764efbd8cbe157c5e67d4787d9401dffba81496934bd7a78cc52e65fcdde80",
"Ton": -840494007,
"Fee": 4830408,
"Jettons": [
{
"Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe",
"Quantity": 4165614
}
]
},
{
"Account": "0:40a0fe4e243dc71295bb6ea73491a3a020594c814ce2937219fd1a6fb308a4b5",
"Ton": -2,
"Fee": 1549602,
"Jettons": null
},
{
"Account": "0:429752403644e932927d37795992d3cca69d9bb517b6bd5c07a27d256bc89b46",
"Ton": 0,
"Fee": 22854803,
"Jettons": [
{
"Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe",
"Quantity": -4165614
}
]
},
{
"Account": "0:433b0d3c9cb130afd4d35f25c388fb81a201d933fd51938d8ab3c87e15090fdf",
"Ton": 793509017,
"Fee": 4381202,
"Jettons": null
},
{
"Account": "0:4e7714a51a18f18d5615c22e9b947c5f4b5b56b0e5deb0cac0d67a67ba259e38",
"Ton": 0,
"Fee": 9723203,
"Jettons": null
},
{
"Account": "0:506e1af93741d3a8147ba27ed2bb43e48734e9b1dd56d5a8b5991919138c7dfe",
"Ton": 1170,
"Fee": 855794,
"Jettons": null
},
{
"Account": "0:65eb5db66adc1d34c70e482fa0f41f079a5da255479af2b378d1e7fb219db831",
"Ton": 0,
"Fee": 2788810,
"Jettons": null
}
]
}
98 changes: 98 additions & 0 deletions pkg/bath/testdata/stonfi-v2-swap-simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"Actions": [
{
"JettonSwap": {
"Dex": "stonfi",
"UserWallet": "0:68524f62c0ca74e5b7ce11031816b183ce213486cb216049393634164de821fe",
"Router": "0:f0ca38239d35c954f8d78e2dce3ed52295c0a371e19540e2c6c2bf7fb112e322",
"In": {
"Amount": 29592300,
"IsTon": false,
"JettonMaster": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe",
"JettonWallet": "0:f2bd9f9d79482377ef150ad15aa88dfc2505e771beb2dd89308c6fe02765ce5c"
},
"Out": {
"Amount": 7809813506,
"IsTon": false,
"JettonMaster": "0:3690254dc15b2297610cda60744a45f2b710aa4234b89adb630e99d79b01bd4f",
"JettonWallet": "0:9ffcc843698c05629b3f8c7791fd2c3a601107364064f9be6cfde58c35d0bf0f"
}
},
"Success": true,
"Type": "JettonSwap",
"BaseTransactions": [
"fc3171638353c317415a3e467ae33ecf01cd0262af5d92527737032f40f95c8e",
"3888fe02c074f4380ec4512b9881d595d7acd8963597f4958017c3dc183d9d79",
"7ccd855d615fb16f5ae1b3b7fc7d7a0fc0080b44c46f3e6c5014bcd6cb01d562",
"5066094bc706f67cf71ccabfc42306bdb6a99ed82771a6ab5da237998d2f99fb",
"650488391db16d8c62103f8a35079fb549935e5200a2aa31969d6fb42cf55648",
"f818a26e94fe3e9333e7e64419be5f45a37698d1044a0a4795a4d2bd0cc52f12",
"881e913f8bb411991ef4db9c54b74b629bd4ec12915dd9a8a8da77f7729b87e3",
"8bee1d42e4ea2fa15afacf2604161a725a5a4120049140bc8543d119f892f8bb",
"91a8f3f529a050adc7823c76c2eb2819041c44ab843aec0595bb8ef078d4c2b6"
]
}
],
"Accounts": [
{
"Account": "0:51aa642c8acb57e3e2976bd5b30a1beb62da3913429eb87b31503c1eeedb12ec",
"Ton": -8,
"Fee": 2140008,
"Jettons": null
},
{
"Account": "0:5aa3722ccb24812e0ab1831f106f51d0fa2600b49947a4364150a9584850e08c",
"Ton": 11825309,
"Fee": 3574691,
"Jettons": null
},
{
"Account": "0:68524f62c0ca74e5b7ce11031816b183ce213486cb216049393634164de821fe",
"Ton": -54844851,
"Fee": 4914441,
"Jettons": [
{
"Address": "0:3690254dc15b2297610cda60744a45f2b710aa4234b89adb630e99d79b01bd4f",
"Quantity": 7809813506
},
{
"Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe",
"Quantity": -29592300
}
]
},
{
"Account": "0:9ffcc843698c05629b3f8c7791fd2c3a601107364064f9be6cfde58c35d0bf0f",
"Ton": -20,
"Fee": 7669220,
"Jettons": null
},
{
"Account": "0:f0ca38239d35c954f8d78e2dce3ed52295c0a371e19540e2c6c2bf7fb112e322",
"Ton": 0,
"Fee": 15364406,
"Jettons": [
{
"Address": "0:3690254dc15b2297610cda60744a45f2b710aa4234b89adb630e99d79b01bd4f",
"Quantity": -7809813506
},
{
"Address": "0:b113a994b5024a16719f69139328eb759596c38a25f59028b146fecdc3621dfe",
"Quantity": 29592300
}
]
},
{
"Account": "0:f2bd9f9d79482377ef150ad15aa88dfc2505e771beb2dd89308c6fe02765ce5c",
"Ton": 0,
"Fee": 1974403,
"Jettons": null
},
{
"Account": "0:fd104b6df84fc43ab7044e9d804c6d8252fc03586ff54b32cb3fbd85e9ad74d4",
"Ton": 0,
"Fee": 7382401,
"Jettons": null
}
]
}

0 comments on commit 8f00ddc

Please sign in to comment.