-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests some event edge cases #799
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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{}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
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()), | ||
)}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
for name, spec := range specs { | ||
t.Run(name, func(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
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) | ||
}) | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good test |
||
func TestToWasmVMGasConversion(t *testing.T) { | ||
specs := map[string]struct { | ||
src storetypes.Gas | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍