Skip to content
Snippets Groups Projects
Select Git revision
  • aae13b13691b69fa03f8f1353f64472410512ca3
  • master default protected
  • elois-ci-refactor protected
  • gtest
  • hugo/gtest
  • json-output
  • nostr
  • 48-error-base-58-requirement-is-violated
  • no-rename
  • hugo/tx-comments
  • poka/dev
  • hugo/dev
  • tuxmain/mail
  • test-gtest
  • 0.4.3-gtest-RC1
  • 0.4.3-RC2
  • 0.4.3-RC1
  • 0.4.2
  • 0.4.1
  • 0.4.0
  • 0.3.0
  • 0.2.17
  • 0.2.16
  • 0.2.15
  • 0.2.14
  • 0.2.13
  • 0.2.12
  • 0.2.10
  • 0.2.9
  • 0.2.8
  • 0.2.7
  • 0.2.6
  • 0.2.5
33 results

net_test.rs

Blame
  • net_test.rs 2.44 KiB
    use crate::*;
    
    use sp_core::DeriveJunction;
    use subxt::ext::sp_runtime::MultiAddress;
    
    pub async fn repart(
    	data: &Data,
    	target: u32,
    	actual_repart: Option<u32>,
    ) -> anyhow::Result<()> {
    	let mut pairs = Vec::new();
    	for i in actual_repart.unwrap_or_default()..target {
    		let pair_i = data.keypair()
    			.derive(std::iter::once(DeriveJunction::hard::<u32>(i)), None)
    			.map_err(|_| anyhow!("Fail to derive //{}", i))?
    			.0;
    		pairs.push((i, pair_i));
    	}
    
    	for (i, pair_i) in &pairs {
    		/*let _ = api
    			.tx()
    			.balances()
    			.transfer(MultiAddress::Id(pair_i.public().into()), 501)?
    			.sign_and_submit_then_watch(&signer, BaseExtrinsicParamsBuilder::new())
    			.await?
    			.wait_for_in_block()
    			.await?;
    		signer.increment_nonce();*/
    
    		if let Some(pair_i_account) = data.client()
    			.storage()
    			.fetch(
    				&runtime::storage().system().account(&pair_i.public().into()),
    				None,
    			)
    			.await?
    		{
    			log::info!("account //{} balance: {}", i, pair_i_account.data.free);
    		}
    	}
    
    	Ok(())
    }
    
    pub async fn spam_roll(data: &Data, actual_repart: usize) -> anyhow::Result<()> {
    	let client = data.client();
    	let mut nonce = 0;
    	let mut pairs = Vec::<(PairSigner<Runtime, Pair>, AccountId)>::with_capacity(actual_repart);
    	for i in 0..actual_repart {
    		let pair_i = data.keypair()
    			.derive(std::iter::once(DeriveJunction::hard::<u32>(i as u32)), None)
    			.map_err(|_| anyhow!("Fail to derive //{}", i))?
    			.0;
    		let account_id_i = pair_i.public().into();
    		pairs.push((PairSigner::new(pair_i), account_id_i));
    	}
    
    	loop {
    		let mut watchers = Vec::with_capacity(actual_repart);
    		for i in 0..(actual_repart - 1) {
    			let dest: AccountId = pairs[i + 1].1.clone();
    			let watcher = client
    				.tx()
    				.create_signed_with_nonce(
    					&runtime::tx().balances().transfer(MultiAddress::Id(dest), 1),
    					&pairs[i].0,
    					nonce,
    					BaseExtrinsicParamsBuilder::new(),
    				)?
    				.submit_and_watch()
    				.await?;
    			nonce += 1;
    			log::info!("send 1 cent from //{} to //{}", i, i + 1);
    			watchers.push(watcher);
    		}
    		let dest: AccountId = pairs[0].1.clone();
    		let watcher = client
    			.tx()
    			.sign_and_submit_then_watch(
    				&runtime::tx().balances().transfer(MultiAddress::Id(dest), 1),
    				&pairs[actual_repart - 1].0,
    				BaseExtrinsicParamsBuilder::new(),
    			)
    			.await?;
    		nonce += 1;
    		log::info!("send 1 cent from //{} to //0", actual_repart - 1);
    		watchers.push(watcher);
    
    		// Wait all transactions
    		for watcher in watchers {
    			watcher.wait_for_in_block().await?;
    		}
    	}
    }