mirror of https://github.com/certusone/wasmd.git
Fix tests, handle genesis init as well
This commit is contained in:
parent
acd1cf9dfe
commit
332f4cc9a8
|
@ -138,6 +138,7 @@ func GenesisInstantiateContractCmd(defaultNodeHome string, genesisMutator Genesi
|
|||
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
|
||||
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
|
||||
cmd.Flags().String(flagAdmin, "", "Address of an admin")
|
||||
cmd.Flags().Bool(flagNoAdmin, false, "You must set this explicitly if you don't want an admin")
|
||||
cmd.Flags().String(flagRunAs, "", "The address that pays the init funds. It is the creator of the contract.")
|
||||
|
||||
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
|
||||
|
|
|
@ -142,6 +142,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet := cmd.Flags()
|
||||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", myWellFundedAccount)
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expMsgCount: 1,
|
||||
},
|
||||
|
@ -157,6 +158,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet := cmd.Flags()
|
||||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", myWellFundedAccount)
|
||||
flagSet.Set("admin", myWellFundedAccount)
|
||||
},
|
||||
expMsgCount: 2,
|
||||
},
|
||||
|
@ -175,6 +177,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet := cmd.Flags()
|
||||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", myWellFundedAccount)
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expMsgCount: 2,
|
||||
},
|
||||
|
@ -185,6 +188,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet := cmd.Flags()
|
||||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", myWellFundedAccount)
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expError: true,
|
||||
},
|
||||
|
@ -202,6 +206,59 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet := cmd.Flags()
|
||||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", myWellFundedAccount)
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expError: true,
|
||||
},
|
||||
"fails if no explicit --no-admin passed": {
|
||||
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)
|
||||
},
|
||||
expError: true,
|
||||
},
|
||||
"fails if both --admin and --no-admin passed": {
|
||||
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("no-admin", "true")
|
||||
flagSet.Set("admin", myWellFundedAccount)
|
||||
},
|
||||
expError: true,
|
||||
},
|
||||
|
@ -227,6 +284,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet := cmd.Flags()
|
||||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expMsgCount: 1,
|
||||
},
|
||||
|
@ -253,6 +311,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", myWellFundedAccount)
|
||||
flagSet.Set("amount", "100stake")
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expMsgCount: 1,
|
||||
},
|
||||
|
@ -279,6 +338,7 @@ func TestInstantiateContractCmd(t *testing.T) {
|
|||
flagSet.Set("label", "testing")
|
||||
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
|
||||
flagSet.Set("amount", "10stake")
|
||||
flagSet.Set("no-admin", "true")
|
||||
},
|
||||
expError: true,
|
||||
},
|
||||
|
|
|
@ -189,15 +189,17 @@ func parseInstantiateArgs(rawCodeID, initMsg string, sender sdk.AccAddress, flag
|
|||
if err != nil {
|
||||
return types.MsgInstantiateContract{}, fmt.Errorf("admin: %s", err)
|
||||
}
|
||||
noAdmin, err := flags.GetBool(flagNoAdmin)
|
||||
if err != nil {
|
||||
return types.MsgInstantiateContract{}, fmt.Errorf("no-admin: %s", err)
|
||||
}
|
||||
|
||||
if adminStr == "" {
|
||||
noAdmin, err := flags.GetBool(flagNoAdmin)
|
||||
if err != nil {
|
||||
return types.MsgInstantiateContract{}, fmt.Errorf("no-admin: %s", err)
|
||||
}
|
||||
if !noAdmin {
|
||||
return types.MsgInstantiateContract{}, fmt.Errorf("You must set an admin or explicitly pass --no-admin to make it immutible (wasmd issue #719)")
|
||||
}
|
||||
// ensure sensible admin is set (or explicitly immutable)
|
||||
if adminStr == "" && !noAdmin {
|
||||
return types.MsgInstantiateContract{}, fmt.Errorf("You must set an admin or explicitly pass --no-admin to make it immutible (wasmd issue #719)")
|
||||
}
|
||||
if adminStr != "" && noAdmin {
|
||||
return types.MsgInstantiateContract{}, fmt.Errorf("You set an admin and passed --no-admin, those cannot both be true")
|
||||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
|
|
Loading…
Reference in New Issue