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

x/bank: balance and metadata validation #8417

Merged
merged 7 commits into from
Jan 23, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
genesis test
  • Loading branch information
fedekunze committed Jan 22, 2021
commit 7bba8ccb89ea44b4611a4ee443ccbcae6814e343
151 changes: 151 additions & 0 deletions x/bank/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package types

import (
"testing"

"github.com/stretchr/testify/require"

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

func TestGenesisStateValidate(t *testing.T) {

testCases := []struct {
name string
genesisState GenesisState
expErr bool
}{
{
"valid genesisState",
GenesisState{
Params: DefaultParams(),
Balances: []Balance{
{
Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t",
Coins: sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
},
},
Supply: sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
DenomMetadata: []Metadata{
{
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
},
},
},
false,
},
{"empty genesisState", GenesisState{}, false},
{
"invalid params ",
GenesisState{
Params: Params{
SendEnabled: []*SendEnabled{
{"", true},
},
},
},
true,
},
{
"dup balances",
GenesisState{
Balances: []Balance{
{
Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t",
Coins: sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
},
{
Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t",
Coins: sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
},
},
},
true,
},
{
"invalid balance",
GenesisState{
Balances: []Balance{
{
Address: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t",
},
},
},
true,
},
{
"dup Metadata",
GenesisState{
DenomMetadata: []Metadata{
{
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
},
{
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "uatom",
Display: "atom",
},
},
},
true,
},
{
"invalid Metadata",
GenesisState{
DenomMetadata: []Metadata{
{
Description: "The native staking token of the Cosmos Hub.",
DenomUnits: []*DenomUnit{
{"uatom", uint32(0), []string{"microatom"}},
{"matom", uint32(3), []string{"milliatom"}},
{"atom", uint32(6), nil},
},
Base: "",
Display: "",
},
},
},
true,
},
{
"invalid supply",
GenesisState{
Supply: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.OneInt()}},
},
true,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {

err := tc.genesisState.Validate()

if tc.expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}