Skip to content

Commit

Permalink
test: intial GenesisState Validate test (fetchai#99)
Browse files Browse the repository at this point in the history
* test: intial GenesisState Validate test

* Fix: fix basic first tests

* Test: test Validate and NewGenesisState

* Fix: let AllowList be empty

* Tidy: goimports genesis_test.go

* Refactor: increase test coverage

* Refactor: remove unnecessary code and rename vars
  • Loading branch information
Josumner authored Jul 14, 2021
1 parent 73de69d commit 9b3f86e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x/airdrop/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (k Keeper) GetWhiteListClients(ctx sdk.Context) []string {
var res []string
k.paramSpace.Get(ctx, types.KeyWhiteList, &res)
k.paramSpace.GetIfExists(ctx, types.KeyWhiteList, &res)
return res
}

Expand Down
63 changes: 63 additions & 0 deletions x/airdrop/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package types_test

import (
"testing"

"github.com/cosmos/cosmos-sdk/x/airdrop/types"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
addr = sdk.AccAddress([]byte("addr________________"))
invalidAddr = sdk.AccAddress([]byte("\n\n\n\n\taddr________________\t\n\n\n\n\n"))
)

func TestNewGenesisState(t *testing.T) {
p := types.NewParams()
expectedFunds := []types.ActiveFund{
{
Sender: addr.String(),
Fund: &types.Fund{
Amount: &sdk.Coin{Denom: "test", Amount: sdk.NewInt(10)},
DripAmount: sdk.NewInt(1),
},
},
}
expectedState := &types.GenesisState{
Params: p,
Funds: expectedFunds,
}
require.Equal(t, expectedState.GetFunds(), expectedFunds)
require.Equal(t, expectedState.Params, p)
}

func TestValidateGenesisState(t *testing.T) {
p1 := types.Params{
AllowList: []string{
addr.String(), // valid address
},
}
p2 := types.Params{
AllowList: []string{
invalidAddr.String(), // invalid address
},
}
funds := []types.ActiveFund{
{
Sender: addr.String(),
Fund: &types.Fund{
Amount: &sdk.Coin{
Denom: "test",
Amount: sdk.NewInt(10),
},
DripAmount: sdk.NewInt(1),
},
},
}
gen1 := types.NewGenesisState(p1, funds)
gen2 := types.NewGenesisState(p2, funds)
require.NoError(t, gen1.Validate())
require.Error(t, gen2.Validate())
}

0 comments on commit 9b3f86e

Please sign in to comment.