generated from kurtosis-tech/package-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add para to relay e2e script * test: add relay to para e2e script * test: add package.json
- Loading branch information
Showing
3 changed files
with
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "e2e", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@paraspell/sdk": "^3.0.11", | ||
"@polkadot/api": "^10.11.2", | ||
"@polkadot/api-base": "^10.11.2", | ||
"@polkadot/apps-config": "^0.133.1", | ||
"@polkadot/types": "^10.11.2", | ||
"@polkadot/util": "^12.6.2" | ||
} | ||
} |
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,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(); |
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,83 @@ | ||
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 Relaychain to Parachain. \n"); | ||
console.log("*".repeat(100), "\n"); | ||
|
||
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 Relaychain Block Height: ", | ||
relayBlock.block.header.number.toHuman(), | ||
"\n" | ||
); | ||
|
||
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, | ||
}); | ||
|
||
const paraBlock = await paraAPI.rpc.chain.getBlock(); | ||
console.log( | ||
"Latest Para Chain Block Height: ", | ||
paraBlock.block.header.number.toHuman(), | ||
"\n" | ||
); | ||
const accountAddress = "gXCcrjjFX3RPyhHYgwZDmw8oe4JFpd5anko3nTY8VrmnJpe"; | ||
console.log( | ||
"Destination Para Chain Account Address : ", | ||
accountAddress, | ||
"\n" | ||
); | ||
|
||
const initialBal = await paraAPI.query.tokens.accounts(accountAddress, { | ||
token: "KSM", | ||
}); | ||
console.log( | ||
"Initial KSM Balance on Destination chain : ", | ||
initialBal.free.toHuman() | ||
); | ||
|
||
console.log( | ||
"Building an XCM call to transfer asset from Relaychain to Parachain...\n" | ||
); | ||
const call = Builder(relayaAPI) | ||
.to("Karura", 2000) // Destination Parachain and Para ID | ||
.amount(10000000000000) // Token amount | ||
.address("oQQwUS5xJwHYbx97jiU1YrnHN1L7PYaD4Uof8un6Hua5EqV") // AccountId32 or AccountKey20 address | ||
.build(); // Function called to build call | ||
|
||
console.log("Getting Alice address to sign and send the transaction.. \n"); | ||
const keyring = new Keyring({ type: "sr25519" }); | ||
const alice = keyring.addFromUri("//Alice"); | ||
console.log("Alice Address : ", alice.address, "\n"); | ||
|
||
const hash = await call.signAndSend(alice); | ||
console.log( | ||
"Transaction Successfully submitted. \nHash: ", | ||
JSON.stringify(hash) | ||
); | ||
relayaAPI.disconnect(); | ||
|
||
// TODO: Listen for events and then check final Balance | ||
await new Promise((f) => setTimeout(f, 25000)); | ||
|
||
const finalBal = await paraAPI.query.tokens.accounts(accountAddress, { | ||
token: "KSM", | ||
}); | ||
console.log( | ||
"KSM Balance on Destination chain after transfer: ", | ||
finalBal.free.toHuman() | ||
); | ||
|
||
paraAPI.disconnect(); | ||
} | ||
|
||
testRelayToPara(); |