You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There may be instances when mocking responses would be very useful. Currently, this requires some creative interface design specifically for the purposes of mocking as the functionality isn't supported natively.
Suggested Solution
I'm not clear on the implementation details required for this feature, but I'll leave some practical interface options for consideration and discussion
import"Foo"access(all)
funtestBar() {
letexpected: Int = 1// Label the subsequent call to Foo.bar() as mocked and return the provided value
Test.mock(Foo.bar(), expected)
letres = Foo.bar
Test.assertEqual(expected, res)
}
I'd also assume that implementation details for fvm-native functionality might look different. For instance, mocking calls to CadenceArch would be helpful for devs using Cadence in the EVM context
import CadenceArch // Assuming some mechanism for statically declaring CadenceArch calls from Cadenceimport"EVM"access(all)
funtestRevertibleRandom() {
letexpected: UInt64 = 1// Label the subsequent call to CadenceArch precompile as mocked and return the provided value
Test.mock(CadenceArch.revertibleRandom(), expected)
letres = executeScript("...", []) // execute some script that gets EVM randomness from a contract in EVM
Test.assertEqual(expected, res.returnValue!)
}
In general, testing randomness in either Cadence or EVM is rather difficult given the inherent non-deterministic behavior, and mocking would be helpful especially for this use case.
The text was updated successfully, but these errors were encountered:
Issue to be solved
There may be instances when mocking responses would be very useful. Currently, this requires some creative interface design specifically for the purposes of mocking as the functionality isn't supported natively.
Suggested Solution
I'm not clear on the implementation details required for this feature, but I'll leave some practical interface options for consideration and discussion
I'd also assume that implementation details for fvm-native functionality might look different. For instance, mocking calls to CadenceArch would be helpful for devs using Cadence in the EVM context
In general, testing randomness in either Cadence or EVM is rather difficult given the inherent non-deterministic behavior, and mocking would be helpful especially for this use case.
The text was updated successfully, but these errors were encountered: