Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Sep 28, 2023
1 parent 014cc10 commit 8dd324f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
21 changes: 16 additions & 5 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2498,42 +2498,53 @@ func TestSetContractLabel(t *testing.T) {
newLabel string
caller sdk.AccAddress
policy types.AuthorizationPolicy
contract sdk.AccAddress
expErr bool
}{
"update label - default policy": {
newLabel: "new label",
caller: example.CreatorAddr,
policy: DefaultAuthorizationPolicy{},
contract: example.Contract,
},
"update label - gov policy": {
newLabel: "new label",
policy: GovAuthorizationPolicy{},
caller: RandomAccountAddress(t),
contract: example.Contract,
},
"update label - unauthorized": {
newLabel: "new label",
caller: RandomAccountAddress(t),
policy: DefaultAuthorizationPolicy{},
contract: example.Contract,
expErr: true,
},
"update label - gov policy": {
"update label - unknown contract": {
newLabel: "new label",
policy: GovAuthorizationPolicy{},
caller: example.CreatorAddr,
policy: DefaultAuthorizationPolicy{},
contract: RandomAccountAddress(t),
expErr: true,
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
ctx, _ := parentCtx.CacheContext()
em := sdk.NewEventManager()
ctx = ctx.WithEventManager(em)
gotErr := k.setContractLabel(ctx, example.Contract, spec.caller, spec.newLabel, spec.policy)
gotErr := k.setContractLabel(ctx, spec.contract, spec.caller, spec.newLabel, spec.policy)
if spec.expErr {
require.Error(t, gotErr)
return
}
require.NoError(t, gotErr)
assert.Equal(t, spec.newLabel, k.GetContractInfo(ctx, example.Contract).Label)
assert.Equal(t, spec.newLabel, k.GetContractInfo(ctx, spec.contract).Label)
// and event emitted
require.Len(t, em.Events(), 1)
assert.Equal(t, "update_contract_label", em.Events()[0].Type)
exp := map[string]string{
"_contract_address": example.Contract.String(),
"_contract_address": spec.contract.String(),
"new_label": spec.newLabel,
}
assert.Equal(t, exp, attrsToStringMap(em.Events()[0].Attributes))
Expand Down
31 changes: 22 additions & 9 deletions x/wasm/keeper/msg_server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,21 +1156,34 @@ func TestUpdateContractLabel(t *testing.T) {
)

specs := map[string]struct {
addr string
expErr bool
addr string
newLabel string
expErr bool
}{
"authority can update contract label": {
addr: authority,
expErr: false,
addr: authority,
newLabel: "new label",
expErr: false,
},
"admin can update contract label": {
addr: myAddress.String(),
expErr: false,
addr: myAddress.String(),
newLabel: "new label",
expErr: false,
},
"other address cannot update contract label": {
addr: otherAddr.String(),
addr: otherAddr.String(),
newLabel: "new label",
expErr: true,
},
"empty new label": {
addr: authority,
expErr: true,
},
"invalid new label": {
addr: authority,
newLabel: " start with space ",
expErr: true,
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
Expand Down Expand Up @@ -1198,7 +1211,7 @@ func TestUpdateContractLabel(t *testing.T) {
// when
msgUpdateLabel := &types.MsgUpdateContractLabel{
Sender: spec.addr,
NewLabel: "new label",
NewLabel: spec.newLabel,
Contract: storeAndInstantiateResponse.Address,
}
_, err = wasmApp.MsgServiceRouter().Handler(msgUpdateLabel)(ctx, msgUpdateLabel)
Expand All @@ -1209,7 +1222,7 @@ func TestUpdateContractLabel(t *testing.T) {
require.Equal(t, "old label", wasmApp.WasmKeeper.GetContractInfo(ctx, contractAddr).Label)
} else {
require.NoError(t, err)
require.Equal(t, "new label", wasmApp.WasmKeeper.GetContractInfo(ctx, contractAddr).Label)
require.Equal(t, spec.newLabel, wasmApp.WasmKeeper.GetContractInfo(ctx, contractAddr).Label)
}
})
}
Expand Down

0 comments on commit 8dd324f

Please sign in to comment.