1#![doc(
18 html_logo_url = "https://use.ink/img/crate-docs/logo.png",
19 html_favicon_url = "https://use.ink/crate-docs/favicon.png"
20)]
21
22mod backend;
23mod backend_calls;
24mod builders;
25mod client_utils;
26mod contract_build;
27mod contract_results;
28mod error;
29pub mod events;
30mod node_proc;
31#[cfg(feature = "sandbox")]
32mod sandbox_client;
33mod subxt_client;
34mod xts;
35
36pub use crate::contract_build::build_root_and_contract_dependencies;
37pub use backend::{
38 BuilderClient,
39 ChainBackend,
40 ContractsBackend,
41 E2EBackend,
42};
43pub use backend_calls::{
44 CallBuilder,
45 InstantiateBuilder,
46};
47pub use client_utils::ContractsRegistry;
48pub use contract_results::{
49 CallDryRunResult,
50 CallResult,
51 InstantiateDryRunResult,
52 InstantiationResult,
53 UploadResult,
54};
55pub use ink_e2e_macro::test;
56pub use node_proc::{
57 TestNodeProcess,
58 TestNodeProcessBuilder,
59};
60#[cfg(feature = "sandbox")]
61pub use sandbox_client::{
62 preset,
63 Client as SandboxClient,
64};
65pub use sp_keyring::Sr25519Keyring;
66pub use subxt::{
67 self,
68 backend::rpc::RpcClient,
69};
70pub use subxt_client::{
71 CallBuilderFinal,
72 Client,
73 Error,
74};
75pub use subxt_signer::{
76 self,
77 sr25519::{
78 self,
79 dev::*,
80 Keypair,
81 },
82};
83pub use tokio;
84pub use tracing_subscriber;
85
86#[cfg(feature = "sandbox")]
87pub use ink_sandbox::DefaultSandbox;
88
89use ink::codegen::ContractCallBuilder;
90use ink_env::{
91 call::FromAddr,
92 ContractEnv,
93 Environment,
94};
95use ink_primitives::{
96 DepositLimit,
97 H160,
98 H256,
99};
100pub use sp_weights::Weight;
101use std::{
102 cell::RefCell,
103 sync::Once,
104};
105use xts::ReviveApi;
106
107use ink_primitives::types::AccountIdMapper;
108pub use subxt::PolkadotConfig;
109
110pub static INIT: Once = Once::new();
112
113thread_local! {
116 pub static LOG_PREFIX: RefCell<String> = RefCell::new(String::from("no prefix set"));
121}
122
123pub fn log_prefix() -> String {
125 LOG_PREFIX.with(|log_prefix| log_prefix.borrow().clone())
126}
127
128pub fn log_info(msg: &str) {
130 tracing::info!("[{}] {}", log_prefix(), msg);
131}
132
133pub fn log_error(msg: &str) {
135 tracing::error!("[{}] {}", log_prefix(), msg);
136}
137
138pub fn account_id(account: Sr25519Keyring) -> ink_primitives::AccountId {
140 ink_primitives::AccountId::try_from(account.to_account_id().as_ref())
141 .expect("account keyring has a valid account id")
142}
143
144pub fn address<E: Environment>(account: Sr25519Keyring) -> H160 {
151 AccountIdMapper::to_address(account.to_account_id().as_ref())
152}
153
154pub fn create_call_builder<Contract>(
156 acc_id: H160,
157) -> <Contract as ContractCallBuilder>::Type
158where
159 <Contract as ContractEnv>::Env: Environment,
160 Contract: ContractCallBuilder,
161 Contract: ContractEnv,
162 Contract::Type: FromAddr,
163{
164 <<Contract as ContractCallBuilder>::Type as FromAddr>::from_addr(acc_id)
165}
166
167fn balance_to_deposit_limit<E: Environment>(
168 b: <E as Environment>::Balance,
169) -> DepositLimit<<E as Environment>::Balance> {
170 DepositLimit::Balance(b)
171}
172
173fn deposit_limit_to_balance<E: Environment>(
174 l: DepositLimit<<E as Environment>::Balance>,
175) -> <E as Environment>::Balance {
176 match l {
177 DepositLimit::Balance(l) => l,
178 DepositLimit::Unchecked => panic!("`Unchecked` is not supported"),
180 }
181}