Finschia / cosmwasm

Fast and reusable WebAssembly smart contract runtime(and library) for finschia-sdk.
Apache License 2.0
27 stars 14 forks source link

Enable to make mock impls of dynamic linked functions #227

Closed loloicci closed 2 years ago

loloicci commented 2 years ago

When using dynamic_link macro, users cannot make mocks impls of dynamic callee functions in the caller contract. Enable it with an attribute of the macro.

// if `user_defined_mock` is false, this macro generates `impl Bar for Foo` for all targets.
// if it is true, this generates impl for wasm32 target only.
#[dynamic_link(Foo, user_defined_mock = true)]
trait Bar: Contract {
  fn foobar(...) { ... }
}

// mock impl
#[cfg(not(target_arch = "wasm32"))]
impl Bar for Foo {
  fn foobar(...) { ... }
}