Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed May 7, 2024
1 parent dba344f commit d611e4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
37 changes: 32 additions & 5 deletions x/auction/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package keeper

import (
"math/rand"
"testing"
"time"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/umee-network/umee/v6/tests/accs"
"github.com/umee-network/umee/v6/x/auction"
)

Expand All @@ -13,12 +18,34 @@ func TestGenesis(t *testing.T) {
require := require.New(t)
k := initKeeper(t)

check := func(gs *auction.GenesisState) {
err := k.InitGenesis(gs)
require.NoError(err)

gsOut, err := k.ExportGenesis()
require.NoError(err)
require.Equal(gs, gsOut)
}

gs := auction.DefaultGenesis()
err := k.InitGenesis(gs)
require.NoError(err)
check(gs)

gsOut, err := k.ExportGenesis()
require.NoError(err)
require.Equal(gs, gsOut)
newCoin := func(a int64) []sdk.Coin {
return sdk.Coins{sdk.NewInt64Coin("atom", a)}
}
randTime := func() time.Time {
return time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC).Add(time.Duration(rand.Int()) * time.Nanosecond)
}

gs.RewardAuctionId = 3
gs.RewardsAuctions = []auction.RewardsKV{
{1, auction.Rewards{newCoin(412313), randTime()}},
{2, auction.Rewards{newCoin(412313), randTime()}},
{4, auction.Rewards{newCoin(412313), randTime()}},
}
gs.RewardsBids = []auction.BidKV{
{1, auction.Bid{accs.Alice, sdkmath.NewInt(153252)}},
{2, auction.Bid{accs.Alice, sdkmath.NewInt(8521)}},
}
check(gs)
}
4 changes: 3 additions & 1 deletion x/auction/keeper/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/umee-network/umee/v6/tests/accs"
"github.com/umee-network/umee/v6/tests/tsdk"
"github.com/umee-network/umee/v6/x/auction"
ugovmocks "github.com/umee-network/umee/v6/x/ugov/mocks"
)

// creates keeper without external dependencies (app, leverage etc...)
Expand All @@ -18,7 +19,8 @@ func initKeeper(t *testing.T) TestKeeper {
subaccs := SubAccounts{
RewardsCollect: accs.GenerateAddr("x/auction/rewards"),
}
kb := NewBuilder(cdc, storeKey, subaccs, nil, nil)
eg := ugovmocks.NewSimpleEmergencyGroupBuilder()
kb := NewBuilder(cdc, storeKey, subaccs, nil, eg)
ctx, _ := tsdk.NewCtxOneStore(t, storeKey)

return TestKeeper{kb.Keeper(&ctx), t, &ctx}
Expand Down

0 comments on commit d611e4a

Please sign in to comment.