From ae9d122e7944ea3fe135cb19276c4534a3a1d432 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 5 May 2023 08:48:09 -0400 Subject: [PATCH 1/4] basic test --- x/airdrop/types/genesis.go | 2 +- x/airdrop/types/genesis_test.go | 12 +++++++ x/airdrop/types/zip_test.go | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) 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/zip_test.go b/x/airdrop/types/zip_test.go index ceb843163..5d82df832 100644 --- a/x/airdrop/types/zip_test.go +++ b/x/airdrop/types/zip_test.go @@ -1,3 +1,62 @@ 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) + }) + } +} From 069b09d9c4fafbf7e1fa45bfc0687d82e2ca2b1a Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 5 May 2023 09:06:11 -0400 Subject: [PATCH 2/4] msg --- x/airdrop/types/msgs_test.go | 86 +++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index 7950ffca6..c265df808 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -1,6 +1,7 @@ package types_test import ( + sdkmath "cosmossdk.io/math" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -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,13 +260,24 @@ func TestMsgIncentivePoolSpendValidateBasic(t *testing.T) { true, }, { - "invalid amount", + "non positive amount", fields{ Authority: addr1, ToAddress: addr2, Amount: sdk.Coins{}, }, true, + }, { + "invalid amount", + fields{ + Authority: addr1, + ToAddress: addr2, + Amount: sdk.Coins{sdk.Coin{ + Denom: "", + Amount: sdkmath.NewInt(1000), + }}, + }, + true, }, { "valid", From 4a97bef6baeb57c40313f5c214e77a9c26553002 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 10 May 2023 13:22:50 -0400 Subject: [PATCH 3/4] fmt --- x/airdrop/types/msgs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index c265df808..f7184070e 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -1,9 +1,9 @@ package types_test import ( - sdkmath "cosmossdk.io/math" "testing" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" From fb9ff61ed73ca5ad623b15fe6cf92869c16e1e88 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 10 May 2023 13:37:29 -0400 Subject: [PATCH 4/4] fmt --- x/airdrop/types/msgs_test.go | 3 ++- x/airdrop/types/zip_test.go | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index f7184070e..77c7ad289 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -267,7 +267,8 @@ func TestMsgIncentivePoolSpendValidateBasic(t *testing.T) { Amount: sdk.Coins{}, }, true, - }, { + }, + { "invalid amount", fields{ Authority: addr1, diff --git a/x/airdrop/types/zip_test.go b/x/airdrop/types/zip_test.go index 5d82df832..d90273de6 100644 --- a/x/airdrop/types/zip_test.go +++ b/x/airdrop/types/zip_test.go @@ -3,7 +3,6 @@ package types_test import ( "bytes" "compress/zlib" - "testing" "github.com/stretchr/testify/require"