mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
add more tests
This commit is contained in:
parent
77bfe11f89
commit
4e7f18313a
@ -2,6 +2,7 @@ package keeper_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
@ -151,3 +152,90 @@ func TestForwardReverseAuctionBasic(t *testing.T) {
|
|||||||
// Check buyer's coins increased
|
// Check buyer's coins increased
|
||||||
tApp.CheckBalance(t, ctx, buyer, cs(c("token1", 115), c("token2", 50)))
|
tApp.CheckBalance(t, ctx, buyer, cs(c("token1", 115), c("token2", 50)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStartForwardAuction(t *testing.T) {
|
||||||
|
someTime := time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
type args struct {
|
||||||
|
seller string
|
||||||
|
lot sdk.Coin
|
||||||
|
bidDenom string
|
||||||
|
}
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
blockTime time.Time
|
||||||
|
args args
|
||||||
|
expectPass bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"normal",
|
||||||
|
someTime,
|
||||||
|
args{liquidator.ModuleName, c("stable", 10), "gov"},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"no module account",
|
||||||
|
someTime,
|
||||||
|
args{"nonExistentModule", c("stable", 10), "gov"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"not enough coins",
|
||||||
|
someTime,
|
||||||
|
args{liquidator.ModuleName, c("stable", 101), "gov"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"incorrect denom",
|
||||||
|
someTime,
|
||||||
|
args{liquidator.ModuleName, c("notacoin", 10), "gov"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
// setup
|
||||||
|
initialLiquidatorCoins := cs(c("stable", 100))
|
||||||
|
tApp := app.NewTestApp()
|
||||||
|
|
||||||
|
liqAcc := supply.NewEmptyModuleAccount(liquidator.ModuleName, supply.Burner) // TODO could add test to check for burner permissions
|
||||||
|
require.NoError(t, liqAcc.SetCoins(initialLiquidatorCoins))
|
||||||
|
tApp.InitializeFromGenesisStates(
|
||||||
|
NewAuthGenStateFromAccs(authexported.GenesisAccounts{liqAcc}),
|
||||||
|
)
|
||||||
|
ctx := tApp.NewContext(false, abci.Header{}).WithBlockTime(tc.blockTime)
|
||||||
|
keeper := tApp.GetAuctionKeeper()
|
||||||
|
|
||||||
|
// run function under test
|
||||||
|
id, err := keeper.StartForwardAuction(ctx, tc.args.seller, tc.args.lot, tc.args.bidDenom)
|
||||||
|
|
||||||
|
// check
|
||||||
|
sk := tApp.GetSupplyKeeper()
|
||||||
|
liquidatorCoins := sk.GetModuleAccount(ctx, liquidator.ModuleName).GetCoins()
|
||||||
|
actualAuc, found := keeper.GetAuction(ctx, id)
|
||||||
|
|
||||||
|
if tc.expectPass {
|
||||||
|
require.NoError(t, err)
|
||||||
|
// check coins moved
|
||||||
|
require.Equal(t, initialLiquidatorCoins.Sub(cs(tc.args.lot)), liquidatorCoins)
|
||||||
|
// check auction in store and is correct
|
||||||
|
require.True(t, found)
|
||||||
|
expectedAuction := types.Auction(types.ForwardAuction{BaseAuction: types.BaseAuction{
|
||||||
|
ID: types.ID(0),
|
||||||
|
Initiator: tc.args.seller,
|
||||||
|
Lot: tc.args.lot,
|
||||||
|
Bidder: nil,
|
||||||
|
Bid: c(tc.args.bidDenom, 0),
|
||||||
|
EndTime: tc.blockTime.Add(types.DefaultMaxAuctionDuration),
|
||||||
|
MaxEndTime: tc.blockTime.Add(types.DefaultMaxAuctionDuration),
|
||||||
|
}})
|
||||||
|
require.Equal(t, expectedAuction, actualAuc)
|
||||||
|
} else {
|
||||||
|
require.Error(t, err)
|
||||||
|
// check coins not moved
|
||||||
|
require.Equal(t, initialLiquidatorCoins, liquidatorCoins)
|
||||||
|
// check auction not in store
|
||||||
|
require.False(t, found)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user