Unverified Commit f7319126 authored by Michael Müller's avatar Michael Müller
Browse files

Experiment with macro to reduce code duplication

parent a18327ef
......@@ -31,6 +31,34 @@ use ink_primitives::Key;
use crate::ChainExtensionInstance;
#[macro_export]
macro_rules! mock_contract {
( $($tt:tt)* ) => {{
#![cfg_attr(not(feature = "std"), no_std)]
use ::ink_lang as ink;
use ::ink_env::{
Environment,
DefaultEnvironment,
call::{build_create, Selector, ExecutionInput, FromAccountId}
};
#[ink::contract]
pub mod my_contract {
#[ink(storage)]
pub struct MyContract { }
impl MyContract {
#[ink(constructor)]
pub fn new() -> Self {
Self {}
}
$( $tt )*
}
}
}};
}
/// The environment of the compiled ink! smart contract.
pub trait ContractEnv {
/// The environment type.
......@@ -114,33 +142,15 @@ where
/// # Example
///
/// ```
/// #![cfg_attr(not(feature = "std"), no_std)]
/// use ink_lang as ink;
/// use ink_prelude;
/// # use ::ink_env::{
/// # Environment,
/// # DefaultEnvironment,
/// # call::{build_create, Selector, ExecutionInput, FromAccountId}
/// # };
/// # #[ink::contract]
/// # pub mod my_contract {
/// # #[ink(storage)]
/// # pub struct MyContract { }
/// #
/// # impl MyContract {
/// # #[ink(constructor)]
/// # pub fn new() -> Self {
/// # Self {}
/// # }
///
/// # ink_lang::mock_contract! {
/// #[ink(message)]
/// pub fn call_me(&self) {
/// pub fn call_me2(&self) {
/// let caller = self.env().caller();
/// let message = ink_prelude::format!("got a call from {:?}", caller);
/// ink_env::debug_println(&message);
/// }
/// # }
/// # }
/// ```
///
/// # Note
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment