From 8f3d9dd2180532363bdaaa8501ebe192859f5abf Mon Sep 17 00:00:00 2001 From: Joe <85871158+Josumner@users.noreply.github.com> Date: Fri, 16 Jul 2021 10:49:35 +0100 Subject: [PATCH] test: draft of keeper/genesis tests to discuss (#102) * test: draft of keeper/genesis tests to discuss * refactor: combine mutually inclusive init/export genesis tests --- x/airdrop/keeper/genesis_test.go | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 x/airdrop/keeper/genesis_test.go diff --git a/x/airdrop/keeper/genesis_test.go b/x/airdrop/keeper/genesis_test.go new file mode 100644 index 000000000000..8c9ea791f0eb --- /dev/null +++ b/x/airdrop/keeper/genesis_test.go @@ -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)) +}