From cf2c53c831457af89204fb96fe6d9d43cb06646c Mon Sep 17 00:00:00 2001 From: Dario Gabriel Lipicar Date: Wed, 9 Oct 2024 18:38:35 -0300 Subject: [PATCH] fix_: bugfixes --- rpc/chain/ethclient/cached_eth_client.go | 12 +++++++++--- rpc/chain/ethclient/db.go | 6 +++++- services/wallet/transfer/commands_sequential_test.go | 4 ++-- tests-functional/tests/test_eth_api.py | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/rpc/chain/ethclient/cached_eth_client.go b/rpc/chain/ethclient/cached_eth_client.go index a5b6e279b..43a891b7c 100644 --- a/rpc/chain/ethclient/cached_eth_client.go +++ b/rpc/chain/ethclient/cached_eth_client.go @@ -95,12 +95,18 @@ func (c *CachedEthClient) getOrFetchBlockByHash(ctx context.Context, hash common func (c *CachedEthClient) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { block, err := c.getOrFetchBlockByHash(ctx, hash, false) - return block.header, err + if err != nil { + return nil, err + } + return block.header, nil } func (c *CachedEthClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { block, err := c.getOrFetchBlockByNumber(ctx, number, false) - return block.header, err + if err != nil { + return nil, err + } + return block.header, nil } func (c *CachedEthClient) getOrFetchUncles(ctx context.Context, blockHash common.Hash, uncleHashes []common.Hash) ([]*types.Header, error) { @@ -283,7 +289,7 @@ func (c *CachedEthClient) callGetBalance(ctx context.Context, account common.Add return nil, err } - return result.ToInt(), nil + return (*big.Int)(result), nil } func (c *CachedEthClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { diff --git a/rpc/chain/ethclient/db.go b/rpc/chain/ethclient/db.go index 077576235..56f665730 100644 --- a/rpc/chain/ethclient/db.go +++ b/rpc/chain/ethclient/db.go @@ -50,6 +50,10 @@ func NewDB(db *sql.DB) *DB { } func (b *DB) GetBlockJSONByNumber(chainID uint64, blockNumber *big.Int, withTransactionDetails bool) (json.RawMessage, error) { + if !isConcreteBlockNumber(blockNumber) { + return nil, sql.ErrNoRows + } + q := sq.Select("block_json"). From("blockchain_data_blocks"). Where(sq.Eq{"chain_id": chainID, "block_number": (*bigint.SQLBigInt)(blockNumber), "with_transaction_details": withTransactionDetails}) @@ -328,7 +332,7 @@ func putBlockJSON(creator sqlite.StatementCreator, chainID uint64, blkJSON json. return err } - if rpcBlock.Number == nil { + if !isConcreteBlockNumber((*big.Int)(rpcBlock.Number)) { // Pending block, don't store return nil } diff --git a/services/wallet/transfer/commands_sequential_test.go b/services/wallet/transfer/commands_sequential_test.go index f868ff6c1..ccfafae26 100644 --- a/services/wallet/transfer/commands_sequential_test.go +++ b/services/wallet/transfer/commands_sequential_test.go @@ -28,7 +28,6 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rpc" - "github.com/status-im/status-go/contracts" "github.com/status-im/status-go/contracts/balancechecker" "github.com/status-im/status-go/contracts/ethscan" "github.com/status-im/status-go/contracts/ierc20" @@ -1578,7 +1577,8 @@ func TestFetchNewBlocksCommand_nonceDetection(t *testing.T) { Client: nil, UpstreamChainID: 1, Networks: []params.Network{}, - DB: db, + AppDB: appDB, + WalletDB: walletDB, WalletFeed: nil, ProviderConfigs: nil, } diff --git a/tests-functional/tests/test_eth_api.py b/tests-functional/tests/test_eth_api.py index bea367ca4..21eb70f73 100644 --- a/tests-functional/tests/test_eth_api.py +++ b/tests-functional/tests/test_eth_api.py @@ -1,6 +1,6 @@ import pytest -from conftest import user_1 +from constants import user_1 from test_cases import EthRpcTestCase