Skip to content

Commit

Permalink
Add a few more tests as requested in review
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed May 10, 2022
1 parent a67dae7 commit 27d3051
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
22 changes: 22 additions & 0 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ func TestEnforceValidPermissionsOnCreate(t *testing.T) {

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
creator := keepers.Faucet.NewFundedAccount(ctx, deposit...)
other := keepers.Faucet.NewFundedAccount(ctx, deposit...)

onlyCreator := types.AccessTypeOnlyAddress.With(creator)
onlyOther := types.AccessTypeOnlyAddress.With(other)

specs := map[string]struct {
defaultPermssion types.AccessType
Expand All @@ -213,6 +215,11 @@ func TestEnforceValidPermissionsOnCreate(t *testing.T) {
requestedPermission: nil,
grantedPermission: types.AccessConfig{Permission: types.AccessTypeEverybody},
},
"explicitly set everybody": {
defaultPermssion: types.AccessTypeEverybody,
requestedPermission: &types.AccessConfig{Permission: types.AccessTypeEverybody},
grantedPermission: types.AccessConfig{Permission: types.AccessTypeEverybody},
},
"cannot override nobody": {
defaultPermssion: types.AccessTypeNobody,
requestedPermission: &onlyCreator,
Expand All @@ -223,6 +230,21 @@ func TestEnforceValidPermissionsOnCreate(t *testing.T) {
requestedPermission: nil,
grantedPermission: types.AccessConfig{Permission: types.AccessTypeNobody},
},
"only defaults to code creator": {
defaultPermssion: types.AccessTypeOnlyAddress,
requestedPermission: nil,
grantedPermission: onlyCreator,
},
"can explicitly set to code creator": {
defaultPermssion: types.AccessTypeOnlyAddress,
requestedPermission: &onlyCreator,
grantedPermission: onlyCreator,
},
"cannot override which address in only": {
defaultPermssion: types.AccessTypeOnlyAddress,
requestedPermission: &onlyOther,
expError: sdkerrors.ErrUnauthorized,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
Expand Down
15 changes: 10 additions & 5 deletions x/wasm/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ func TestAccesConfigSubset(t *testing.T) {
check: AccessConfig{Permission: AccessTypeEverybody},
isSubSet: false,
},
"unspecified > nobody": {
superSet: AccessConfig{Permission: AccessTypeNobody},
check: AccessConfig{Permission: AccessTypeUnspecified},
isSubSet: false,
},
"nobody <= everybody": {
superSet: AccessConfig{Permission: AccessTypeEverybody},
check: AccessConfig{Permission: AccessTypeNobody},
Expand All @@ -409,6 +414,11 @@ func TestAccesConfigSubset(t *testing.T) {
check: AccessConfig{Permission: AccessTypeEverybody},
isSubSet: true,
},
"unspecified > everybody": {
superSet: AccessConfig{Permission: AccessTypeEverybody},
check: AccessConfig{Permission: AccessTypeUnspecified},
isSubSet: false,
},
"nobody <= only": {
superSet: AccessConfig{Permission: AccessTypeOnlyAddress, Address: "owner"},
check: AccessConfig{Permission: AccessTypeNobody},
Expand All @@ -434,11 +444,6 @@ func TestAccesConfigSubset(t *testing.T) {
check: AccessConfig{Permission: AccessTypeNobody},
isSubSet: false,
},
"unspecified > everybody": {
superSet: AccessConfig{Permission: AccessTypeEverybody},
check: AccessConfig{Permission: AccessTypeUnspecified},
isSubSet: false,
},
}

for name, spec := range specs {
Expand Down

0 comments on commit 27d3051

Please sign in to comment.