59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package token
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/status-im/status-go/appdatabase"
|
|
"github.com/status-im/status-go/sqlite"
|
|
)
|
|
|
|
func setupTestTokenDB(t *testing.T) (*Manager, func()) {
|
|
tmpfile, err := ioutil.TempFile("", "wallet-token-tests-")
|
|
require.NoError(t, err)
|
|
db, err := appdatabase.InitializeDB(tmpfile.Name(), "wallet-token-tests", sqlite.ReducedKDFIterationsNumber)
|
|
require.NoError(t, err)
|
|
return &Manager{db, nil, nil}, func() {
|
|
require.NoError(t, db.Close())
|
|
require.NoError(t, os.Remove(tmpfile.Name()))
|
|
}
|
|
}
|
|
|
|
func TestCustoms(t *testing.T) {
|
|
manager, stop := setupTestTokenDB(t)
|
|
defer stop()
|
|
|
|
rst, err := manager.GetCustoms()
|
|
require.NoError(t, err)
|
|
require.Nil(t, rst)
|
|
|
|
token := Token{
|
|
Address: common.Address{1},
|
|
Name: "Zilliqa",
|
|
Symbol: "ZIL",
|
|
Decimals: 12,
|
|
Color: "#fa6565",
|
|
ChainID: 777,
|
|
}
|
|
|
|
err = manager.UpsertCustom(token)
|
|
require.NoError(t, err)
|
|
|
|
rst, err = manager.GetCustoms()
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, len(rst))
|
|
require.Equal(t, token, *rst[0])
|
|
|
|
err = manager.DeleteCustom(777, token.Address)
|
|
require.NoError(t, err)
|
|
|
|
rst, err = manager.GetCustoms()
|
|
require.NoError(t, err)
|
|
require.Equal(t, 0, len(rst))
|
|
}
|