[wallet] fix UpsertRange

This commit is contained in:
Roman Volosovskyi 2021-04-20 09:53:32 +03:00
parent ddc93981a7
commit fd49876a47
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 25 additions and 2 deletions

View File

@ -1 +1 @@
0.76.4
0.76.5

View File

@ -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
}

View File

@ -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))
}