1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
// Copyright 2018-2022 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Module for the logic behind ink!'s End-to-End testing framework.
#![doc(
html_logo_url = "https://use.ink/img/crate-docs/logo.png",
html_favicon_url = "https://use.ink/crate-docs/favicon.png"
)]
mod builders;
mod client;
mod node_proc;
mod xts;
pub use builders::{
build_message,
MessageBuilder,
};
pub use client::{
CallDryRunResult,
CallResult,
Client,
Error,
InstantiationResult,
UploadResult,
};
pub use env_logger;
pub use ink_e2e_macro::test;
pub use node_proc::{
TestNodeProcess,
TestNodeProcessBuilder,
};
pub use sp_core::H256;
pub use sp_keyring::AccountKeyring;
pub use subxt;
pub use subxt_signer::sr25519::{
self,
dev::*,
Keypair,
};
pub use tokio;
use pallet_contracts_primitives::{
CodeUploadResult,
ContractExecResult,
ContractInstantiateResult,
};
use std::{
cell::RefCell,
sync::Once,
};
use xts::ContractsApi;
pub use subxt::PolkadotConfig;
/// We use this to only initialize `env_logger` once.
pub static INIT: Once = Once::new();
// We save the name of the currently executing test here as a mean
// of prefixing log entries to make it easier pinning them to tests.
thread_local! {
/// This prefix will be used for log output. It is set by each
/// `#[ink_e2e::test]` with the function name as String.
/// This way it is possible to distinguish the lines in stdout
/// and stderr, to still know which line belongs to which test.
pub static LOG_PREFIX: RefCell<String> = RefCell::new(String::from("no prefix set"));
}
/// Returns the name of the test which is currently executed.
pub fn log_prefix() -> String {
LOG_PREFIX.with(|log_prefix| log_prefix.borrow().clone())
}
/// Writes `msg` to stdout.
pub fn log_info(msg: &str) {
log::info!("[{}] {}", log_prefix(), msg);
}
/// Writes `msg` to stderr.
pub fn log_error(msg: &str) {
log::error!("[{}] {}", log_prefix(), msg);
}
/// Get an ink! [`ink_primitives::AccountId`] for a given keyring account.
pub fn account_id(account: AccountKeyring) -> ink_primitives::AccountId {
ink_primitives::AccountId::try_from(account.to_account_id().as_ref())
.expect("account keyring has a valid account id")
}
/// Builds a contract and imports its scaffolded structure as a module.
#[macro_export]
macro_rules! build {
($($arg:tt)*) => (
ink_e2e::smart_bench_macro::contract!($($arg)*)
);
}