mirror of
https://github.com/status-im/status-go.git
synced 2025-02-22 03:38:27 +00:00
[wallet] fix UpsertRange
This commit is contained in:
parent
ddc93981a7
commit
fd49876a47
@ -772,7 +772,7 @@ func insertBlocksWithTransactions(creator statementCreator, account common.Addre
|
||||
|
||||
func (db *Database) UpsertRange(account common.Address, network uint64, from, to, balance *big.Int, nonce uint64) error {
|
||||
log.Debug("upsert blocks range", "account", account, "network id", network, "from", from, "to", to, "balance", balance, "nonce", nonce)
|
||||
insert, err := db.db.Prepare("INSERT INTO blocks_ranges (network_id, address, blk_from, blk_to, balance, nonce) VALUES (?, ?, ?, ?)")
|
||||
insert, err := db.db.Prepare("INSERT INTO blocks_ranges (network_id, address, blk_from, blk_to, balance, nonce) VALUES (?, ?, ?, ?, ?, ?)")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -425,3 +425,26 @@ func TestGetNewRanges(t *testing.T) {
|
||||
require.Equal(t, int64(50), newRange.to.Int64())
|
||||
require.Equal(t, 4, len(d))
|
||||
}
|
||||
|
||||
func TestUpsertRange(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
|
||||
r := &BlocksRange{
|
||||
from: big.NewInt(0),
|
||||
to: big.NewInt(10),
|
||||
}
|
||||
nonce := uint64(199)
|
||||
balance := big.NewInt(7657)
|
||||
account := common.Address{2}
|
||||
|
||||
err := db.UpsertRange(account, db.network, r.from, r.to, balance, nonce)
|
||||
require.NoError(t, err)
|
||||
|
||||
block, err := db.GetLastKnownBlockByAddress(account)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, 0, block.Number.Cmp(r.to))
|
||||
require.Equal(t, 0, block.Balance.Cmp(balance))
|
||||
require.Equal(t, nonce, uint64(*block.Nonce))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user