Browse Source

Merge pull request #387 from hermeznetwork/feature/fix-get-best-bid-coord

Fix historyDB GetBestBidCoordinator
feature/sql-semaphore1
Eduard S 3 years ago
committed by GitHub
parent
commit
92e34fb683
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions
  1. +1
    -1
      db/historydb/historydb.go
  2. +10
    -2
      db/historydb/historydb_test.go

+ 1
- 1
db/historydb/historydb.go

@ -377,7 +377,7 @@ func (hdb *HistoryDB) GetBestBidCoordinator(slotNum int64) (*common.BidCoordinat
err := meddler.QueryRow( err := meddler.QueryRow(
hdb.db, bidCoord, hdb.db, bidCoord,
`SELECT ( `SELECT (
SELECT default_slot_set_bid_slot_num
SELECT default_slot_set_bid
FROM auction_vars FROM auction_vars
WHERE default_slot_set_bid_slot_num <= $1 WHERE default_slot_set_bid_slot_num <= $1
ORDER BY eth_block_num DESC LIMIT 1 ORDER BY eth_block_num DESC LIMIT 1

+ 10
- 2
db/historydb/historydb_test.go

@ -912,7 +912,8 @@ func TestGetBestBidCoordinator(t *testing.T) {
} }
err = historyDB.addCoordinators(historyDB.db, coords) err = historyDB.addCoordinators(historyDB.db, coords)
require.NoError(t, err) require.NoError(t, err)
err = historyDB.addBids(historyDB.db, []common.Bid{
bids := []common.Bid{
{ {
SlotNum: 10, SlotNum: 10,
BidValue: big.NewInt(10), BidValue: big.NewInt(10),
@ -925,7 +926,9 @@ func TestGetBestBidCoordinator(t *testing.T) {
EthBlockNum: 2, EthBlockNum: 2,
Bidder: coords[1].Bidder, Bidder: coords[1].Bidder,
}, },
})
}
err = historyDB.addBids(historyDB.db, bids)
require.NoError(t, err) require.NoError(t, err)
forger10, err := historyDB.GetBestBidCoordinator(10) forger10, err := historyDB.GetBestBidCoordinator(10)
@ -933,6 +936,11 @@ func TestGetBestBidCoordinator(t *testing.T) {
require.Equal(t, coords[1].Forger, forger10.Forger) require.Equal(t, coords[1].Forger, forger10.Forger)
require.Equal(t, coords[1].Bidder, forger10.Bidder) require.Equal(t, coords[1].Bidder, forger10.Bidder)
require.Equal(t, coords[1].URL, forger10.URL) require.Equal(t, coords[1].URL, forger10.URL)
require.Equal(t, bids[1].SlotNum, forger10.SlotNum)
require.Equal(t, bids[1].BidValue, forger10.BidValue)
for i := range forger10.DefaultSlotSetBid {
require.Equal(t, auction.DefaultSlotSetBid[i], forger10.DefaultSlotSetBid[i])
}
_, err = historyDB.GetBestBidCoordinator(11) _, err = historyDB.GetBestBidCoordinator(11)
require.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err)) require.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err))

Loading…
Cancel
Save