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;
31mod subxt_client;
32mod xts;
33
34pub use crate::contract_build::build_root_and_contract_dependencies;
35pub use backend::{
36 BuilderClient,
37 ChainBackend,
38 ContractsBackend,
39 E2EBackend,
40};
41pub use backend_calls::{
42 CallBuilder,
43 InstantiateBuilder,
44};
45pub use builders::{
46 CreateBuilderPartial,
47 constructor_exec_input,
48};
49pub use client_utils::{
50 ContractsRegistry,
51 code_hash,
52 salt,
53};
54pub use contract_results::{
55 BareInstantiationResult,
56 CallDryRunResult,
57 CallResult,
58 ContractExecResultFor,
59 ContractResult,
60 InstantiateDryRunResult,
61 InstantiationResult,
62 UploadResult,
63};
64pub use ink_e2e_macro::test;
65pub use ink_revive_types::evm::CallTrace;
66pub use node_proc::{
67 TestNodeProcess,
68 TestNodeProcessBuilder,
69};
70pub use sp_keyring::Sr25519Keyring;
71pub use subxt::{
72 self,
73 backend::rpc::RpcClient,
74};
75pub use subxt_client::{
76 CallBuilderFinal,
77 Client,
78 Error,
79};
80pub use subxt_signer::{
81 self,
82 sr25519::{
83 self,
84 Keypair,
85 dev::*,
86 },
87};
88pub use tokio;
89pub use tracing;
90pub use tracing_subscriber;
91
92use ink::codegen::ContractCallBuilder;
93use ink_env::{
94 ContractEnv,
95 Environment,
96 call::FromAddr,
97};
98use ink_primitives::{
99 Address,
100 DepositLimit,
101 H256,
102 types::AccountIdMapper,
103};
104pub use sp_weights::Weight;
105use std::{
106 cell::RefCell,
107 sync::Once,
108};
109use xts::ReviveApi;
110
111pub use subxt::PolkadotConfig;
112
113pub static INIT: Once = Once::new();
115
116thread_local! {
119 pub static LOG_PREFIX: RefCell<String> = RefCell::new(String::from("no prefix set"));
124}
125
126pub fn log_prefix() -> String {
128 LOG_PREFIX.with(|log_prefix| log_prefix.borrow().clone())
129}
130
131pub fn log_info(msg: &str) {
133 tracing::info!("[{}] {}", log_prefix(), msg);
134}
135
136pub fn log_error(msg: &str) {
138 tracing::error!("[{}] {}", log_prefix(), msg);
139}
140
141pub fn account_id(account: Sr25519Keyring) -> ink_primitives::AccountId {
143 ink_primitives::AccountId::try_from(account.to_account_id().as_ref())
144 .expect("account keyring has a valid account id")
145}
146
147pub fn address<E: Environment>(account: Sr25519Keyring) -> Address {
154 AccountIdMapper::to_address(account.to_account_id().as_ref())
155}
156
157pub fn address_from_account_id<AccountId: AsRef<[u8]>>(account_id: AccountId) -> Address {
164 AccountIdMapper::to_address(account_id.as_ref())
165}
166
167pub fn address_from_keypair<AccountId: From<[u8; 32]> + AsRef<[u8]>>(
174 keypair: &Keypair,
175) -> Address {
176 let account_id: AccountId = keypair_to_account(keypair);
177 address_from_account_id(account_id)
178}
179
180pub fn keypair_to_account<AccountId: From<[u8; 32]>>(keypair: &Keypair) -> AccountId {
182 AccountId::from(keypair.public_key().0)
183}
184
185pub fn create_call_builder<Contract>(
187 acc_id: Address,
188) -> <Contract as ContractCallBuilder>::Type<ink::env::DefaultAbi>
189where
190 <Contract as ContractEnv>::Env: Environment,
191 Contract: ContractCallBuilder + ContractEnv,
192 <Contract as ContractCallBuilder>::Type<ink::env::DefaultAbi>: FromAddr,
193{
194 <<Contract as ContractCallBuilder>::Type<ink::env::DefaultAbi> as FromAddr>::from_addr(
195 acc_id,
196 )
197}
198
199pub fn create_call_builder_abi<Contract, Abi>(
201 acc_id: Address,
202) -> <Contract as ContractCallBuilder>::Type<Abi>
203where
204 <Contract as ContractEnv>::Env: Environment,
205 Contract: ContractCallBuilder + ContractEnv,
206 <Contract as ContractCallBuilder>::Type<Abi>: FromAddr,
207{
208 <<Contract as ContractCallBuilder>::Type<Abi> as FromAddr>::from_addr(acc_id)
209}
210
211fn balance_to_deposit_limit_dry_run<E: Environment>(
216 b: Option<<E as Environment>::Balance>,
217) -> DepositLimit<<E as Environment>::Balance> {
218 match b {
219 Some(v) => DepositLimit::Balance(v),
220 None => DepositLimit::UnsafeOnlyForDryRun,
221 }
222}
223
224fn balance_to_deposit_limit<E: Environment>(
230 limit: Option<<E as Environment>::Balance>,
231) -> DepositLimit<<E as Environment>::Balance> {
232 match limit {
233 Some(val) => DepositLimit::Balance(val),
234 None => panic!("Deposit limit must be specified for on-chain submissions."),
235 }
236}
237
238fn deposit_limit_to_balance<E: Environment>(
243 limit: DepositLimit<<E as Environment>::Balance>,
244) -> <E as Environment>::Balance {
245 match limit {
246 DepositLimit::Balance(val) => val,
247 DepositLimit::UnsafeOnlyForDryRun => {
248 panic!("Unrestricted deposit limit not allowed for balance conversion!")
249 }
250 }
251}