Skip to content

Commit

Permalink
test_: added tests for updating fees when after router provides the b…
Browse files Browse the repository at this point in the history
…est route
  • Loading branch information
saledjenic committed Sep 4, 2024
1 parent f655fa5 commit d52622f
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 192 deletions.
192 changes: 27 additions & 165 deletions api/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/typeddata"
"github.com/status-im/status-go/services/wallet"
walletservice "github.com/status-im/status-go/services/wallet"
"github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/sqlite"
"github.com/status-im/status-go/t/helpers"
Expand Down Expand Up @@ -90,51 +90,39 @@ func setupTestMultiDB() (*multiaccounts.Database, func() error, error) {
}, nil
}

func setupGethStatusBackend() (*GethStatusBackend, func() error, func() error, func() error, error) {
func setupGethStatusBackend(t *testing.T) (*GethStatusBackend, error) {
db, stop1, err := setupTestDB()
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}
backend := NewGethStatusBackend()
backend.StatusNode().SetAppDB(db)

ma, stop2, err := setupTestMultiDB()
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}
backend.StatusNode().SetMultiaccountsDB(ma)

walletDb, stop3, err := setupTestWalletDB()
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}
backend.StatusNode().SetWalletDB(walletDb)

return backend, stop1, stop2, stop3, err
t.Cleanup(func() {
require.NoError(t, stop1())
require.NoError(t, stop2())
require.NoError(t, stop3())
require.NoError(t, backend.StopNode())
})
return backend, err
}

func TestBackendStartNodeConcurrently(t *testing.T) {
utils.Init()

backend, stop1, stop2, stop3, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop3()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down Expand Up @@ -171,25 +159,7 @@ func TestBackendStartNodeConcurrently(t *testing.T) {
func TestBackendRestartNodeConcurrently(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down Expand Up @@ -219,25 +189,7 @@ func TestBackendRestartNodeConcurrently(t *testing.T) {
func TestBackendGettersConcurrently(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down Expand Up @@ -324,25 +276,7 @@ func TestBackendConnectionChangesToOffline(t *testing.T) {
func TestBackendCallRPCConcurrently(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down Expand Up @@ -420,25 +354,7 @@ func TestAppStateChange(t *testing.T) {
func TestBlockedRPCMethods(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down Expand Up @@ -480,25 +396,7 @@ func TestCallRPCWithStoppedNode(t *testing.T) {
func TestStartStopMultipleTimes(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand All @@ -519,25 +417,7 @@ func TestStartStopMultipleTimes(t *testing.T) {
func TestHashTypedData(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down Expand Up @@ -1031,25 +911,7 @@ func TestConvertAccount(t *testing.T) {

utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

backend.rootDataDir = rootDataDir
Expand Down Expand Up @@ -1412,7 +1274,7 @@ func TestCreateWallet(t *testing.T) {

walletService := statusNode.WalletService()
require.NotNil(t, walletService)
walletAPI := walletservice.NewAPI(walletService)
walletAPI := wallet.NewAPI(walletService)

paths := []string{"m/44'/60'/0'/0/1"}

Expand Down Expand Up @@ -1568,12 +1430,12 @@ func TestWalletConfigOnLoginAccount(t *testing.T) {
}

require.Equal(t, b.config.WalletConfig.InfuraAPIKey, infuraToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[mainnetChainID], alchemyEthereumMainnetToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[sepoliaChainID], alchemyEthereumSepoliaToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[arbitrumChainID], alchemyArbitrumMainnetToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[arbitrumSepoliaChainID], alchemyArbitrumSepoliaToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[optimismChainID], alchemyOptimismMainnetToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[optimismSepoliaChainID], alchemyOptimismSepoliaToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[common.EthereumMainnet], alchemyEthereumMainnetToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[common.EthereumSepolia], alchemyEthereumSepoliaToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[common.ArbitrumMainnet], alchemyArbitrumMainnetToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[common.ArbitrumSepolia], alchemyArbitrumSepoliaToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[common.OptimismMainnet], alchemyOptimismMainnetToken)
require.Equal(t, b.config.WalletConfig.AlchemyAPIKeys[common.OptimismSepolia], alchemyOptimismSepoliaToken)
require.Equal(t, b.config.WalletConfig.RaribleMainnetAPIKey, raribleMainnetAPIKey)
require.Equal(t, b.config.WalletConfig.RaribleTestnetAPIKey, raribleTestnetAPIKey)

Expand Down
20 changes: 1 addition & 19 deletions api/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,7 @@ import (
func TestHashMessage(t *testing.T) {
utils.Init()

backend, stop1, stop2, stopWallet, err := setupGethStatusBackend()
defer func() {
err := stop1()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stop2()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
defer func() {
err := stopWallet()
if err != nil {
require.NoError(t, backend.StopNode())
}
}()
backend, err := setupGethStatusBackend(t)
require.NoError(t, err)

config, err := utils.MakeTestNodeConfig(params.StatusChainNetworkID)
Expand Down
Loading

0 comments on commit d52622f

Please sign in to comment.