Skip to content

Commit

Permalink
chore: setup sending balance
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Dec 10, 2024
1 parent 06cdc37 commit 07226ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions blueprint-test-utils/src/tangle/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ pub async fn request_service(
PaymentAsset::from(Asset::Custom(0)),
value,
);
let balance_call = api::storage().balances().account(user.account_id());
let balance = client
.storage()
.at_latest()
.await?
.fetch_or_default(&balance_call)
.await?;
println!("XXX | Balance: {:?}", balance);
let res = client
.tx()
.sign_and_submit_then_watch_default(&call, user)
Expand Down
26 changes: 25 additions & 1 deletion blueprint-test-utils/src/test_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ use blueprint_manager::executor::BlueprintManagerHandle;
use blueprint_manager::sdk::entry::SendFuture;
use cargo_tangle::deploy::Opts;
use gadget_sdk::clients::tangle::runtime::TangleClient;
use gadget_sdk::tangle_subxt::tangle_testnet_runtime::api;
use gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::PriceTargets;
use gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::services::calls::types::register::{Preferences, RegistrationArgs};
use subxt::ext::sp_runtime::traits::IdentifyAccount;
use libp2p::Multiaddr;
use log::debug;
use sp_core::crypto::Ss58AddressFormat;
use subxt::ext::sp_runtime::traits::Verify;
use subxt::ext::sp_runtime::MultiSignature;
use std::collections::HashSet;
use std::future::Future;
use std::net::IpAddr;
Expand All @@ -36,7 +40,7 @@ use url::Url;
use std::path::PathBuf;
use subxt::tx::Signer;
use gadget_sdk::keystore::KeystoreUriSanitizer;
use sp_core::Pair;
use sp_core::{sr25519, Pair, Public};
use tracing::Instrument;
use gadget_sdk::{error, info, warn};
use gadget_sdk::clients::tangle::services::{RpcServicesWithBlueprint, ServicesClient};
Expand All @@ -49,6 +53,11 @@ use tnt_core_bytecode::bytecode::MASTER_BLUEPRINT_SERVICE_MANAGER;
const LOCAL_BIND_ADDR: &str = "127.0.0.1";
pub const NAME_IDS: [&str; 5] = ["Alice", "Bob", "Charlie", "Dave", "Eve"];

/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> TPublic::Pair {
TPublic::Pair::from_string(&format!("//{seed}"), None).expect("static values are valid; qed")
}

/// - `N`: number of nodes
/// - `K`: Number of networks accessible per node (should be equal to the number of services in a given blueprint)
/// - `D`: Any data that you want to pass with NodeInput.
Expand Down Expand Up @@ -157,6 +166,21 @@ pub async fn new_test_ext_blueprint_manager<
opts.signer = Some(handle.sr25519_id().clone().into_inner());
}

// Give the accounts balances
let client = get_client(&opts.ws_rpc_url, &opts.http_rpc_url)
.await
.expect("Failed to create an account-based localhost client");

let alice = get_from_seed::<sr25519::Public>("Alice");
let transfer_call = api::tx()
.balances()
.transfer_allow_death(tg_addr.into(), 1_000_000_000_000_000_000_000_000);
let res = client
.tx()
.sign_and_submit_then_watch_default(&transfer_call, alice)
.await
.expect("Failed to transfer funds to Alice");

handles.push(handle);
}

Expand Down

0 comments on commit 07226ef

Please sign in to comment.