Merge pull request #799 from CosmWasm/empty_events
Tests some event edge cases
This commit is contained in:
@@ -183,6 +183,13 @@ func TestNewCustomEvents(t *testing.T) {
|
||||
sdk.NewAttribute("_contract_address", myContract.String()),
|
||||
sdk.NewAttribute("my Key", "myVal"))},
|
||||
},
|
||||
"empty event elements": {
|
||||
src: make(wasmvmtypes.Events, 10),
|
||||
isError: true,
|
||||
},
|
||||
"nil": {
|
||||
exp: sdk.Events{},
|
||||
},
|
||||
}
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@@ -240,6 +247,15 @@ func TestNewWasmModuleEvent(t *testing.T) {
|
||||
sdk.NewAttribute("_contract_address", myContract.String()),
|
||||
sdk.NewAttribute("my-real-key", "some-val"))},
|
||||
},
|
||||
"empty elements": {
|
||||
src: make([]wasmvmtypes.EventAttribute, 10),
|
||||
isError: true,
|
||||
},
|
||||
"nil": {
|
||||
exp: sdk.Events{sdk.NewEvent("wasm",
|
||||
sdk.NewAttribute("_contract_address", myContract.String()),
|
||||
)},
|
||||
},
|
||||
}
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
@@ -283,6 +283,26 @@ func TestReplyCost(t *testing.T) {
|
||||
srcConfig: DefaultGasRegisterConfig(),
|
||||
exp: sdk.Gas(DefaultInstanceCost + 3*DefaultContractMessageDataCost),
|
||||
},
|
||||
"subcall response with empty events": {
|
||||
src: wasmvmtypes.Reply{
|
||||
Result: wasmvmtypes.SubcallResult{
|
||||
Ok: &wasmvmtypes.SubcallResponse{
|
||||
Events: make([]wasmvmtypes.Event, 10),
|
||||
},
|
||||
},
|
||||
},
|
||||
srcConfig: DefaultGasRegisterConfig(),
|
||||
exp: DefaultInstanceCost,
|
||||
},
|
||||
"subcall response with events unset": {
|
||||
src: wasmvmtypes.Reply{
|
||||
Result: wasmvmtypes.SubcallResult{
|
||||
Ok: &wasmvmtypes.SubcallResponse{},
|
||||
},
|
||||
},
|
||||
srcConfig: DefaultGasRegisterConfig(),
|
||||
exp: DefaultInstanceCost,
|
||||
},
|
||||
}
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@@ -298,6 +318,33 @@ func TestReplyCost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventCosts(t *testing.T) {
|
||||
// most cases are covered in TestReplyCost already. This ensures some edge cases
|
||||
specs := map[string]struct {
|
||||
srcAttrs []wasmvmtypes.EventAttribute
|
||||
srcEvents wasmvmtypes.Events
|
||||
expGas sdk.Gas
|
||||
}{
|
||||
"empty events": {
|
||||
srcEvents: make([]wasmvmtypes.Event, 1),
|
||||
expGas: DefaultPerCustomEventCost,
|
||||
},
|
||||
"empty attributes": {
|
||||
srcAttrs: make([]wasmvmtypes.EventAttribute, 1),
|
||||
expGas: DefaultPerAttributeCost,
|
||||
},
|
||||
"both nil": {
|
||||
expGas: 0,
|
||||
},
|
||||
}
|
||||
for name, spec := range specs {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
gotGas := NewDefaultWasmGasRegister().EventCosts(spec.srcAttrs, spec.srcEvents)
|
||||
assert.Equal(t, spec.expGas, gotGas)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToWasmVMGasConversion(t *testing.T) {
|
||||
specs := map[string]struct {
|
||||
src storetypes.Gas
|
||||
|
||||
Reference in New Issue
Block a user