From 8e734eb7937e8148bc228b84848fc9aa498dbdbe Mon Sep 17 00:00:00 2001 From: samlior Date: Mon, 23 Mar 2026 14:52:27 +0800 Subject: [PATCH] chore: add test cases --- pkg/shreder/txparser_test.go | 165 +++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/pkg/shreder/txparser_test.go b/pkg/shreder/txparser_test.go index 6da89dd..07a1875 100644 --- a/pkg/shreder/txparser_test.go +++ b/pkg/shreder/txparser_test.go @@ -514,3 +514,168 @@ func TestParseRaydiumLaunchLabBuyExactIn(t *testing.T) { t.Fatalf("expected ExactSOL true, got false") } } + +func TestParseRaydiumLaunchLabBuyExactOut(t *testing.T) { + rpcUrl := os.Getenv("SOL_RPC_URL") + if rpcUrl == "" { + t.Fatalf("SOL_RPC_URL is not set") + } + + client := rpc.New(rpcUrl) + ch := make(chan TxSignal) + closed := make(chan struct{}) + go func() { + ParseTransactionForSubscribe( + context.Background(), + getTransaction(t, client, "4x2gArQAezap4RZKK5Tpfu1SNadCsTbjeUYG5KNggoHeGFiZdV1MmrrvXLXvyh2e6C1Gh22ohU4dFAzGw18y6VLT"), + nil, + ch, + closed, + ) + }() + go func() { + <-closed + close(ch) + }() + signals := make([]TxSignal, 0) + for signal := range ch { + signals = append(signals, signal) + } + + if len(signals) != 1 { + t.Fatalf("expected 1 signal, got %d", len(signals)) + } + + signal := signals[0] + if signal.Label != "raydiumlaunchlab" { + t.Fatalf("expected raydiumlaunchlab signal, got %s", signal.Label) + } + if signal.Event != "buy" { + t.Fatalf("expected buy event, got %s", signal.Event) + } + if signal.Maker != "nya666pQkP3PzWxi7JngU3rRMHuc7zbLK8c8wxQ4qpT" { + t.Fatalf("expected maker nya666pQkP3PzWxi7JngU3rRMHuc7zbLK8c8wxQ4qpT, got %s", signal.Maker) + } + if signal.Token0Address != "8ZTAvKJiPqExQYTYXoE2FuCoRFJAmyuEXXb4GbPvbonk" { + t.Fatalf("expected token0 address 8ZTAvKJiPqExQYTYXoE2FuCoRFJAmyuEXXb4GbPvbonk, got %s", signal.Token0Address) + } + if signal.Token0AmountUint64 != 2888057167672 { + t.Fatalf("expected token0 amount 2888057167672, got %d", signal.Token0AmountUint64) + } + if signal.Token1AmountUint64 != 159300000 { + t.Fatalf("expected token1 amount 159300000, got %d", signal.Token1AmountUint64) + } + if signal.ExactSOL { + t.Fatalf("expected ExactSOL false, got true") + } +} + +func TestParseRaydiumLaunchLabSellExactIn(t *testing.T) { + rpcUrl := os.Getenv("SOL_RPC_URL") + if rpcUrl == "" { + t.Fatalf("SOL_RPC_URL is not set") + } + + client := rpc.New(rpcUrl) + ch := make(chan TxSignal) + closed := make(chan struct{}) + go func() { + ParseTransactionForSubscribe( + context.Background(), + getTransaction(t, client, "37LGuUiTnBpagELdwVWtffkbJaLsucbRimnFueKS23EaFdYsjHC42SS3XjyC5tyRaokj5tdwiKYfBqNFAmMbTUgv"), + nil, + ch, + closed, + ) + }() + go func() { + <-closed + close(ch) + }() + signals := make([]TxSignal, 0) + for signal := range ch { + signals = append(signals, signal) + } + + if len(signals) != 1 { + t.Fatalf("expected 1 signal, got %d", len(signals)) + } + + signal := signals[0] + if signal.Label != "raydiumlaunchlab" { + t.Fatalf("expected raydiumlaunchlab signal, got %s", signal.Label) + } + if signal.Event != "sell" { + t.Fatalf("expected sell event, got %s", signal.Event) + } + if signal.Maker != "7GSDLZHBNnEgYwe8TLLy8iDbnKWaR5NfNVoxvQJ26nux" { + t.Fatalf("expected maker 7GSDLZHBNnEgYwe8TLLy8iDbnKWaR5NfNVoxvQJ26nux, got %s", signal.Maker) + } + if signal.Token0Address != "6bs2ECcL1XG5Tw8t3xvpyCsQDunQpdYtDXNyD74bonk" { + t.Fatalf("expected token0 address 6bs2ECcL1XG5Tw8t3xvpyCsQDunQpdYtDXNyD74bonk, got %s", signal.Token0Address) + } + if signal.Token0AmountUint64 != 3144872514758 { + t.Fatalf("expected token0 amount 3144872514758, got %d", signal.Token0AmountUint64) + } + if signal.Token1AmountUint64 != 373068521 { + t.Fatalf("expected token1 amount 373068521, got %d", signal.Token1AmountUint64) + } + if signal.ExactSOL { + t.Fatalf("expected ExactSOL false, got true") + } +} + +func TestParseRaydiumLaunchLabSellExactOut(t *testing.T) { + rpcUrl := os.Getenv("SOL_RPC_URL") + if rpcUrl == "" { + t.Fatalf("SOL_RPC_URL is not set") + } + + client := rpc.New(rpcUrl) + ch := make(chan TxSignal) + closed := make(chan struct{}) + go func() { + ParseTransactionForSubscribe( + context.Background(), + getTransaction(t, client, "3z8iC9zDLeQzjcLtUnwDT1j9Z5p5rFWXyCcRUhvUCVDTrPJSoZbbULkMTZk2mUUeAX1qaMBZUsPCd59B4KaGooSk"), + nil, + ch, + closed, + ) + }() + go func() { + <-closed + close(ch) + }() + signals := make([]TxSignal, 0) + for signal := range ch { + signals = append(signals, signal) + } + + if len(signals) != 1 { + t.Fatalf("expected 1 signal, got %d", len(signals)) + } + + signal := signals[0] + if signal.Label != "raydiumlaunchlab" { + t.Fatalf("expected raydiumlaunchlab signal, got %s", signal.Label) + } + if signal.Event != "sell" { + t.Fatalf("expected sell event, got %s", signal.Event) + } + if signal.Maker != "F4RMpjLMJZKmrYBxjpVadty7e326XUziLkYTDtNtpo2e" { + t.Fatalf("expected maker F4RMpjLMJZKmrYBxjpVadty7e326XUziLkYTDtNtpo2e, got %s", signal.Maker) + } + if signal.Token0Address != "ByubRkVymfNBoX9DUfUL39Zi6qzqWkTbLviQtx9ktxWv" { + t.Fatalf("expected token0 address ByubRkVymfNBoX9DUfUL39Zi6qzqWkTbLviQtx9ktxWv, got %s", signal.Token0Address) + } + if signal.Token0AmountUint64 != 594669717336 { + t.Fatalf("expected token0 amount 594669717336, got %d", signal.Token0AmountUint64) + } + if signal.Token1AmountUint64 != 141400000 { + t.Fatalf("expected token1 amount 141400000, got %d", signal.Token1AmountUint64) + } + if !signal.ExactSOL { + t.Fatalf("expected ExactSOL true, got false") + } +}