cadence
cadence copied to clipboard
testRuntimeInterface method should not return default values
Issue To Be Solved
The testRuntimeInterface
methods call hooks specified in the tests. If no hook is specified then some of them return default values. Instead of returning defaults, these methods should panic with a useful message. Also, some methods panic with a generic nil pointer reference when no hook is specified; they should panic with a useful message as well.
There are two reasons for this change:
- To speed up debugging with better error messages.
- Unmasking potential bugs hiding behind defaults. My reasoning is some tests may unintentionally rely on the default behavior of the FVM mock (aka testRuntimeInterface).
This issue's scope includes:
- Changes to the
testRuntimeInterface
methods in theruntime_test.go
file. - The myriad changes to the Cadence tests that break as a result of these changes.
This issue's scope does NOT include helper functions for populating testRuntimeInterface
with useful hooks unless doing so is faster because this issue isn't for wide-ranging test refactoring.
An example of such a helper function is getAccountKeyTestRuntimeInterface
in account_test.go
.
Suggested Solution
A few methods, like SetProgram
, do not need to be changed. This might also include ProgramChecked,
ProgramInterpreted,
ProgramInterpreted, and
RecordTrace`, which return nothing and default to simply returning.
Most others need a change like the inclusion of the conditional here:
func (i *testRuntimeInterface) SetCadenceValue(owner common.Address, key string, value cadence.Value) (err error) {
if i.setCadenceValue == nil {
panic("must specify testRuntimeInterface.setCadenceValue")
}
return i.setCadenceValue(owner, key, value)
}
Including the storage-using methods:
func (i *testRuntimeInterface) ValueExists(owner, key []byte) (exists bool, err error) {
if i.storage.valueExists == nil {
panic("must specify testRuntimeInterface.storage.valueExists")
}
return i.storage.ValueExists(owner, key)
}```