Skip to content

Commit

Permalink
test: draft of keeper/genesis tests to discuss (#102)
Browse files Browse the repository at this point in the history
* test: draft of keeper/genesis tests to discuss

* refactor: combine mutually inclusive init/export genesis tests
  • Loading branch information
Josumner authored Jul 16, 2021
1 parent 4967618 commit 8f3d9dd
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions x/airdrop/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package keeper_test

import (
"testing"
"time"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/airdrop/types"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

var (
addr = sdk.AccAddress([]byte("addr________________"))
)

type GenesisTestSuite struct {
suite.Suite

app *simapp.SimApp
ctx sdk.Context
}

func (s *GenesisTestSuite) SetupTest() {
app := simapp.Setup(false)
s.app = app
s.ctx = app.BaseApp.NewContext(false, tmproto.Header{
Time: time.Now(),
Height: 10,
})

s.app.AirdropKeeper.SetParams(s.ctx, types.NewParams(addr.String()))
}

func (s *GenesisTestSuite) TestInitAndExportGenesis() {
p := types.Params{
AllowList: []string{
addr.String(),
},
}
funds := []types.ActiveFund{
{
Sender: addr.String(),
Fund: &types.Fund{
Amount: &sdk.Coin{
Denom: "test",
Amount: sdk.NewInt(10),
},
DripAmount: sdk.NewInt(1),
},
},
}
genState := types.NewGenesisState(p, funds)
s.app.AirdropKeeper.InitGenesis(s.ctx, genState)
actualFunds, _ := s.app.AirdropKeeper.GetActiveFunds(s.ctx)
s.Require().Equal(s.app.AirdropKeeper.GetParams(s.ctx), p)
s.Require().Equal(funds, actualFunds)
s.Require().Equal(s.app.AirdropKeeper.ExportGenesis(s.ctx), genState)
}

func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
}

0 comments on commit 8f3d9dd

Please sign in to comment.