From c407dd1702ffc229b9b68a3e66ecc831f48b5383 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 13 Mar 2025 13:10:58 +0300 Subject: [PATCH] Added TestReadSwapPreviewData --- store/swap_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/store/swap_test.go b/store/swap_test.go index 46ec631..d2a92fc 100644 --- a/store/swap_test.go +++ b/store/swap_test.go @@ -13,7 +13,7 @@ func TestReadSwapData(t *testing.T) { ctx, store := InitializeTestDb(t) // Test swap data - transactionData := map[storedb.DataTyp]string{ + swapData := map[storedb.DataTyp]string{ storedb.DATA_PUBLIC_KEY: publicKey, storedb.DATA_ACTIVE_POOL_ADDRESS: "0x48a953cA5cf5298bc6f6Af3C608351f537AAcb9e", storedb.DATA_ACTIVE_SWAP_FROM_SYM: "AMANI", @@ -24,7 +24,7 @@ func TestReadSwapData(t *testing.T) { } // Store the data - for key, value := range transactionData { + for key, value := range swapData { if err := store.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil { t.Fatal(err) } @@ -45,3 +45,46 @@ func TestReadSwapData(t *testing.T) { assert.NoError(t, err) assert.Equal(t, expectedResult, data) } + +func TestReadSwapPreviewData(t *testing.T) { + sessionId := "session123" + publicKey := "0X13242618721" + ctx, store := InitializeTestDb(t) + + // Test swap preview data + swapPreviewData := map[storedb.DataTyp]string{ + storedb.DATA_PUBLIC_KEY: publicKey, + storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT: "1339482", + storedb.DATA_ACTIVE_SWAP_FROM_DECIMAL: "6", + storedb.DATA_ACTIVE_POOL_ADDRESS: "0x48a953cA5cf5298bc6f6Af3C608351f537AAcb9e", + storedb.DATA_ACTIVE_SWAP_FROM_ADDRESS: "0xc7B78Ac9ACB9E025C8234621FC515bC58179dEAe", + storedb.DATA_ACTIVE_SWAP_FROM_SYM: "AMANI", + storedb.DATA_ACTIVE_SWAP_TO_ADDRESS: "0x765DE816845861e75A25fCA122bb6898B8B1282a", + storedb.DATA_ACTIVE_SWAP_TO_SYM: "cUSD", + storedb.DATA_ACTIVE_SWAP_TO_DECIMAL: "18", + } + + // Store the data + for key, value := range swapPreviewData { + if err := store.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil { + t.Fatal(err) + } + } + + expectedResult := SwapPreviewData{ + PublicKey: "0X13242618721", + ActiveSwapMaxAmount: "1339482", + ActiveSwapFromDecimal: "6", + ActivePoolAddress: "0x48a953cA5cf5298bc6f6Af3C608351f537AAcb9e", + ActiveSwapFromAddress: "0xc7B78Ac9ACB9E025C8234621FC515bC58179dEAe", + ActiveSwapFromSym: "AMANI", + ActiveSwapToAddress: "0x765DE816845861e75A25fCA122bb6898B8B1282a", + ActiveSwapToSym: "cUSD", + ActiveSwapToDecimal: "18", + } + + data, err := ReadSwapPreviewData(ctx, store, sessionId) + + assert.NoError(t, err) + assert.Equal(t, expectedResult, data) +}