mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 10:37:56 +00:00
Fix up contracts pallet tests (#163)
* Revert contracts put_code test to pure code (not using the macro) * Test contract instantiate * Fmt
This commit is contained in:
@@ -19,6 +19,9 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
|
|||||||
[features]
|
[features]
|
||||||
client = ["substrate-subxt-client"]
|
client = ["substrate-subxt-client"]
|
||||||
|
|
||||||
|
# enable this feature to run tests which require a local dev chain node
|
||||||
|
integration-tests = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
thiserror = "1.0.20"
|
thiserror = "1.0.20"
|
||||||
|
|||||||
+77
-35
@@ -117,43 +117,85 @@ pub struct InstantiatedEvent<T: Contracts> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use sp_keyring::AccountKeyring;
|
||||||
|
|
||||||
subxt_test!({
|
use super::*;
|
||||||
name: test_put_code_and_instantiate,
|
use crate::{
|
||||||
prelude: {
|
ClientBuilder,
|
||||||
|
ContractsTemplateRuntime,
|
||||||
|
PairSigner,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn contract_wasm() -> Vec<u8> {
|
||||||
const CONTRACT: &str = r#"
|
const CONTRACT: &str = r#"
|
||||||
(module
|
(module
|
||||||
(func (export "call"))
|
(func (export "call"))
|
||||||
(func (export "deploy"))
|
(func (export "deploy"))
|
||||||
)
|
)
|
||||||
"#;
|
"#;
|
||||||
let wasm = wabt::wat2wasm(CONTRACT).expect("invalid wabt");
|
wabt::wat2wasm(CONTRACT).expect("invalid wabt")
|
||||||
let code_hash;
|
}
|
||||||
},
|
|
||||||
step: {
|
#[async_std::test]
|
||||||
call: PutCodeCall {
|
#[cfg(feature = "integration-tests")]
|
||||||
_runtime: PhantomData,
|
async fn tx_put_code() {
|
||||||
code: &wasm,
|
env_logger::try_init().ok();
|
||||||
},
|
|
||||||
event: CodeStoredEvent {
|
let signer = PairSigner::new(AccountKeyring::Alice.pair());
|
||||||
code_hash: {
|
let client = ClientBuilder::<ContractsTemplateRuntime>::new()
|
||||||
code_hash = event.code_hash.clone();
|
.build()
|
||||||
event.code_hash.clone()
|
.await
|
||||||
},
|
.unwrap();
|
||||||
},
|
|
||||||
},
|
let code = contract_wasm();
|
||||||
step: {
|
let result = client.put_code_and_watch(&signer, &code).await.unwrap();
|
||||||
call: InstantiateCall {
|
let code_stored = result.code_stored().unwrap();
|
||||||
endowment: 100_000_000_000_000,
|
|
||||||
gas_limit: 500_000_000,
|
assert!(
|
||||||
code_hash: &code_hash,
|
code_stored.is_some(),
|
||||||
data: &[],
|
format!(
|
||||||
},
|
"Error calling put_code and receiving CodeStored Event: {:?}",
|
||||||
event: InstantiatedEvent {
|
code_stored
|
||||||
caller: alice.clone(),
|
)
|
||||||
contract: event.contract.clone(),
|
);
|
||||||
},
|
}
|
||||||
},
|
|
||||||
});
|
#[async_std::test]
|
||||||
|
#[cfg(feature = "integration-tests")]
|
||||||
|
async fn tx_instantiate() {
|
||||||
|
env_logger::try_init().ok();
|
||||||
|
let signer = PairSigner::new(AccountKeyring::Bob.pair());
|
||||||
|
let client = ClientBuilder::<ContractsTemplateRuntime>::new()
|
||||||
|
.build()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// call put_code extrinsic
|
||||||
|
let code = contract_wasm();
|
||||||
|
let result = client.put_code_and_watch(&signer, &code).await.unwrap();
|
||||||
|
let code_stored = result.code_stored().unwrap();
|
||||||
|
let code_hash = code_stored.unwrap().code_hash;
|
||||||
|
|
||||||
|
log::info!("Code hash: {:?}", code_hash);
|
||||||
|
|
||||||
|
// call instantiate extrinsic
|
||||||
|
let result = client
|
||||||
|
.instantiate_and_watch(
|
||||||
|
&signer,
|
||||||
|
100_000_000_000_000, // endowment
|
||||||
|
500_000_000, // gas_limit
|
||||||
|
&code_hash,
|
||||||
|
&[], // data
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
log::info!("Instantiate result: {:?}", result);
|
||||||
|
let event = result.instantiated().unwrap();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
event.is_some(),
|
||||||
|
format!("Error instantiating contract: {:?}", result)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,39 @@ impl Balances for NodeTemplateRuntime {
|
|||||||
|
|
||||||
impl Sudo for NodeTemplateRuntime {}
|
impl Sudo for NodeTemplateRuntime {}
|
||||||
|
|
||||||
|
/// Concrete type definitions compatible with the node template, with the
|
||||||
|
/// contracts pallet enabled.
|
||||||
|
///
|
||||||
|
/// Inherits types from [`NodeTemplateRuntime`], but adds an implementation for
|
||||||
|
/// the contracts pallet trait.
|
||||||
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
pub struct ContractsTemplateRuntime;
|
||||||
|
|
||||||
|
impl Runtime for ContractsTemplateRuntime {
|
||||||
|
type Signature = <NodeTemplateRuntime as Runtime>::Signature;
|
||||||
|
type Extra = DefaultExtra<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl System for ContractsTemplateRuntime {
|
||||||
|
type Index = <NodeTemplateRuntime as System>::Index;
|
||||||
|
type BlockNumber = <NodeTemplateRuntime as System>::BlockNumber;
|
||||||
|
type Hash = <NodeTemplateRuntime as System>::Hash;
|
||||||
|
type Hashing = <NodeTemplateRuntime as System>::Hashing;
|
||||||
|
type AccountId = <NodeTemplateRuntime as System>::AccountId;
|
||||||
|
type Address = <NodeTemplateRuntime as System>::Address;
|
||||||
|
type Header = <NodeTemplateRuntime as System>::Header;
|
||||||
|
type Extrinsic = <NodeTemplateRuntime as System>::Extrinsic;
|
||||||
|
type AccountData = <NodeTemplateRuntime as System>::AccountData;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Balances for ContractsTemplateRuntime {
|
||||||
|
type Balance = <NodeTemplateRuntime as Balances>::Balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Contracts for ContractsTemplateRuntime {}
|
||||||
|
|
||||||
|
impl Sudo for ContractsTemplateRuntime {}
|
||||||
|
|
||||||
/// Concrete type definitions compatible with those for kusama, v0.7
|
/// Concrete type definitions compatible with those for kusama, v0.7
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
|
|||||||
Reference in New Issue
Block a user