mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
614d4e40fe
* Update cometbft, cosmos, ethermint, and ibc-go * Replace github.com/tendermint/tendermint by github.com/cometbft/cometbft * Replace github.com/tendermint/tm-db by github.com/cometbft/cometbft-db * Replace gogo/protobuf with cosmos/gogoproto & simapp replacement * Replace cosmos-sdk/simapp/helpers with cosmos-sdk/testutil/sims * Remove no longer used simulations * Replace ibchost with ibcexported See https://github.com/cosmos/ibc-go/blob/v7.2.2/docs/migrations/v6-to-v7.md#ibc-module-constants * Add new consensus params keeper * Add consensus keeper to blockers * Fix keeper and module issues in app.go * Add IsSendEnabledCoins and update SetParams interface changes * Fix protobuf build for cosmos 47 (#1800) * fix cp errors by using -f; fix lint by only linting our proto dir; and use proofs.proto directly from ics23 for ibc-go v7 * run proto-all; commit updated third party deps and swagger changes * regenerate proto files * use correct gocosmos build plugin for buf * re-gen all protobuf files to update paths for new gocosmos plugin * update protoc and buf to latest versions * fix staking keeper issues in app.go * update tally handler for gov changes * chain id fix and flag fixes * update deps for cometbft 47.7 upgrade * remove all module legacy queriers * update stakingKeeper to pointer * Replace ModuleCdc from govv1beta1 to govcodec * remove simulations * abci.LastCommitInfo → abci.CommitInfo * Remove unused code in keys.go * simapp.MakeTestEncodingConfig -> moduletestutil.MakeTestEncodingConfi * Fix chain id issues in tests * Fix remaining unit test issues * Update changelog for upgrade * Fix e2e tests using updated kvtool * Update protonet to v47 compatible genesis * Bump cometbft-db to v0.9.1-kava.1 * Update kvtool * Remove extra changelog * Fix merged rocksdb issues * go mod cleanup * Bump cometbft-db to v9 and go to 1.21 * Bump rocksdb version to v8.10.0 * Update kvtool to latest version * Update gin to v1.9.0 * Use ibctm.ModuleName in app_test * Fallback to genesis chain id instead of client toml * Remove all simulations * Fix cdp migrations issue with v47 * Update dependencies to correct tags --------- Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
136 lines
4.4 KiB
Go
136 lines
4.4 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/auction/types"
|
|
)
|
|
|
|
func SetGetDeleteAuction(t *testing.T) {
|
|
// setup keeper, create auction
|
|
tApp := app.NewTestApp()
|
|
keeper := tApp.GetAuctionKeeper()
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1})
|
|
|
|
someTime := time.Date(43, time.January, 1, 0, 0, 0, 0, time.UTC) // need to specify UTC as tz info is lost on unmarshal
|
|
var id uint64 = 5
|
|
auction := types.NewSurplusAuction("some_module", c("usdx", 100), "kava", someTime).WithID(id)
|
|
|
|
// write and read from store
|
|
keeper.SetAuction(ctx, auction)
|
|
readAuction, found := keeper.GetAuction(ctx, id)
|
|
|
|
// check before and after match
|
|
require.True(t, found)
|
|
require.Equal(t, auction, readAuction)
|
|
// check auction is in the index
|
|
keeper.IterateAuctionsByTime(ctx, auction.GetEndTime(), func(readID uint64) bool {
|
|
require.Equal(t, auction.GetID(), readID)
|
|
return false
|
|
})
|
|
|
|
// delete auction
|
|
keeper.DeleteAuction(ctx, id)
|
|
|
|
// check auction does not exist
|
|
_, found = keeper.GetAuction(ctx, id)
|
|
require.False(t, found)
|
|
// check auction not in index
|
|
keeper.IterateAuctionsByTime(ctx, time.Unix(999999999, 0), func(readID uint64) bool {
|
|
require.Fail(t, "index should be empty", " found auction ID '%s", readID)
|
|
return false
|
|
})
|
|
}
|
|
|
|
func TestIncrementNextAuctionID(t *testing.T) {
|
|
// setup keeper
|
|
tApp := app.NewTestApp()
|
|
keeper := tApp.GetAuctionKeeper()
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1})
|
|
|
|
// store id
|
|
var id uint64 = 123456
|
|
keeper.SetNextAuctionID(ctx, id)
|
|
|
|
require.NoError(t, keeper.IncrementNextAuctionID(ctx))
|
|
|
|
// check id was incremented
|
|
readID, err := keeper.GetNextAuctionID(ctx)
|
|
require.NoError(t, err)
|
|
require.Equal(t, id+1, readID)
|
|
}
|
|
|
|
func TestIterateAuctions(t *testing.T) {
|
|
// setup
|
|
tApp := app.NewTestApp()
|
|
tApp.InitializeFromGenesisStates()
|
|
keeper := tApp.GetAuctionKeeper()
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1})
|
|
|
|
auctions := []types.Auction{
|
|
types.NewSurplusAuction("sellerMod", c("denom", 12345678), "anotherdenom", time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)).WithID(0),
|
|
types.NewDebtAuction("buyerMod", c("denom", 12345678), c("anotherdenom", 12345678), time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC), c("debt", 12345678)).WithID(1),
|
|
types.NewCollateralAuction("sellerMod", c("denom", 12345678), time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC), c("anotherdenom", 12345678), types.WeightedAddresses{}, c("debt", 12345678)).WithID(2),
|
|
}
|
|
for _, a := range auctions {
|
|
keeper.SetAuction(ctx, a)
|
|
}
|
|
|
|
// run
|
|
var readAuctions []types.Auction
|
|
keeper.IterateAuctions(ctx, func(a types.Auction) bool {
|
|
readAuctions = append(readAuctions, a)
|
|
return false
|
|
})
|
|
|
|
// check
|
|
require.Equal(t, auctions, readAuctions)
|
|
}
|
|
|
|
func TestIterateAuctionsByTime(t *testing.T) {
|
|
// setup keeper
|
|
tApp := app.NewTestApp()
|
|
keeper := tApp.GetAuctionKeeper()
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1})
|
|
|
|
// setup byTime index
|
|
byTimeIndex := []struct {
|
|
endTime time.Time
|
|
auctionID uint64
|
|
}{
|
|
{time.Date(0, time.January, 1, 0, 0, 0, 0, time.UTC), 9999}, // distant past
|
|
{time.Date(1998, time.January, 1, 11, 59, 59, 999999999, time.UTC), 1}, // just before cutoff
|
|
{time.Date(1998, time.January, 1, 11, 59, 59, 999999999, time.UTC), 2}, //
|
|
{time.Date(1998, time.January, 1, 12, 0, 0, 0, time.UTC), 3}, // equal to cutoff
|
|
{time.Date(1998, time.January, 1, 12, 0, 0, 0, time.UTC), 4}, //
|
|
{time.Date(1998, time.January, 1, 12, 0, 0, 1, time.UTC), 5}, // just after cutoff
|
|
{time.Date(1998, time.January, 1, 12, 0, 0, 1, time.UTC), 6}, //
|
|
{time.Date(9999, time.January, 1, 0, 0, 0, 0, time.UTC), 0}, // distant future
|
|
}
|
|
for _, v := range byTimeIndex {
|
|
keeper.InsertIntoByTimeIndex(ctx, v.endTime, v.auctionID)
|
|
}
|
|
|
|
// read out values from index up to a cutoff time and check they are as expected
|
|
cutoffTime := time.Date(1998, time.January, 1, 12, 0, 0, 0, time.UTC)
|
|
var expectedIndex []uint64
|
|
for _, v := range byTimeIndex {
|
|
if v.endTime.Before(cutoffTime) || v.endTime.Equal(cutoffTime) { // endTime ≤ cutoffTime
|
|
expectedIndex = append(expectedIndex, v.auctionID)
|
|
}
|
|
}
|
|
var readIndex []uint64
|
|
keeper.IterateAuctionsByTime(ctx, cutoffTime, func(id uint64) bool {
|
|
readIndex = append(readIndex, id)
|
|
return false
|
|
})
|
|
|
|
require.Equal(t, expectedIndex, readIndex)
|
|
}
|