98 lines
2.8 KiB
Go
98 lines
2.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/CosmWasm/wasmd/x/wasm/types"
|
|
)
|
|
|
|
func TestParseAccessConfigUpdates(t *testing.T) {
|
|
specs := map[string]struct {
|
|
src []string
|
|
exp []types.AccessConfigUpdate
|
|
expErr bool
|
|
}{
|
|
"nobody": {
|
|
src: []string{"1:nobody"},
|
|
exp: []types.AccessConfigUpdate{{
|
|
CodeID: 1,
|
|
InstantiatePermission: types.AccessConfig{Permission: types.AccessTypeNobody},
|
|
}},
|
|
},
|
|
"everybody": {
|
|
src: []string{"1:everybody"},
|
|
exp: []types.AccessConfigUpdate{{
|
|
CodeID: 1,
|
|
InstantiatePermission: types.AccessConfig{Permission: types.AccessTypeEverybody},
|
|
}},
|
|
},
|
|
"any of addresses - single": {
|
|
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"},
|
|
exp: []types.AccessConfigUpdate{
|
|
{
|
|
CodeID: 1,
|
|
InstantiatePermission: types.AccessConfig{
|
|
Permission: types.AccessTypeAnyOfAddresses,
|
|
Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"any of addresses - multiple": {
|
|
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"},
|
|
exp: []types.AccessConfigUpdate{
|
|
{
|
|
CodeID: 1,
|
|
InstantiatePermission: types.AccessConfig{
|
|
Permission: types.AccessTypeAnyOfAddresses,
|
|
Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"multiple code ids with different permissions": {
|
|
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", "2:nobody"},
|
|
exp: []types.AccessConfigUpdate{
|
|
{
|
|
CodeID: 1,
|
|
InstantiatePermission: types.AccessConfig{
|
|
Permission: types.AccessTypeAnyOfAddresses,
|
|
Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"},
|
|
},
|
|
}, {
|
|
CodeID: 2,
|
|
InstantiatePermission: types.AccessConfig{
|
|
Permission: types.AccessTypeNobody,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"any of addresses - empty list": {
|
|
src: []string{"1:"},
|
|
expErr: true,
|
|
},
|
|
"any of addresses - invalid address": {
|
|
src: []string{"1:foo"},
|
|
expErr: true,
|
|
},
|
|
"any of addresses - duplicate address": {
|
|
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"},
|
|
expErr: true,
|
|
},
|
|
}
|
|
for name, spec := range specs {
|
|
t.Run(name, func(t *testing.T) {
|
|
got, gotErr := parseAccessConfigUpdates(spec.src)
|
|
if spec.expErr {
|
|
require.Error(t, gotErr)
|
|
return
|
|
}
|
|
require.NoError(t, gotErr)
|
|
assert.Equal(t, spec.exp, got)
|
|
})
|
|
}
|
|
}
|