-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use serde_json::json; | ||
|
||
use futures::stream::StreamExt; | ||
use zombienet_sdk::{NetworkConfigBuilder, NetworkConfigExt}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
tracing_subscriber::fmt::init(); | ||
let network = NetworkConfigBuilder::new() | ||
.with_relaychain(|r| { | ||
r.with_chain("rococo-local") | ||
.with_default_command("polkadot") | ||
.with_node(|node| node.with_name("alice")) | ||
.with_node(|node| node.with_name("bob")) | ||
}) | ||
.with_parachain(|p| { | ||
p.with_id(100) | ||
.cumulus_based(true) | ||
.with_collator(|n| n.with_name("collator").with_command("polkadot-parachain")) | ||
}) | ||
.build() | ||
.unwrap() | ||
.spawn_native() | ||
.await?; | ||
|
||
println!("🚀🚀🚀🚀 network deployed"); | ||
|
||
let alice = network.get_node("alice")?; | ||
let client = alice.client::<subxt::PolkadotConfig>().await?; | ||
|
||
// wait 2 blocks | ||
let mut blocks = client.blocks().subscribe_finalized().await?.take(2); | ||
|
||
while let Some(block) = blocks.next().await { | ||
println!("Block #{}", block?.header().number); | ||
} | ||
|
||
// run pjs with code | ||
let query_paras = r#" | ||
const parachains: number[] = (await api.query.paras.parachains()) || []; | ||
return parachains.toJSON() | ||
"#; | ||
|
||
let paras = alice.pjs(query_paras, vec![]).await??; | ||
|
||
println!("parachains registered: {:?}", paras); | ||
|
||
// run pjs with file | ||
let _ = alice.pjs_file("./examples/pjs_transfer.js", vec![json!("//Alice")]).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const seed = arguments[0]; | ||
|
||
await utilCrypto.cryptoWaitReady(); | ||
const k = new keyring.Keyring({ type: "sr25519" }); | ||
const signer = k.addFromUri(seed); | ||
|
||
// Make a transfer from Alice to Bob and listen to system events. | ||
// You need to be connected to a development chain for this example to work. | ||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; | ||
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'; | ||
|
||
// Get a random number between 1 and 100000 | ||
const randomAmount = Math.floor((Math.random() * 100000) + 1); | ||
|
||
// Create a extrinsic, transferring randomAmount units to Bob. | ||
const transferAllowDeath = api.tx.balances.transferAllowDeath(BOB, randomAmount); | ||
|
||
return new Promise(async (resolve, _reject) => { | ||
// Sign and Send the transaction | ||
const unsub = await transferAllowDeath.signAndSend(signer, ({ events = [], status }) => { | ||
if (status.isInBlock) { | ||
console.log('Successful transfer of ' + randomAmount + ' with hash ' + status.asInBlock.toHex()); | ||
return resolve(); | ||
} else { | ||
console.log('Status of transfer: ' + status.type); | ||
} | ||
|
||
events.forEach(({ phase, event: { data, method, section } }) => { | ||
console.log(phase.toString() + ' : ' + section + '.' + method + ' ' + data.toString()); | ||
}); | ||
}); | ||
}); |