github.com/Finschia/finschia-sdk@v0.48.1/x/bank/types/genesis_test.go (about)

     1  package types
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	sdk "github.com/Finschia/finschia-sdk/types"
     9  )
    10  
    11  func TestGenesisStateValidate(t *testing.T) {
    12  	testCases := []struct {
    13  		name         string
    14  		genesisState GenesisState
    15  		expErr       bool
    16  	}{
    17  		{
    18  			"valid genesisState",
    19  			GenesisState{
    20  				Params: DefaultParams(),
    21  				Balances: []Balance{
    22  					{
    23  						Address: "link1yq8lgssgxlx9smjhes6ryjasmqmd3ts2p6925r",
    24  						Coins:   sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
    25  					},
    26  				},
    27  				Supply: sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
    28  				DenomMetadata: []Metadata{
    29  					{
    30  						Name:        "Cosmos Hub Atom",
    31  						Symbol:      "ATOM",
    32  						Description: "The native staking token of the Cosmos Hub.",
    33  						DenomUnits: []*DenomUnit{
    34  							{"uatom", uint32(0), []string{"microatom"}},
    35  							{"matom", uint32(3), []string{"milliatom"}},
    36  							{"atom", uint32(6), nil},
    37  						},
    38  						Base:    "uatom",
    39  						Display: "atom",
    40  					},
    41  				},
    42  			},
    43  			false,
    44  		},
    45  		{"empty genesisState", GenesisState{}, false},
    46  		{
    47  			"invalid params ",
    48  			GenesisState{
    49  				Params: Params{
    50  					SendEnabled: []*SendEnabled{
    51  						{"", true},
    52  					},
    53  				},
    54  			},
    55  			true,
    56  		},
    57  		{
    58  			"dup balances",
    59  			GenesisState{
    60  				Balances: []Balance{
    61  					{
    62  						Address: "link1yq8lgssgxlx9smjhes6ryjasmqmd3ts2p6925r",
    63  						Coins:   sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
    64  					},
    65  					{
    66  						Address: "link1yq8lgssgxlx9smjhes6ryjasmqmd3ts2p6925r",
    67  						Coins:   sdk.Coins{sdk.NewInt64Coin("uatom", 1)},
    68  					},
    69  				},
    70  			},
    71  			true,
    72  		},
    73  		{
    74  			"0  balance",
    75  			GenesisState{
    76  				Balances: []Balance{
    77  					{
    78  						Address: "link1yq8lgssgxlx9smjhes6ryjasmqmd3ts2p6925r",
    79  					},
    80  				},
    81  			},
    82  			false,
    83  		},
    84  		{
    85  			"dup Metadata",
    86  			GenesisState{
    87  				DenomMetadata: []Metadata{
    88  					{
    89  						Name:        "Cosmos Hub Atom",
    90  						Symbol:      "ATOM",
    91  						Description: "The native staking token of the Cosmos Hub.",
    92  						DenomUnits: []*DenomUnit{
    93  							{"uatom", uint32(0), []string{"microatom"}},
    94  							{"matom", uint32(3), []string{"milliatom"}},
    95  							{"atom", uint32(6), nil},
    96  						},
    97  						Base:    "uatom",
    98  						Display: "atom",
    99  					},
   100  					{
   101  						Name:        "Cosmos Hub Atom",
   102  						Symbol:      "ATOM",
   103  						Description: "The native staking token of the Cosmos Hub.",
   104  						DenomUnits: []*DenomUnit{
   105  							{"uatom", uint32(0), []string{"microatom"}},
   106  							{"matom", uint32(3), []string{"milliatom"}},
   107  							{"atom", uint32(6), nil},
   108  						},
   109  						Base:    "uatom",
   110  						Display: "atom",
   111  					},
   112  				},
   113  			},
   114  			true,
   115  		},
   116  		{
   117  			"invalid Metadata",
   118  			GenesisState{
   119  				DenomMetadata: []Metadata{
   120  					{
   121  						Name:        "Cosmos Hub Atom",
   122  						Symbol:      "ATOM",
   123  						Description: "The native staking token of the Cosmos Hub.",
   124  						DenomUnits: []*DenomUnit{
   125  							{"uatom", uint32(0), []string{"microatom"}},
   126  							{"matom", uint32(3), []string{"milliatom"}},
   127  							{"atom", uint32(6), nil},
   128  						},
   129  						Base:    "",
   130  						Display: "",
   131  					},
   132  				},
   133  			},
   134  			true,
   135  		},
   136  		{
   137  			"invalid supply",
   138  			GenesisState{
   139  				Supply: sdk.Coins{sdk.Coin{Denom: "", Amount: sdk.OneInt()}},
   140  			},
   141  			true,
   142  		},
   143  	}
   144  
   145  	for _, tc := range testCases {
   146  		tc := tc
   147  		t.Run(tc.name, func(t *testing.T) {
   148  			err := tc.genesisState.Validate()
   149  
   150  			if tc.expErr {
   151  				require.Error(t, err)
   152  			} else {
   153  				require.NoError(t, err)
   154  			}
   155  		})
   156  	}
   157  }