@@ -117,43 +117,85 @@ pub struct InstantiatedEvent<T: Contracts> {
117
117
118
118
#[ cfg( test) ]
119
119
mod tests {
120
+ use sp_keyring:: AccountKeyring ;
121
+
120
122
use super :: * ;
123
+ use crate :: {
124
+ ClientBuilder ,
125
+ ContractsTemplateRuntime ,
126
+ PairSigner ,
127
+ } ;
128
+
129
+ fn contract_wasm ( ) -> Vec < u8 > {
130
+ const CONTRACT : & str = r#"
131
+ (module
132
+ (func (export "call"))
133
+ (func (export "deploy"))
134
+ )
135
+ "# ;
136
+ wabt:: wat2wasm ( CONTRACT ) . expect ( "invalid wabt" )
137
+ }
138
+
139
+ #[ async_std:: test]
140
+ #[ cfg( feature = "integration-tests" ) ]
141
+ async fn tx_put_code ( ) {
142
+ env_logger:: try_init ( ) . ok ( ) ;
143
+
144
+ let signer = PairSigner :: new ( AccountKeyring :: Alice . pair ( ) ) ;
145
+ let client = ClientBuilder :: < ContractsTemplateRuntime > :: new ( )
146
+ . build ( )
147
+ . await
148
+ . unwrap ( ) ;
149
+
150
+ let code = contract_wasm ( ) ;
151
+ let result = client. put_code_and_watch ( & signer, & code) . await . unwrap ( ) ;
152
+ let code_stored = result. code_stored ( ) . unwrap ( ) ;
153
+
154
+ assert ! (
155
+ code_stored. is_some( ) ,
156
+ format!(
157
+ "Error calling put_code and receiving CodeStored Event: {:?}" ,
158
+ code_stored
159
+ )
160
+ ) ;
161
+ }
162
+
163
+ #[ async_std:: test]
164
+ #[ cfg( feature = "integration-tests" ) ]
165
+ async fn tx_instantiate ( ) {
166
+ env_logger:: try_init ( ) . ok ( ) ;
167
+ let signer = PairSigner :: new ( AccountKeyring :: Bob . pair ( ) ) ;
168
+ let client = ClientBuilder :: < ContractsTemplateRuntime > :: new ( )
169
+ . build ( )
170
+ . await
171
+ . unwrap ( ) ;
172
+
173
+ // call put_code extrinsic
174
+ let code = contract_wasm ( ) ;
175
+ let result = client. put_code_and_watch ( & signer, & code) . await . unwrap ( ) ;
176
+ let code_stored = result. code_stored ( ) . unwrap ( ) ;
177
+ let code_hash = code_stored. unwrap ( ) . code_hash ;
178
+
179
+ log:: info!( "Code hash: {:?}" , code_hash) ;
180
+
181
+ // call instantiate extrinsic
182
+ let result = client
183
+ . instantiate_and_watch (
184
+ & signer,
185
+ 100_000_000_000_000 , // endowment
186
+ 500_000_000 , // gas_limit
187
+ & code_hash,
188
+ & [ ] , // data
189
+ )
190
+ . await
191
+ . unwrap ( ) ;
192
+
193
+ log:: info!( "Instantiate result: {:?}" , result) ;
194
+ let event = result. instantiated ( ) . unwrap ( ) ;
121
195
122
- subxt_test ! ( {
123
- name: test_put_code_and_instantiate,
124
- prelude: {
125
- const CONTRACT : & str = r#"
126
- (module
127
- (func (export "call"))
128
- (func (export "deploy"))
129
- )
130
- "# ;
131
- let wasm = wabt:: wat2wasm( CONTRACT ) . expect( "invalid wabt" ) ;
132
- let code_hash;
133
- } ,
134
- step: {
135
- call: PutCodeCall {
136
- _runtime: PhantomData ,
137
- code: & wasm,
138
- } ,
139
- event: CodeStoredEvent {
140
- code_hash: {
141
- code_hash = event. code_hash. clone( ) ;
142
- event. code_hash. clone( )
143
- } ,
144
- } ,
145
- } ,
146
- step: {
147
- call: InstantiateCall {
148
- endowment: 100_000_000_000_000 ,
149
- gas_limit: 500_000_000 ,
150
- code_hash: & code_hash,
151
- data: & [ ] ,
152
- } ,
153
- event: InstantiatedEvent {
154
- caller: alice. clone( ) ,
155
- contract: event. contract. clone( ) ,
156
- } ,
157
- } ,
158
- } ) ;
196
+ assert ! (
197
+ event. is_some( ) ,
198
+ format!( "Error instantiating contract: {:?}" , result)
199
+ ) ;
200
+ }
159
201
}
0 commit comments