diff --git a/x/airdrop/types/genesis.go b/x/airdrop/types/genesis.go index 532304440..03565f6ae 100644 --- a/x/airdrop/types/genesis.go +++ b/x/airdrop/types/genesis.go @@ -80,7 +80,7 @@ func (gs *GenesisState) Validate() error { return nil } -// GetGenesisStateFromAppState returns x/bank GenesisState given raw application +// GetGenesisStateFromAppState returns x/airdrop GenesisState given raw application // genesis state. func GetGenesisStateFromAppState(cdc codec.JSONCodec, appState map[string]json.RawMessage) *GenesisState { var genesisState GenesisState diff --git a/x/airdrop/types/genesis_test.go b/x/airdrop/types/genesis_test.go index 04548c1c5..e445833b9 100644 --- a/x/airdrop/types/genesis_test.go +++ b/x/airdrop/types/genesis_test.go @@ -16,6 +16,9 @@ func TestGenesisState_Validate(t *testing.T) { ZoneDrops []*types.ZoneDrop ClaimRecords []*types.ClaimRecord } + + defaultGenesis := types.DefaultGenesisState() + tests := []struct { name string fields fields @@ -26,6 +29,15 @@ func TestGenesisState_Validate(t *testing.T) { fields{}, false, }, + { + "default genesis", + fields{ + defaultGenesis.Params, + defaultGenesis.ZoneDrops, + defaultGenesis.ClaimRecords, + }, + false, + }, { "duplicate zone drop", fields{ diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index 7950ffca6..77c7ad289 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -3,6 +3,7 @@ package types_test import ( "testing" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" @@ -100,6 +101,78 @@ func TestMsgClaim_ValidateBasic(t *testing.T) { }, true, }, + { + "invalid proof no key", + fields{ + ChainID: "cosmoshub-4", + Action: int64(types.ActionInitialClaim), + Address: "cosmos1pgfzn0zhxjjgte7hprwtnqyhrn534lqk437x2w", + Proofs: []*cmtypes.Proof{ + { + Key: nil, + Data: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + ProofOps: &crypto.ProofOps{}, + Height: 10, + ProofType: "lockup", + }, + }, + }, + true, + }, + { + "invalid proof no data", + fields{ + ChainID: "cosmoshub-4", + Action: int64(types.ActionInitialClaim), + Address: "cosmos1pgfzn0zhxjjgte7hprwtnqyhrn534lqk437x2w", + Proofs: []*cmtypes.Proof{ + { + Key: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + Data: nil, + ProofOps: &crypto.ProofOps{}, + Height: 10, + ProofType: "lockup", + }, + }, + }, + true, + }, + { + "invalid proof no proof ops", + fields{ + ChainID: "cosmoshub-4", + Action: int64(types.ActionInitialClaim), + Address: "cosmos1pgfzn0zhxjjgte7hprwtnqyhrn534lqk437x2w", + Proofs: []*cmtypes.Proof{ + { + Key: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + Data: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + ProofOps: nil, + Height: 10, + ProofType: "lockup", + }, + }, + }, + true, + }, + { + "invalid proof no height", + fields{ + ChainID: "cosmoshub-4", + Action: int64(types.ActionInitialClaim), + Address: "cosmos1pgfzn0zhxjjgte7hprwtnqyhrn534lqk437x2w", + Proofs: []*cmtypes.Proof{ + { + Key: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + Data: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + ProofOps: &crypto.ProofOps{}, + Height: -1, + ProofType: "lockup", + }, + }, + }, + true, + }, { "valid", fields{ @@ -187,7 +260,7 @@ func TestMsgIncentivePoolSpendValidateBasic(t *testing.T) { true, }, { - "invalid amount", + "non positive amount", fields{ Authority: addr1, ToAddress: addr2, @@ -195,6 +268,18 @@ func TestMsgIncentivePoolSpendValidateBasic(t *testing.T) { }, true, }, + { + "invalid amount", + fields{ + Authority: addr1, + ToAddress: addr2, + Amount: sdk.Coins{sdk.Coin{ + Denom: "", + Amount: sdkmath.NewInt(1000), + }}, + }, + true, + }, { "valid", fields{ diff --git a/x/airdrop/types/zip_test.go b/x/airdrop/types/zip_test.go index ceb843163..d90273de6 100644 --- a/x/airdrop/types/zip_test.go +++ b/x/airdrop/types/zip_test.go @@ -1,3 +1,61 @@ package types_test +import ( + "bytes" + "compress/zlib" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ingenuity-build/quicksilver/x/airdrop/types" +) + // TODO test + +func TestDecompress(t *testing.T) { + testString := "hello, world\n" + var b bytes.Buffer + w := zlib.NewWriter(&b) + _, err := w.Write([]byte(testString)) + require.NoError(t, err) + require.NoError(t, w.Close()) + + tests := []struct { + name string + data []byte + expected []byte + wantErr bool + }{ + { + "no data", + nil, + nil, + true, + }, + { + "no data", + []byte{0, 0, 0}, + nil, + true, + }, + + { + "valid data", + b.Bytes(), + []byte(testString), + false, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + got, err := types.Decompress(tc.data) + if tc.wantErr { + require.Error(t, err) + return + } + require.NoError(t, err) + require.Equal(t, tc.expected, got) + }) + } +}