Skip to content

Commit

Permalink
Don't enforce balance when no funds sent
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jan 8, 2021
1 parent 87eb03d commit 9650941
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
4 changes: 4 additions & 0 deletions x/wasm/client/cli/genesis_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ func getAllContracts(state *types.GenesisState) []contractMeta {
}

func hasAccountBalance(cmd *cobra.Command, appState map[string]json.RawMessage, sender sdk.AccAddress, coins sdk.Coins) (bool, error) {
// no coins needed, no account needed
if coins.IsZero() {
return true, nil
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return false, err
Expand Down
110 changes: 109 additions & 1 deletion x/wasm/client/cli/genesis_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestInstantiateContractCmd(t *testing.T) {
},
expError: true,
},
"fails without a sender balance": {
"succeeds with unknown account when no init_funds": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
Expand All @@ -239,6 +239,58 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet.Set("label", "testing")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
},
expMsgCount: 1,
},
"succeeds with funds from well funded account": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("amount", "100stake")
},
expMsgCount: 1,
},
"fails without enough sender balance": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("amount", "10stake")
},
expError: true,
},
}
Expand Down Expand Up @@ -359,6 +411,61 @@ func TestExecuteContractCmd(t *testing.T) {
},
expError: true,
},
"succeeds with unknown account when no sent_funds": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
Contracts: []types.Contract{
{
ContractAddress: firstContractAddress,
ContractInfo: types.ContractInfoFixture(func(info *types.ContractInfo) {
info.Created = nil
}),
ContractState: []types.Model{},
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
},
expMsgCount: 1,
},
"succeeds with funds from well funded account": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfoFixture(),
CodeBytes: wasmIdent,
},
},
Contracts: []types.Contract{
{
ContractAddress: firstContractAddress,
ContractInfo: types.ContractInfoFixture(func(info *types.ContractInfo) {
info.Created = nil
}),
ContractState: []types.Model{},
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("amount", "100stake")
},
expMsgCount: 1,
},
"fails without enough sender balance": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Expand All @@ -383,6 +490,7 @@ func TestExecuteContractCmd(t *testing.T) {
cmd.SetArgs([]string{firstContractAddress, `{}`})
flagSet := cmd.Flags()
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("amount", "10stake")
},
expError: true,
},
Expand Down

0 comments on commit 9650941

Please sign in to comment.