Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions substrate/frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,13 +1625,13 @@ mod tests {
}

struct MockCtx<'a> {
ext: &'a mut dyn Ext<T = Test>,
ext: &'a mut MockStack<'a>,
input_data: Vec<u8>,
}

#[derive(Clone)]
struct MockExecutable {
func: Rc<dyn Fn(MockCtx, &Self) -> ExecResult + 'static>,
func: Rc<dyn for<'a> Fn(MockCtx<'a>, &Self) -> ExecResult + 'static>,
func_type: ExportedFunction,
code_hash: CodeHash<Test>,
code_info: CodeInfo<Test>,
Expand Down Expand Up @@ -1724,6 +1724,16 @@ mod tests {
if let &Constructor = function {
Self::increment_refcount(self.code_hash).unwrap();
}
// # Safety
//
// We know that we **always** call execute with a `MockStack` in this test.
//
// # Note
//
// The transmute is necessary because `execute` has to be generic over all
// `E: Ext`. However, `MockExecutable` can't be generic over `E` as it would
// constitute a cycle.
let ext = unsafe { std::mem::transmute(ext) };
if function == &self.func_type {
(self.func)(MockCtx { ext, input_data }, &self)
} else {
Expand Down