fix_: token store clearing

This commit fixes issue with having a multiple contract addresses for the same symbols at the same networks.
An issue we had with this was that when we're searching for a token by symbol, always the first one from the
list was returned. That thing may result later in not having enough balance for that token on certain network,
even the user actually has it.
This commit is contained in:
Sale Djenic 2024-05-22 12:43:32 +02:00 committed by saledjenic
parent d31200e55b
commit dcef87af3f
2 changed files with 63 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package token
import (
"errors"
"fmt"
"math/big"
"sync"
"testing"
@ -383,3 +384,44 @@ func Test_removeTokenBalanceOnEventAccountRemoved(t *testing.T) {
server.Stop()
manager.stopAccountsWatcher()
}
func Test_tokensListsValidity(t *testing.T) {
appDB, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
require.NoError(t, err)
walletDB, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
require.NoError(t, err)
accountsDB, err := accounts.NewDB(appDB)
require.NoError(t, err)
nm := network.NewManager(appDB)
manager := NewTokenManager(walletDB, nil, nil, nm, appDB, nil, nil, nil, accountsDB)
require.NotNil(t, manager)
tokensListWrapper := manager.GetList()
require.NotNil(t, tokensListWrapper)
allLists := tokensListWrapper.Data
require.Greater(t, len(allLists), 0)
tmpMap := make(map[string][]*Token)
for _, list := range allLists {
for _, token := range list.Tokens {
key := fmt.Sprintf("%d-%s", token.ChainID, token.Symbol)
if added, ok := tmpMap[key]; ok {
found := false
for _, a := range added {
if a.Address == token.Address {
found = true
break
}
}
require.True(t, found)
} else {
tmpMap[key] = []*Token{token}
}
}
}
}

View File

@ -250,10 +250,10 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x4470bb87d77b963a013db939be332f927f2b992e"),
Name: "AdEx",
Address: common.HexToAddress("0xADE00C28244d5CE17D72E40330B1c318cD12B7c3"),
Name: "Ambire AdEx",
Symbol: "ADX",
Decimals: 4,
Decimals: 18,
ChainID: 1,
TokenListID: "status",
},
@ -346,8 +346,8 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x960b236a07cf122663c4303350609a66a7b288c0"),
Name: "Aragon Network Token",
Address: common.HexToAddress("0xa117000000f279D81A1D3cc75430fAA017FA5A2e"),
Name: "Aragon",
Symbol: "ANT",
Decimals: 18,
ChainID: 1,
@ -418,8 +418,8 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0xbeb9ef514a379b997e0798fdcc901ee474b6d9a1"),
Name: "Melon Token",
Address: common.HexToAddress("0xec67005c4E498Ec7f55E092bd1d35cbC47C91892"),
Name: "Melon",
Symbol: "MLN",
Decimals: 18,
ChainID: 1,
@ -674,16 +674,16 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x0d88ed6e74bbfd96b831231638b66c05571e824f"),
Name: "AVENTUS",
Address: common.HexToAddress("0x845576c64f9754CF09d87e45B720E82F3EeF522C"),
Name: "Artverse Token",
Symbol: "AVT",
Decimals: 18,
ChainID: 1,
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x6531f133e6deebe7f2dce5a0441aa7ef330b4e53"),
Name: "Chronobank TIME",
Address: common.HexToAddress("0x485d17A6f1B8780392d53D64751824253011A260"),
Name: "ChronoTech",
Symbol: "TIME",
Decimals: 8,
ChainID: 1,
@ -1274,8 +1274,8 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x5Af2Be193a6ABCa9c8817001F45744777Db30756"),
Name: "Voyager",
Address: common.HexToAddress("0x3C4B6E6e1eA3D4863700D7F76b36B7f3D3f13E3d"),
Name: "Voyager Token",
Symbol: "VGX",
Decimals: 8,
ChainID: 1,
@ -1555,8 +1555,8 @@ func newDefaultStore() *DefaultStore {
},
&Token{
Address: common.HexToAddress("0x7f5c764cbc14f9669b88837ca1490cca17c31607"),
Name: "USD Coin",
Symbol: "USDC",
Name: "USDCoin (Bridged from Ethereum)",
Symbol: "USDC.e",
Decimals: 6,
ChainID: 10,
TokenListID: "status",
@ -1586,9 +1586,9 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0xff970a61a04b1ca14834a43f5de4533ebddb5cc8"),
Name: "USD Coin",
Symbol: "USDC",
Address: common.HexToAddress("0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"),
Name: "Bridged USDC",
Symbol: "USDC.e",
Decimals: 6,
ChainID: 42161,
TokenListID: "status",
@ -1626,7 +1626,7 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x17fc002b466eec40dae837fc4be5c67993ddbd6f"),
Address: common.HexToAddress("0x7468a5d8E02245B00E8C0217fCE021C70Bc51305"),
Name: "Frax",
Symbol: "FRAX",
Decimals: 18,
@ -1642,8 +1642,8 @@ func newDefaultStore() *DefaultStore {
TokenListID: "status",
},
&Token{
Address: common.HexToAddress("0x23a941036ae778ac51ab04cea08ed6e2fe103614"),
Name: "Graph Token",
Address: common.HexToAddress("0x9623063377AD1B27544C965cCd7342f7EA7e88C7"),
Name: "The Graph",
Symbol: "GRT",
Decimals: 18,
ChainID: 42161,