forked from cerc-io/laconicd-deprecated
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/cerc-io/laconicd/x/wasm/types"
|
|
)
|
|
|
|
func TestParseAccessConfigFlags(t *testing.T) {
|
|
specs := map[string]struct {
|
|
args []string
|
|
expCfg *types.AccessConfig
|
|
expErr bool
|
|
}{
|
|
"nobody": {
|
|
args: []string{"--instantiate-nobody=true"},
|
|
expCfg: &types.AccessConfig{Permission: types.AccessTypeNobody},
|
|
},
|
|
"everybody": {
|
|
args: []string{"--instantiate-everybody=true"},
|
|
expCfg: &types.AccessConfig{Permission: types.AccessTypeEverybody},
|
|
},
|
|
"only address": {
|
|
args: []string{"--instantiate-only-address=cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"},
|
|
expErr: true,
|
|
},
|
|
"only address - invalid": {
|
|
args: []string{"--instantiate-only-address=foo"},
|
|
expErr: true,
|
|
},
|
|
"any of address": {
|
|
args: []string{"--instantiate-anyof-addresses=cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"},
|
|
expCfg: &types.AccessConfig{Permission: types.AccessTypeAnyOfAddresses, Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}},
|
|
},
|
|
"any of address - invalid": {
|
|
args: []string{"--instantiate-anyof-addresses=cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,foo"},
|
|
expErr: true,
|
|
},
|
|
"not set": {
|
|
args: []string{},
|
|
},
|
|
}
|
|
for name, spec := range specs {
|
|
t.Run(name, func(t *testing.T) {
|
|
flags := StoreCodeCmd().Flags()
|
|
require.NoError(t, flags.Parse(spec.args))
|
|
gotCfg, gotErr := parseAccessConfigFlags(flags)
|
|
if spec.expErr {
|
|
require.Error(t, gotErr)
|
|
return
|
|
}
|
|
require.NoError(t, gotErr)
|
|
assert.Equal(t, spec.expCfg, gotCfg)
|
|
})
|
|
}
|
|
}
|