From 43aa3e376973e98989c1d3ca87523690b5c48384 Mon Sep 17 00:00:00 2001 From: Hemanth Kumar <96766939+hemz10@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:51:32 +0530 Subject: [PATCH] test: update script to use sdk to send message from para to relay in local net (#174) * test: test script for sending tokens from para to relaychain * refactor: correct typos in relay-para script --- testdata/e2e/para_relay.js | 43 ++++++++++++++++++++++++++++++++++++++ testdata/e2e/relay_para.js | 18 ++++++++-------- 2 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 testdata/e2e/para_relay.js diff --git a/testdata/e2e/para_relay.js b/testdata/e2e/para_relay.js new file mode 100644 index 0000000..fc41f1c --- /dev/null +++ b/testdata/e2e/para_relay.js @@ -0,0 +1,43 @@ +import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; +import { Builder } from "@paraspell/sdk"; + +async function testRelayToPara() { + console.log("*".repeat(100)); + console.log("Demo on Sending tokens from Parachain to Relaychain. \n"); + console.log("*".repeat(100), "\n"); + + console.log("Establishing connection to Parachain...."); + let ParaWsProvider = new WsProvider("ws://127.0.0.1:32886"); + const API = await ApiPromise.create({ + provider: ParaWsProvider, + noInitWarn: true, + }); + + const relayBlock = await API.rpc.chain.getBlock(); + console.log( + "Latest Parachain Block Height: ", + relayBlock.block.header.number.toHuman(), + "\n" + ); + + // You can use ss58Format: ? as an argument when initalizing keyring to get exact alice address as mentioned for that particular parachain + const keyring = new Keyring({ type: "sr25519" }); + const alice = keyring.addFromUri("//Alice"); + console.log("Alice Address : ", alice.address, "\n"); + + const call = Builder(API) + .from('Karura') + .amount(5000000000000) // Token amount + .address("5CAqjCqo2CfzrbhuuqdGrBuEFrsKycxGd3KGaNn1qN89eFFG") // AccountId32 or AccountKey20 address + .build() + + const hash = await call.signAndSend(alice); + console.log( + "Transaction Successfully submitted. \nHash: ", + (hash.toHex()) + ); + + API.disconnect(); +} + +testRelayToPara(); diff --git a/testdata/e2e/relay_para.js b/testdata/e2e/relay_para.js index 36f20c1..5e58fd9 100644 --- a/testdata/e2e/relay_para.js +++ b/testdata/e2e/relay_para.js @@ -3,22 +3,22 @@ import { Builder } from "@paraspell/sdk"; async function testRelayToPara() { console.log("*".repeat(100)); - console.log("Demo on Sending tokens from Relay Chain to Para chain. \n"); + console.log("Demo on Sending tokens from Relaychain to Parachain. \n"); console.log("*".repeat(100), "\n"); - console.log("Establishing connection to Relay Chain...."); - let relayWsProvider = new WsProvider("ws://127.0.0.1:34322"); + console.log("Establishing connection to Relaychain...."); + let relayWsProvider = new WsProvider("ws://127.0.0.1:32883"); const relayaAPI = await ApiPromise.create({ provider: relayWsProvider }); const relayBlock = await relayaAPI.rpc.chain.getBlock(); console.log( - "Latest Relay Chain Block Height: ", + "Latest Relaychain Block Height: ", relayBlock.block.header.number.toHuman(), "\n" ); - console.log("Establishing connection to Para Chain...."); - let paraWsProvider = new WsProvider("ws://127.0.0.1:34328"); + console.log("Establishing connection to Parachain...."); + let paraWsProvider = new WsProvider("ws://127.0.0.1:32886"); const paraAPI = await ApiPromise.create({ provider: paraWsProvider, noInitWarn: true, @@ -46,12 +46,12 @@ async function testRelayToPara() { ); console.log( - "Building an XCM call to transfer asset from relay chain to Para chain...\n" + "Building an XCM call to transfer asset from Relaychain to Parachain...\n" ); const call = Builder(relayaAPI) - .to("BifrostPolkadot", 2000) // Destination Parachain and Para ID + .to("Karura", 2000) // Destination Parachain and Para ID .amount(10000000000000) // Token amount - .address("gXCcrjjFX3RPyhHYgwZDmw8oe4JFpd5anko3nTY8VrmnJpe") // AccountId32 or AccountKey20 address + .address("oQQwUS5xJwHYbx97jiU1YrnHN1L7PYaD4Uof8un6Hua5EqV") // AccountId32 or AccountKey20 address .build(); // Function called to build call console.log("Getting Alice address to sign and send the transaction.. \n");