mirror of
https://github.com/colinear-labs/chain.git
synced 2026-03-05 04:34:26 -08:00
auction clear + test
This commit is contained in:
@@ -112,3 +112,13 @@ func (b *bidDB) GetHighestBid(auctionId string) (*types.Bid, error) {
|
||||
|
||||
return bid, err
|
||||
}
|
||||
|
||||
func (b *bidDB) ClearAuction(auctionId string) error {
|
||||
k := []byte(auctionId)
|
||||
|
||||
err := b.db.Update(func(txn *badger.Txn) error {
|
||||
return txn.Delete(k)
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package memdb
|
||||
import (
|
||||
"cosmos-test/x/cosmostest/types"
|
||||
"testing"
|
||||
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
)
|
||||
|
||||
func TestBasicFlow(t *testing.T) {
|
||||
@@ -14,12 +16,12 @@ func TestBasicFlow(t *testing.T) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// add a higher bid (won't check amount, though)
|
||||
|
||||
// add a higher bid (db funcs won't check amount, though)
|
||||
if err := BidDB.AddBid("0", &types.Bid{Owner: "cosmos456", Amount: "200"}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// check highest bid
|
||||
if bid, err := BidDB.GetHighestBid("0"); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
@@ -27,4 +29,19 @@ func TestBasicFlow(t *testing.T) {
|
||||
panic("Highest auction item not selected")
|
||||
}
|
||||
}
|
||||
|
||||
// clear auction under id 0
|
||||
if err := BidDB.ClearAuction("0"); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
// expect auction key to be unknown
|
||||
if err := BidDB.db.View(func(txn *badger.Txn) error {
|
||||
_, err := txn.Get([]byte("0"))
|
||||
return err
|
||||
}); err != nil {
|
||||
if err != badger.ErrKeyNotFound {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user