@@ -31,6 +31,34 @@ use ink_primitives::Key;
31
31
32
32
use crate :: ChainExtensionInstance ;
33
33
34
+ #[ macro_export]
35
+ macro_rules! mock_contract {
36
+ ( $( $tt: tt) * ) => { {
37
+ #![ cfg_attr( not( feature = "std" ) , no_std) ]
38
+ use :: ink_lang as ink;
39
+ use :: ink_env:: {
40
+ Environment ,
41
+ DefaultEnvironment ,
42
+ call:: { build_create, Selector , ExecutionInput , FromAccountId }
43
+ } ;
44
+ #[ ink:: contract]
45
+ pub mod my_contract {
46
+ #[ ink( storage) ]
47
+ pub struct MyContract { }
48
+
49
+ impl MyContract {
50
+ #[ ink( constructor) ]
51
+ pub fn new( ) -> Self {
52
+ Self { }
53
+ }
54
+
55
+ $( $tt ) *
56
+
57
+ }
58
+ }
59
+ } } ;
60
+ }
61
+
34
62
/// The environment of the compiled ink! smart contract.
35
63
pub trait ContractEnv {
36
64
/// The environment type.
@@ -114,33 +142,15 @@ where
114
142
/// # Example
115
143
///
116
144
/// ```
117
- /// #![cfg_attr(not(feature = "std"), no_std)]
118
- /// use ink_lang as ink;
119
145
/// use ink_prelude;
120
- /// # use ::ink_env::{
121
- /// # Environment,
122
- /// # DefaultEnvironment,
123
- /// # call::{build_create, Selector, ExecutionInput, FromAccountId}
124
- /// # };
125
- /// # #[ink::contract]
126
- /// # pub mod my_contract {
127
- /// # #[ink(storage)]
128
- /// # pub struct MyContract { }
129
- /// #
130
- /// # impl MyContract {
131
- /// # #[ink(constructor)]
132
- /// # pub fn new() -> Self {
133
- /// # Self {}
134
- /// # }
135
- ///
146
+ /// # ink_lang::mock_contract! {
136
147
/// #[ink(message)]
137
- /// pub fn call_me (&self) {
148
+ /// pub fn call_me2 (&self) {
138
149
/// let caller = self.env().caller();
139
150
/// let message = ink_prelude::format!("got a call from {:?}", caller);
140
151
/// ink_env::debug_println(&message);
141
152
/// }
142
153
/// # }
143
- /// # }
144
154
/// ```
145
155
///
146
156
/// # Note
0 commit comments