Browse Source

Fix historyDB GetBestBidCoordinator

feature/sql-semaphore1
laisolizq 3 years ago
parent
commit
bc29222341
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(
hdb.db, bidCoord,
`SELECT (
SELECT default_slot_set_bid_slot_num
SELECT default_slot_set_bid
FROM auction_vars
WHERE default_slot_set_bid_slot_num <= $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)
require.NoError(t, err)
err = historyDB.addBids(historyDB.db, []common.Bid{
bids := []common.Bid{
{
SlotNum: 10,
BidValue: big.NewInt(10),
@ -925,7 +926,9 @@ func TestGetBestBidCoordinator(t *testing.T) {
EthBlockNum: 2,
Bidder: coords[1].Bidder,
},
})
}
err = historyDB.addBids(historyDB.db, bids)
require.NoError(t, err)
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].Bidder, forger10.Bidder)
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)
require.Equal(t, sql.ErrNoRows, tracerr.Unwrap(err))

Loading…
Cancel
Save