Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: x/airdrop types #421

Merged
merged 7 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/airdrop/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions x/airdrop/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down
87 changes: 86 additions & 1 deletion x/airdrop/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -187,14 +260,26 @@ 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",
fields{
Expand Down
58 changes: 58 additions & 0 deletions x/airdrop/types/zip_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}