mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 01:41:03 +00:00
Convert integration tests to use test node process (#253)
* Remove integration-tests feature, use test node process * Allow tests to run in parallel * Fmt * Fix errors * Fix more errors * Use test node process in test context * Remove code for managing accounts for contract tests * Update contract dispatchables * Fix up contract calls for 3.0 compat * Fmt * Fix up some tests * Fix some more tests * Fix some more tests * Fmt
This commit is contained in:
@@ -37,4 +37,4 @@ jobs:
|
|||||||
run: cargo build --workspace --verbose
|
run: cargo build --workspace --verbose
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: cargo test --workspace --verbose -- --test-threads=1
|
run: cargo test --workspace --verbose
|
||||||
|
|||||||
+9
-13
@@ -226,26 +226,22 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
#[cfg(feature = "integration-tests")]
|
|
||||||
async fn test_state_balance_lock() -> Result<(), crate::Error> {
|
async fn test_state_balance_lock() -> Result<(), crate::Error> {
|
||||||
use crate::{
|
use crate::frame::staking::{
|
||||||
frame::staking::{
|
BondCallExt,
|
||||||
BondCallExt,
|
RewardDestination,
|
||||||
RewardDestination,
|
|
||||||
},
|
|
||||||
runtimes::KusamaRuntime as RT,
|
|
||||||
ClientBuilder,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let bob = PairSigner::<RT, _>::new(AccountKeyring::Bob.pair());
|
let bob = PairSigner::<TestRuntime, _>::new(AccountKeyring::Bob.pair());
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
|
|
||||||
client
|
client
|
||||||
.bond_and_watch(
|
.bond_and_watch(
|
||||||
&bob,
|
&bob,
|
||||||
AccountKeyring::Charlie.to_account_id(),
|
&AccountKeyring::Charlie.to_account_id().into(),
|
||||||
100_000_000_000,
|
100_000_000_000_000,
|
||||||
RewardDestination::Stash,
|
RewardDestination::Stash,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -258,7 +254,7 @@ mod tests {
|
|||||||
locks,
|
locks,
|
||||||
vec![BalanceLock {
|
vec![BalanceLock {
|
||||||
id: *b"staking ",
|
id: *b"staking ",
|
||||||
amount: 100_000_000_000,
|
amount: 100_000_000_000_000,
|
||||||
reasons: Reasons::All,
|
reasons: Reasons::All,
|
||||||
}]
|
}]
|
||||||
);
|
);
|
||||||
|
|||||||
+93
-105
@@ -24,7 +24,6 @@ use codec::{
|
|||||||
Decode,
|
Decode,
|
||||||
Encode,
|
Encode,
|
||||||
};
|
};
|
||||||
use core::marker::PhantomData;
|
|
||||||
|
|
||||||
/// Gas units are chosen to be represented by u64 so that gas metering
|
/// Gas units are chosen to be represented by u64 so that gas metering
|
||||||
/// instructions can operate on them efficiently.
|
/// instructions can operate on them efficiently.
|
||||||
@@ -34,52 +33,63 @@ pub type Gas = u64;
|
|||||||
#[module]
|
#[module]
|
||||||
pub trait Contracts: System + Balances {}
|
pub trait Contracts: System + Balances {}
|
||||||
|
|
||||||
/// Stores the given binary Wasm code into the chain's storage and returns
|
/// Instantiates a new contract from the supplied `code` optionally transferring
|
||||||
/// its `codehash`.
|
/// some balance.
|
||||||
/// You can instantiate contracts only with stored code.
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
|
|
||||||
pub struct PutCodeCall<'a, T: Contracts> {
|
|
||||||
/// Runtime marker.
|
|
||||||
pub _runtime: PhantomData<T>,
|
|
||||||
/// Wasm blob.
|
|
||||||
pub code: &'a [u8],
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new contract from the `codehash` generated by `put_code`,
|
|
||||||
/// optionally transferring some balance.
|
|
||||||
///
|
///
|
||||||
/// Creation is executed as follows:
|
/// This is the only function that can deploy new code to the chain.
|
||||||
///
|
///
|
||||||
/// - The destination address is computed based on the sender and hash of
|
/// Instantiation is executed as follows:
|
||||||
/// the code.
|
///
|
||||||
/// - The smart-contract account is instantiated at the computed address.
|
/// - The supplied `code` is instrumented, deployed, and a `code_hash` is created for that code.
|
||||||
/// - The `ctor_code` is executed in the context of the newly-instantiated
|
/// - If the `code_hash` already exists on the chain the underlying `code` will be shared.
|
||||||
/// account. Buffer returned after the execution is saved as the `code`https://www.bbc.co.uk/
|
/// - The destination address is computed based on the sender, code_hash and the salt.
|
||||||
/// of the account. That code will be invoked upon any call received by
|
/// - The smart-contract account is created at the computed address.
|
||||||
/// this account.
|
/// - The `endowment` is transferred to the new account.
|
||||||
/// - The contract is initialized.
|
/// - The `deploy` function is executed in the context of the newly-created account.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
|
#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
|
||||||
pub struct InstantiateCall<'a, T: Contracts> {
|
pub struct InstantiateWithCodeCall<'a, T: Contracts> {
|
||||||
/// Initial balance transferred to the contract.
|
/// The balance to transfer from the `origin` to the newly created contract.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub endowment: <T as Balances>::Balance,
|
pub endowment: <T as Balances>::Balance,
|
||||||
/// Gas limit.
|
/// The gas limit enforced when executing the constructor.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub gas_limit: Gas,
|
pub gas_limit: Gas,
|
||||||
/// Code hash returned by the put_code call.
|
/// The contract code to deploy in raw bytes.
|
||||||
|
pub code: &'a [u8],
|
||||||
|
/// The input data to pass to the contract constructor.
|
||||||
|
pub data: &'a [u8],
|
||||||
|
/// Used for the address derivation.
|
||||||
|
pub salt: &'a [u8],
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiates a contract from a previously deployed wasm binary.
|
||||||
|
///
|
||||||
|
/// This function is identical to [`InstantiateWithCodeCall`] but without the
|
||||||
|
/// code deployment step. Instead, the `code_hash` of an on-chain deployed wasm binary
|
||||||
|
/// must be supplied.
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
|
||||||
|
pub struct InstantiateCall<'a, T: Contracts> {
|
||||||
|
/// The balance to transfer from the `origin` to the newly created contract.
|
||||||
|
#[codec(compact)]
|
||||||
|
pub endowment: <T as Balances>::Balance,
|
||||||
|
/// The gas limit enforced when executing the constructor.
|
||||||
|
#[codec(compact)]
|
||||||
|
pub gas_limit: Gas,
|
||||||
|
/// Code hash of the already deployed on-chain deployed wasm binary.
|
||||||
pub code_hash: &'a <T as System>::Hash,
|
pub code_hash: &'a <T as System>::Hash,
|
||||||
/// Data to initialize the contract with.
|
/// Data to initialize the contract with.
|
||||||
pub data: &'a [u8],
|
pub data: &'a [u8],
|
||||||
|
/// Used for the address derivation.
|
||||||
|
pub salt: &'a [u8],
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes a call to an account, optionally transferring some balance.
|
/// Makes a call to an account, optionally transferring some balance.
|
||||||
///
|
///
|
||||||
/// * If the account is a smart-contract account, the associated code will
|
/// * If the account is a smart-contract account, the associated code will be
|
||||||
/// be executed and any value will be transferred.
|
/// executed and any value will be transferred.
|
||||||
/// * If the account is a regular account, any value will be transferred.
|
/// * If the account is a regular account, any value will be transferred.
|
||||||
/// * If no account exists and the call value is not less than
|
/// * If no account exists and the call value is not less than `existential_deposit`,
|
||||||
/// `existential_deposit`, a regular account will be created and any value
|
/// a regular account will be created and any value will be transferred.
|
||||||
/// will be transferred.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Call, Encode)]
|
#[derive(Clone, Debug, PartialEq, Call, Encode)]
|
||||||
pub struct CallCall<'a, T: Contracts> {
|
pub struct CallCall<'a, T: Contracts> {
|
||||||
/// Address of the contract.
|
/// Address of the contract.
|
||||||
@@ -122,82 +132,44 @@ pub struct ContractExecutionEvent<T: Contracts> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "integration-tests")]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
use sp_keyring::AccountKeyring;
|
use sp_keyring::AccountKeyring;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
balances::*,
|
tests::{
|
||||||
system::*,
|
test_node_process,
|
||||||
|
TestNodeProcess,
|
||||||
|
TestRuntime,
|
||||||
|
},
|
||||||
Client,
|
Client,
|
||||||
ClientBuilder,
|
|
||||||
ContractsTemplateRuntime,
|
|
||||||
Error,
|
Error,
|
||||||
ExtrinsicSuccess,
|
ExtrinsicSuccess,
|
||||||
PairSigner,
|
PairSigner,
|
||||||
Signer,
|
|
||||||
};
|
};
|
||||||
use sp_core::{
|
use sp_core::sr25519::Pair;
|
||||||
crypto::AccountId32,
|
|
||||||
sr25519::Pair,
|
|
||||||
};
|
|
||||||
use std::sync::atomic::{
|
|
||||||
AtomicU32,
|
|
||||||
Ordering,
|
|
||||||
};
|
|
||||||
|
|
||||||
static STASH_NONCE: std::sync::atomic::AtomicU32 = AtomicU32::new(0);
|
|
||||||
|
|
||||||
struct TestContext {
|
struct TestContext {
|
||||||
client: Client<ContractsTemplateRuntime>,
|
node_process: TestNodeProcess<TestRuntime>,
|
||||||
signer: PairSigner<ContractsTemplateRuntime, Pair>,
|
signer: PairSigner<TestRuntime, Pair>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestContext {
|
impl TestContext {
|
||||||
async fn init() -> Self {
|
async fn init() -> Self {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
|
|
||||||
let client = ClientBuilder::<ContractsTemplateRuntime>::new()
|
let node_process = test_node_process().await;
|
||||||
.build()
|
let signer = PairSigner::new(AccountKeyring::Alice.pair());
|
||||||
.await
|
|
||||||
.expect("Error creating client");
|
|
||||||
let mut stash = PairSigner::new(AccountKeyring::Alice.pair());
|
|
||||||
let nonce = client
|
|
||||||
.account(&stash.account_id(), None)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.nonce;
|
|
||||||
let local_nonce = STASH_NONCE.fetch_add(1, Ordering::SeqCst);
|
|
||||||
|
|
||||||
stash.set_nonce(nonce + local_nonce);
|
TestContext {
|
||||||
|
node_process,
|
||||||
let signer = Self::generate_account(&client, &mut stash).await;
|
signer,
|
||||||
|
}
|
||||||
TestContext { client, signer }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// generate a new keypair for an account, and fund it so it can perform smart contract operations
|
async fn instantiate_with_code(
|
||||||
async fn generate_account(
|
|
||||||
client: &Client<ContractsTemplateRuntime>,
|
|
||||||
stash: &mut PairSigner<ContractsTemplateRuntime, Pair>,
|
|
||||||
) -> PairSigner<ContractsTemplateRuntime, Pair> {
|
|
||||||
use sp_core::Pair as _;
|
|
||||||
let new_account = Pair::generate().0;
|
|
||||||
let new_account_id: AccountId32 = new_account.public().into();
|
|
||||||
// fund the account
|
|
||||||
let endowment = 200_000_000_000_000;
|
|
||||||
let _ = client
|
|
||||||
.transfer_and_watch(stash, &new_account_id.into(), endowment)
|
|
||||||
.await
|
|
||||||
.expect("New account balance transfer failed");
|
|
||||||
stash.increment_nonce();
|
|
||||||
PairSigner::new(new_account)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn put_code(
|
|
||||||
&self,
|
&self,
|
||||||
) -> Result<CodeStoredEvent<ContractsTemplateRuntime>, Error> {
|
) -> Result<CodeStoredEvent<TestRuntime>, Error> {
|
||||||
const CONTRACT: &str = r#"
|
const CONTRACT: &str = r#"
|
||||||
(module
|
(module
|
||||||
(func (export "call"))
|
(func (export "call"))
|
||||||
@@ -206,28 +178,40 @@ mod tests {
|
|||||||
"#;
|
"#;
|
||||||
let code = wabt::wat2wasm(CONTRACT).expect("invalid wabt");
|
let code = wabt::wat2wasm(CONTRACT).expect("invalid wabt");
|
||||||
|
|
||||||
let result = self.client.put_code_and_watch(&self.signer, &code).await?;
|
let result = self
|
||||||
let code_stored = result.code_stored()?.ok_or_else(|| {
|
.client()
|
||||||
|
.instantiate_with_code_and_watch(
|
||||||
|
&self.signer,
|
||||||
|
100_000_000_000_000_000, // endowment
|
||||||
|
500_000_000_000, // gas_limit
|
||||||
|
&code,
|
||||||
|
&[], // data
|
||||||
|
&[], // salt
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let event = result.code_stored()?.ok_or_else(|| {
|
||||||
Error::Other("Failed to find a CodeStored event".into())
|
Error::Other("Failed to find a CodeStored event".into())
|
||||||
})?;
|
})?;
|
||||||
log::info!("Code hash: {:?}", code_stored.code_hash);
|
log::info!("Code hash: {:?}", event.code_hash);
|
||||||
Ok(code_stored)
|
Ok(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn instantiate(
|
async fn instantiate(
|
||||||
&self,
|
&self,
|
||||||
code_hash: &<ContractsTemplateRuntime as System>::Hash,
|
code_hash: &<TestRuntime as System>::Hash,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
) -> Result<InstantiatedEvent<ContractsTemplateRuntime>, Error> {
|
salt: &[u8],
|
||||||
|
) -> Result<InstantiatedEvent<TestRuntime>, Error> {
|
||||||
// call instantiate extrinsic
|
// call instantiate extrinsic
|
||||||
let result = self
|
let result = self
|
||||||
.client
|
.client()
|
||||||
.instantiate_and_watch(
|
.instantiate_and_watch(
|
||||||
&self.signer,
|
&self.signer,
|
||||||
100_000_000_000_000, // endowment
|
100_000_000_000_000_000, // endowment
|
||||||
500_000_000, // gas_limit
|
500_000_000_000, // gas_limit
|
||||||
code_hash,
|
code_hash,
|
||||||
data,
|
data,
|
||||||
|
salt,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -241,11 +225,11 @@ mod tests {
|
|||||||
|
|
||||||
async fn call(
|
async fn call(
|
||||||
&self,
|
&self,
|
||||||
contract: &<ContractsTemplateRuntime as System>::Address,
|
contract: &<TestRuntime as System>::Address,
|
||||||
input_data: &[u8],
|
input_data: &[u8],
|
||||||
) -> Result<ExtrinsicSuccess<ContractsTemplateRuntime>, Error> {
|
) -> Result<ExtrinsicSuccess<TestRuntime>, Error> {
|
||||||
let result = self
|
let result = self
|
||||||
.client
|
.client()
|
||||||
.call_and_watch(
|
.call_and_watch(
|
||||||
&self.signer,
|
&self.signer,
|
||||||
contract,
|
contract,
|
||||||
@@ -257,17 +241,21 @@ mod tests {
|
|||||||
log::info!("Call result: {:?}", result);
|
log::info!("Call result: {:?}", result);
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn client(&self) -> &Client<TestRuntime> {
|
||||||
|
self.node_process.client()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn tx_put_code() {
|
async fn tx_instantiate_with_code() {
|
||||||
let ctx = TestContext::init().await;
|
let ctx = TestContext::init().await;
|
||||||
let code_stored = ctx.put_code().await;
|
let code_stored = ctx.instantiate_with_code().await;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
code_stored.is_ok(),
|
code_stored.is_ok(),
|
||||||
format!(
|
format!(
|
||||||
"Error calling put_code and receiving CodeStored Event: {:?}",
|
"Error calling instantiate_with_code and receiving CodeStored Event: {:?}",
|
||||||
code_stored
|
code_stored
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -276,9 +264,9 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn tx_instantiate() {
|
async fn tx_instantiate() {
|
||||||
let ctx = TestContext::init().await;
|
let ctx = TestContext::init().await;
|
||||||
let code_stored = ctx.put_code().await.unwrap();
|
let code_stored = ctx.instantiate_with_code().await.unwrap();
|
||||||
|
|
||||||
let instantiated = ctx.instantiate(&code_stored.code_hash, &[]).await;
|
let instantiated = ctx.instantiate(&code_stored.code_hash, &[], &[1u8]).await;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
instantiated.is_ok(),
|
instantiated.is_ok(),
|
||||||
@@ -289,10 +277,10 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn tx_call() {
|
async fn tx_call() {
|
||||||
let ctx = TestContext::init().await;
|
let ctx = TestContext::init().await;
|
||||||
let code_stored = ctx.put_code().await.unwrap();
|
let code_stored = ctx.instantiate_with_code().await.unwrap();
|
||||||
|
|
||||||
let instantiated = ctx
|
let instantiated = ctx
|
||||||
.instantiate(&code_stored.code_hash.into(), &[])
|
.instantiate(&code_stored.code_hash.into(), &[], &[1u8])
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let executed = ctx.call(&instantiated.contract.into(), &[]).await;
|
let executed = ctx.call(&instantiated.contract.into(), &[]).await;
|
||||||
|
|||||||
+51
-38
@@ -200,9 +200,9 @@ pub struct NominateCall<T: Staking> {
|
|||||||
/// Take the origin account as a stash and lock up `value` of its balance.
|
/// Take the origin account as a stash and lock up `value` of its balance.
|
||||||
/// `controller` will be the account that controls it.
|
/// `controller` will be the account that controls it.
|
||||||
#[derive(Call, Encode, Debug)]
|
#[derive(Call, Encode, Debug)]
|
||||||
pub struct BondCall<T: Staking> {
|
pub struct BondCall<'a, T: Staking> {
|
||||||
/// Tٗhe controller account
|
/// Tٗhe controller account
|
||||||
pub contrller: T::AccountId,
|
pub controller: &'a T::Address,
|
||||||
/// Lock up `value` of its balance.
|
/// Lock up `value` of its balance.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub value: T::Balance,
|
pub value: T::Balance,
|
||||||
@@ -211,7 +211,6 @@ pub struct BondCall<T: Staking> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "integration-tests")]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -221,8 +220,10 @@ mod tests {
|
|||||||
Signer,
|
Signer,
|
||||||
},
|
},
|
||||||
frame::balances::*,
|
frame::balances::*,
|
||||||
runtimes::KusamaRuntime as RT,
|
tests::{
|
||||||
ClientBuilder,
|
test_node_process,
|
||||||
|
TestRuntime,
|
||||||
|
},
|
||||||
Error,
|
Error,
|
||||||
ExtrinsicSuccess,
|
ExtrinsicSuccess,
|
||||||
};
|
};
|
||||||
@@ -242,14 +243,15 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_validate_with_controller_account() -> Result<(), Error> {
|
async fn test_validate_with_controller_account() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let alice = PairSigner::<RT, _>::new(AccountKeyring::Alice.pair());
|
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
let announce_validator = client
|
let announce_validator = client
|
||||||
.validate_and_watch(&alice, ValidatorPrefs::default())
|
.validate_and_watch(&alice, ValidatorPrefs::default())
|
||||||
.await;
|
.await;
|
||||||
assert_matches!(announce_validator, Ok(ExtrinsicSuccess {block: _, extrinsic: _, events}) => {
|
assert_matches!(announce_validator, Ok(ExtrinsicSuccess {block: _, extrinsic: _, events}) => {
|
||||||
// TOOD: this is unsatisfying – can we do better?
|
// TOOD: this is unsatisfying – can we do better?
|
||||||
assert_eq!(events.len(), 3);
|
assert_eq!(events.len(), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -258,8 +260,10 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_validate_not_possible_for_stash_account() -> Result<(), Error> {
|
async fn test_validate_not_possible_for_stash_account() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let alice_stash = PairSigner::<RT, _>::new(get_from_seed("Alice//stash"));
|
let alice_stash =
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
PairSigner::<TestRuntime, _>::new(get_from_seed("Alice//stash"));
|
||||||
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
let announce_validator = client
|
let announce_validator = client
|
||||||
.validate_and_watch(&alice_stash, ValidatorPrefs::default())
|
.validate_and_watch(&alice_stash, ValidatorPrefs::default())
|
||||||
.await;
|
.await;
|
||||||
@@ -273,16 +277,17 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_nominate_with_controller_account() -> Result<(), Error> {
|
async fn test_nominate_with_controller_account() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let alice = PairSigner::<RT, _>::new(AccountKeyring::Alice.pair());
|
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
|
||||||
let bob = PairSigner::<RT, _>::new(AccountKeyring::Bob.pair());
|
let bob = PairSigner::<TestRuntime, _>::new(AccountKeyring::Bob.pair());
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
|
|
||||||
let nomination = client
|
let nomination = client
|
||||||
.nominate_and_watch(&alice, vec![bob.account_id().clone()])
|
.nominate_and_watch(&alice, vec![bob.account_id().clone().into()])
|
||||||
.await;
|
.await;
|
||||||
assert_matches!(nomination, Ok(ExtrinsicSuccess {block: _, extrinsic: _, events}) => {
|
assert_matches!(nomination, Ok(ExtrinsicSuccess {block: _, extrinsic: _, events}) => {
|
||||||
// TOOD: this is unsatisfying – can we do better?
|
// TOOD: this is unsatisfying – can we do better?
|
||||||
assert_eq!(events.len(), 3);
|
assert_eq!(events.len(), 2);
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -291,12 +296,13 @@ mod tests {
|
|||||||
async fn test_nominate_not_possible_for_stash_account() -> Result<(), Error> {
|
async fn test_nominate_not_possible_for_stash_account() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let alice_stash =
|
let alice_stash =
|
||||||
PairSigner::<RT, sr25519::Pair>::new(get_from_seed("Alice//stash"));
|
PairSigner::<TestRuntime, sr25519::Pair>::new(get_from_seed("Alice//stash"));
|
||||||
let bob = PairSigner::<RT, _>::new(AccountKeyring::Bob.pair());
|
let bob = PairSigner::<TestRuntime, _>::new(AccountKeyring::Bob.pair());
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
|
|
||||||
let nomination = client
|
let nomination = client
|
||||||
.nominate_and_watch(&alice_stash, vec![bob.account_id().clone()])
|
.nominate_and_watch(&alice_stash, vec![bob.account_id().clone().into()])
|
||||||
.await;
|
.await;
|
||||||
assert_matches!(nomination, Err(Error::Runtime(RuntimeError::Module(module_err))) => {
|
assert_matches!(nomination, Err(Error::Runtime(RuntimeError::Module(module_err))) => {
|
||||||
assert_eq!(module_err.module, "Staking");
|
assert_eq!(module_err.module, "Staking");
|
||||||
@@ -309,14 +315,16 @@ mod tests {
|
|||||||
async fn test_chill_works_for_controller_only() -> Result<(), Error> {
|
async fn test_chill_works_for_controller_only() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let alice_stash =
|
let alice_stash =
|
||||||
PairSigner::<RT, sr25519::Pair>::new(get_from_seed("Alice//stash"));
|
PairSigner::<TestRuntime, sr25519::Pair>::new(get_from_seed("Alice//stash"));
|
||||||
let bob_stash = PairSigner::<RT, sr25519::Pair>::new(get_from_seed("Bob//stash"));
|
let bob_stash =
|
||||||
let alice = PairSigner::<RT, _>::new(AccountKeyring::Alice.pair());
|
PairSigner::<TestRuntime, sr25519::Pair>::new(get_from_seed("Bob//stash"));
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
|
||||||
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
|
|
||||||
// this will fail the second time, which is why this is one test, not two
|
// this will fail the second time, which is why this is one test, not two
|
||||||
client
|
client
|
||||||
.nominate_and_watch(&alice, vec![bob_stash.account_id().clone()])
|
.nominate_and_watch(&alice, vec![bob_stash.account_id().clone().into()])
|
||||||
.await?;
|
.await?;
|
||||||
let store = LedgerStore {
|
let store = LedgerStore {
|
||||||
controller: alice.account_id().clone(),
|
controller: alice.account_id().clone(),
|
||||||
@@ -333,7 +341,7 @@ mod tests {
|
|||||||
let chill = client.chill_and_watch(&alice).await;
|
let chill = client.chill_and_watch(&alice).await;
|
||||||
assert_matches!(chill, Ok(ExtrinsicSuccess {block: _, extrinsic: _, events}) => {
|
assert_matches!(chill, Ok(ExtrinsicSuccess {block: _, extrinsic: _, events}) => {
|
||||||
// TOOD: this is unsatisfying – can we do better?
|
// TOOD: this is unsatisfying – can we do better?
|
||||||
assert_eq!(events.len(), 3);
|
assert_eq!(events.len(), 2);
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -341,14 +349,15 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_bond() -> Result<(), Error> {
|
async fn test_bond() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let alice = PairSigner::<RT, _>::new(AccountKeyring::Alice.pair());
|
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
|
||||||
let client = ClientBuilder::<RT>::new().build().await.unwrap();
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
|
|
||||||
let bond = client
|
let bond = client
|
||||||
.bond_and_watch(
|
.bond_and_watch(
|
||||||
&alice,
|
&alice,
|
||||||
AccountKeyring::Bob.to_account_id(),
|
&AccountKeyring::Bob.to_account_id().into(),
|
||||||
100_000_000_000,
|
100_000_000_000_000,
|
||||||
RewardDestination::Stash,
|
RewardDestination::Stash,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -361,7 +370,7 @@ mod tests {
|
|||||||
let bond_again = client
|
let bond_again = client
|
||||||
.bond_and_watch(
|
.bond_and_watch(
|
||||||
&alice,
|
&alice,
|
||||||
AccountKeyring::Bob.to_account_id(),
|
&AccountKeyring::Bob.to_account_id().into(),
|
||||||
100_000_000_000,
|
100_000_000_000,
|
||||||
RewardDestination::Stash,
|
RewardDestination::Stash,
|
||||||
)
|
)
|
||||||
@@ -378,7 +387,8 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_total_issuance_is_okay() -> Result<(), Error> {
|
async fn test_total_issuance_is_okay() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
let total_issuance = client.total_issuance(None).await?;
|
let total_issuance = client.total_issuance(None).await?;
|
||||||
assert!(total_issuance > 1u128 << 32);
|
assert!(total_issuance > 1u128 << 32);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -387,7 +397,8 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_history_depth_is_okay() -> Result<(), Error> {
|
async fn test_history_depth_is_okay() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
let history_depth = client.history_depth(None).await?;
|
let history_depth = client.history_depth(None).await?;
|
||||||
assert_eq!(history_depth, 84);
|
assert_eq!(history_depth, 84);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -396,7 +407,8 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_current_era_is_okay() -> Result<(), Error> {
|
async fn test_current_era_is_okay() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
let _current_era = client
|
let _current_era = client
|
||||||
.current_era(None)
|
.current_era(None)
|
||||||
.await?
|
.await?
|
||||||
@@ -407,16 +419,17 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_era_reward_points_is_okay() -> Result<(), Error> {
|
async fn test_era_reward_points_is_okay() -> Result<(), Error> {
|
||||||
env_logger::try_init().ok();
|
env_logger::try_init().ok();
|
||||||
let client = ClientBuilder::<RT>::new().build().await?;
|
let test_node_proc = test_node_process().await;
|
||||||
|
let client = test_node_proc.client();
|
||||||
let store = ErasRewardPointsStore {
|
let store = ErasRewardPointsStore {
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
index: 0,
|
index: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _current_era = client
|
let current_era_result = client.fetch(&store, None).await?;
|
||||||
.fetch(&store, None)
|
|
||||||
.await?
|
assert_matches!(current_era_result, Some(_));
|
||||||
.expect("current era always exists");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
mod node_proc;
|
mod node_proc;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use node_proc::TestNodeProcess;
|
pub use node_proc::TestNodeProcess;
|
||||||
use sp_core::storage::{
|
use sp_core::storage::{
|
||||||
well_known_keys,
|
well_known_keys,
|
||||||
StorageKey,
|
StorageKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user