Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 55 additions & 38 deletions tools/moonbeam-xcmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const DEFAULT_GENESIS_BALANCE = 2n ** 80n;
const DEFAULT_GENESIS_STAKING = 1_000n * GLMR;
const GENESIS_ACCOUNT_BALANCE = DEFAULT_GENESIS_BALANCE - DEFAULT_GENESIS_STAKING;

interface HrmpChannelId {
sender: number;
recipient: number;
}

function assert(condition: boolean, msg: string) {
if (!condition) throw new Error(msg);
}
Expand Down Expand Up @@ -79,49 +84,57 @@ async function test() {
"wrong balance for relayAlice, expected: 1000000000000000000, returned: " +
Number(relayAlice.data.free)
);
console.log("Sanity Checks Passed for Relay Chain and Both Parachains");
console.log("++ Sanity Checks Passed for Relay Chain and Both Parachains");
// Open channel using relay sudo as caller
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");
const sender: number = 200;
const recipient: number = 201;
const unsub = await relayApi.tx.sudo
.sudo(relayApi.tx.parasSudoWrapper.sudoEstablishHrmpChannel(sender, recipient, 8, 1024))
.signAndSend(alice, {}, (result) => {
console.log(`Current status is ${result.status}`);
if (result.status.isInBlock) {
console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
} else if (result.status.isFinalized) {
console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`);
unsub();
}
});
await new Promise<void>(async (resolve) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@4meta5 the promise here garabties that the thread only continues after the tx is finalized

const unsub = await relayApi.tx.sudo
.sudo(relayApi.tx.parasSudoWrapper.sudoEstablishHrmpChannel(sender, recipient, 8, 1024))
.signAndSend(alice, {}, ({ events = [], status }) => {
console.log(`Current status is ${status}`);
if (status.isInBlock) {
console.log(`Transaction included at blockHash ${status.asInBlock}`);
} else if (status.isFinalized) {
console.log(`Transaction finalized at blockHash ${status.asFinalized}`);
// Loop through Vec<EventRecord> to display all events
events.forEach(({ phase, event: { data, method, section } }) => {
console.log(`\t' ${phase}: ${section}.${method}:: ${data}`);
});
unsub();
resolve();
}
});
});
console.log("api call resolved");
await wait(60000);
// (1) TODO: check that the channel is actually open by querying relay chain storage for
// `hrmp` pallet
// const channelID = HrmpChannelId { sender, recipient };
// const expectedChannel = await relayApi.query.hrmp.hrmpChannels(channelID);
// assert(
// expectedChannel.isSome(),
// "Channel does not exist but we expected it to exist"
// );
const channelID: HrmpChannelId = { sender, recipient };
// @ts-ignore
const expectedChannel = await relayApi.query.hrmp.hrmpChannels(channelID);
// const expectedChannel = await relayApi.query.hrmp.hrmpChannels(sender, recipient);
console.log("expectedchannel", expectedChannel, expectedChannel.toHuman());

assert(expectedChannel !== undefined, "Channel does not exist but we expected it to exist");
// (2) TODO: check that channel deposits are reserved from sender and recipient
// HOW LONG TO WAIT UNTIL QUEUED DOWNWARD MESSAGES ARE RECEIVED BY PARARCHAIN
await wait(50000);
// await wait(50);
// (3) TODO: check that the downward message Xcm::HrmpNewChannelOpenRequest
// { sender, max_msg_size, max_capacity }
// was sent to the recipient parachain
// const recipientChannels = moonbeam201.query.channels.recipientChannels();
// assert(
// senderChannels[0] === recipient,
// "Sender channel with recipient ID not yet opened on sender chain"
// );
const recipientChannels = await moonbeam201.query.channels.recipientChannels();
console.log("recipientChannels", recipientChannels, recipientChannels.toHuman());
// assert(
// recipientChannels[0] === sender,
// "Recipient channel with sender ID not yet opened on recipient chain"
// );
// (4) TODO: check that the downward message Xcm::HrmpChannelAccepted { recipient }
// was sent to the sender parachain
// const senderChannels = moonbeam200.query.channels.senderChannels();
const senderChannels = await moonbeam200.query.channels.senderChannels();
console.log("senderChannels", senderChannels);
// assert(
// senderChannels[0] === recipient,
// "Sender channel with recipient ID not yet opened on sender chain"
Expand All @@ -130,22 +143,26 @@ async function test() {
// transfer_native_to_account_key_20_parachain
const senderKeyring = new Keyring({ type: "ethereum" });
const gerald = await senderKeyring.addFromUri(GERALD_PRIVKEY, null, "ethereum");
const unsub2 = await moonbeam200.tx.xtransfer
.transferNative(recipient, GERALD, 100000)
.signAndSend(gerald, ({ events = [], status }) => {
console.log(`Current status is ${status.type}`);
await new Promise<void>(async (resolve) => {
const unsub2 = await moonbeam200.tx.xtransfer
.transferNative(recipient, GERALD, 100000)
.signAndSend(gerald, ({ events = [], status }) => {
console.log(`Current status is ${status.type}`);

if (status.isFinalized) {
console.log(`Transaction finalized at blockHash ${status.asFinalized}`);
if (status.isFinalized) {
console.log(`Transaction finalized at blockHash ${status.asFinalized}`);

// Loopcod through Vec<EventRecord> to display all events
events.forEach(({ phase, event: { data, method, section } }) => {
console.log(`\t' ${phase}: ${section}.${method}:: ${data}`);
});
// Loopcod through Vec<EventRecord> to display all events
events.forEach(({ phase, event: { data, method, section } }) => {
console.log(`\t' ${phase}: ${section}.${method}:: ${data}`);
});

unsub2();
}
});
unsub2();
resolve();
}
});
});
await wait(60000);
// check to see if message is received on the recipient chain
// check to see if account balance changes on sender chain
// check to see if account balance changes on recipient chain
Expand Down
2 changes: 1 addition & 1 deletion tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "moonbeam-tools",
"version": "0.0.1",
"dependencies": {
"@polkadot/api": "^4.0.3",
"@polkadot/api": "^4.2.1",
"@polkadot/util-crypto": "^6.0.5",
"bip39": "^3.0.3",
"eth-block-tracker": "^4.4.3",
Expand Down
112 changes: 56 additions & 56 deletions tools/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
babel-plugin-polyfill-regenerator "^0.1.2"
semver "^6.3.0"

"@babel/runtime@^7.13.7", "@babel/runtime@^7.13.8", "@babel/runtime@^7.13.9", "@babel/runtime@^7.5.5", "@babel/runtime@^7.9.2":
"@babel/runtime@^7.13.10", "@babel/runtime@^7.13.7", "@babel/runtime@^7.13.8", "@babel/runtime@^7.13.9", "@babel/runtime@^7.5.5", "@babel/runtime@^7.9.2":
version "7.13.10"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d"
integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==
Expand Down Expand Up @@ -372,15 +372,15 @@
"@polkadot/x-rxjs" "^5.9.2"
bn.js "^4.11.9"

"@polkadot/api-derive@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-4.0.3.tgz#542d871d84c64f927565d655eabce0ec2b917a4a"
integrity sha512-ADHrIoYumHJBQuIdtDEX6LPiJVZmLGBlFvlkRGYsKL7qJzRZtkzfuNgd8i3cZVDKk9mlcpldmj1DTiN3KBjH0Q==
"@polkadot/api-derive@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-4.2.1.tgz#848a2a9ef947f08660af2571f72ca2b06969f2e3"
integrity sha512-TQqhK356IEk7ksMDE/tA3ZKqFEI8O8virZItd/w+RFaBs/HfbDNP8p+xPM5+6Rif3kuBzdubMv3Bdq/OIAJc6g==
dependencies:
"@babel/runtime" "^7.13.9"
"@polkadot/api" "4.0.3"
"@polkadot/rpc-core" "4.0.3"
"@polkadot/types" "4.0.3"
"@babel/runtime" "^7.13.10"
"@polkadot/api" "4.2.1"
"@polkadot/rpc-core" "4.2.1"
"@polkadot/types" "4.2.1"
"@polkadot/util" "^6.0.5"
"@polkadot/util-crypto" "^6.0.5"
"@polkadot/x-rxjs" "^6.0.5"
Expand All @@ -405,19 +405,19 @@
bn.js "^4.11.9"
eventemitter3 "^4.0.7"

"@polkadot/api@4.0.3", "@polkadot/api@^4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-4.0.3.tgz#e3e11ab6341f84562c29677fb9d14d499c6aa892"
integrity sha512-jZf/NBkj6Ao7hG3I0ay7zOyDZm21tdqNRqglagBI+9Nw3wPvPL2Dz/mnGQCaeSq/fv/frY6YZQvouj4gRQzGwQ==
"@polkadot/api@4.2.1", "@polkadot/api@^4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-4.2.1.tgz#8eb0997dc148a34a4aca3a0dcaabad9954565909"
integrity sha512-PbXwcLnZr5V5LfKsovMS0TRG+rfJp8lJxluCyOSABDpaz2h1B5R8rdYEZCmXI3qSrT0yu2C6Pp8AjTQHRd7SAA==
dependencies:
"@babel/runtime" "^7.13.9"
"@polkadot/api-derive" "4.0.3"
"@babel/runtime" "^7.13.10"
"@polkadot/api-derive" "4.2.1"
"@polkadot/keyring" "^6.0.5"
"@polkadot/metadata" "4.0.3"
"@polkadot/rpc-core" "4.0.3"
"@polkadot/rpc-provider" "4.0.3"
"@polkadot/types" "4.0.3"
"@polkadot/types-known" "4.0.3"
"@polkadot/metadata" "4.2.1"
"@polkadot/rpc-core" "4.2.1"
"@polkadot/rpc-provider" "4.2.1"
"@polkadot/types" "4.2.1"
"@polkadot/types-known" "4.2.1"
"@polkadot/util" "^6.0.5"
"@polkadot/util-crypto" "^6.0.5"
"@polkadot/x-rxjs" "^6.0.5"
Expand Down Expand Up @@ -454,14 +454,14 @@
"@polkadot/util-crypto" "^5.9.2"
bn.js "^4.11.9"

"@polkadot/metadata@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-4.0.3.tgz#f0c7b63f8d0f40d8f81218849613f35edcb8157b"
integrity sha512-w4QRpIendx0LWINS3o93weqrNenI4X5T2iOdiPYd+DkIj1k3GI9An5BWnta9e953xEtGstwW169PF/itWMKyTw==
"@polkadot/metadata@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-4.2.1.tgz#7bff99e44992708469e7b2aa70d0865637d8febe"
integrity sha512-oXuKOrKTU0wys5pedKd1OVUDWK8/NoBRCrUYN8fxq3Qq/J9Sz6lF4ZbgX3w22C75l1z2+acsebiZBwlpWgKeqw==
dependencies:
"@babel/runtime" "^7.13.9"
"@polkadot/types" "4.0.3"
"@polkadot/types-known" "4.0.3"
"@babel/runtime" "^7.13.10"
"@polkadot/types" "4.2.1"
"@polkadot/types-known" "4.2.1"
"@polkadot/util" "^6.0.5"
"@polkadot/util-crypto" "^6.0.5"
bn.js "^4.11.9"
Expand Down Expand Up @@ -492,15 +492,15 @@
"@polkadot/util" "^5.9.2"
"@polkadot/x-rxjs" "^5.9.2"

"@polkadot/rpc-core@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-4.0.3.tgz#40046acd961d925ef69532694f48437c7bceef0c"
integrity sha512-BJD5OS9uYlNMNPwRSFB0oT7az9NXBapapcafi6g1O6d4rvDwmsiptKr4+hkoLhzpuZcx6rfYSsVf7oz1v1J9/g==
"@polkadot/rpc-core@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-4.2.1.tgz#249f2e8f359450e365b0784d494814c7348e9a3e"
integrity sha512-A67Rt7lFpdauj7O7fRGn9yhII0SpCRJ/NkHWKo/whj8RwIAuOdxLnekGC9Qr26FPi0mAqN5DBQ8vYSDUiLFXxA==
dependencies:
"@babel/runtime" "^7.13.9"
"@polkadot/metadata" "4.0.3"
"@polkadot/rpc-provider" "4.0.3"
"@polkadot/types" "4.0.3"
"@babel/runtime" "^7.13.10"
"@polkadot/metadata" "4.2.1"
"@polkadot/rpc-provider" "4.2.1"
"@polkadot/types" "4.2.1"
"@polkadot/util" "^6.0.5"
"@polkadot/x-rxjs" "^6.0.5"

Expand All @@ -519,13 +519,13 @@
bn.js "^4.11.9"
eventemitter3 "^4.0.7"

"@polkadot/rpc-provider@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-4.0.3.tgz#55d3e87ff439e2908292fac80bcbd8244291f283"
integrity sha512-xddbODw+uMQrrdWWtKb39OwFqs6VFxvBHDjKmnB8IEUzKq2CIEDJG4qe3y2FfTeVCLWWxSmtxyOj0xo3jok3uw==
"@polkadot/rpc-provider@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-4.2.1.tgz#2dbb217773a57fde2a70fc15628e2682e3ac81f8"
integrity sha512-Gwfs6JAD4Sp+Uz1kEtBSt1P6C3Lwn9xZ64CupU1/6w3qj9QzTFOKHKoznnekiH5HXSh53qVz2c2OSXptSrwL0Q==
dependencies:
"@babel/runtime" "^7.13.9"
"@polkadot/types" "4.0.3"
"@babel/runtime" "^7.13.10"
"@polkadot/types" "4.2.1"
"@polkadot/util" "^6.0.5"
"@polkadot/util-crypto" "^6.0.5"
"@polkadot/x-fetch" "^6.0.5"
Expand All @@ -545,14 +545,14 @@
"@polkadot/util" "^5.9.2"
bn.js "^4.11.9"

"@polkadot/types-known@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-4.0.3.tgz#e1a39c938d5b91c175eb548a586bde6a521205b2"
integrity sha512-XF6Ft2L3zU0E294SpySFi0fv9JIrL0YM0ftOrvqagdXopchc9Sg9XTm3uoukrT8yVu5IVWjQHyk2NwqeAlNV4A==
"@polkadot/types-known@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-4.2.1.tgz#0f1ccef363359de0370cd5b3cc3e6dfe51a18f38"
integrity sha512-/zbvzcCiv6yLhnikVWrN03uJk/3Vuer+sbK8G/pVtLOUhRYdDLOet7VPmRnjH9CGsEGJDQebu0zqW77npg5V2Q==
dependencies:
"@babel/runtime" "^7.13.9"
"@babel/runtime" "^7.13.10"
"@polkadot/networks" "^6.0.5"
"@polkadot/types" "4.0.3"
"@polkadot/types" "4.2.1"
"@polkadot/util" "^6.0.5"
bn.js "^4.11.9"

Expand All @@ -569,13 +569,13 @@
"@types/bn.js" "^4.11.6"
bn.js "^4.11.9"

"@polkadot/types@4.0.3":
version "4.0.3"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-4.0.3.tgz#80640b102b585c7971c7116df6a23bcb1379aa31"
integrity sha512-aLNugf0Zyde8gAkHtPh8Pp2Rw6XJUUIDe9v/Lc3siJji6aPJuzwHW9XoJYBw8A8pl0MbmrJk3js/o3hEKqmFqg==
"@polkadot/types@4.2.1":
version "4.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-4.2.1.tgz#7be97d3abda4bb3f9031b43602062ed464596696"
integrity sha512-xl8QnbXiJmSm6MUZH/U/ov3ZSXMN+KgNjsTCCzfz2xR5B3eK9ClYcstYYkNSyF12K90Gut9bnNSGZvaCfT2hNQ==
dependencies:
"@babel/runtime" "^7.13.9"
"@polkadot/metadata" "4.0.3"
"@babel/runtime" "^7.13.10"
"@polkadot/metadata" "4.2.1"
"@polkadot/util" "^6.0.5"
"@polkadot/util-crypto" "^6.0.5"
"@polkadot/x-rxjs" "^6.0.5"
Expand Down Expand Up @@ -4114,9 +4114,9 @@ polkadot-launch@PureStake/polkadot-launch#moonbeam-launch:
version "1.0.12"
resolved "https://codeload.github.com/PureStake/polkadot-launch/tar.gz/077ecbe74d0ebc30d337ce98429e1306d87ac04c"
dependencies:
"@polkadot/api" "^3.11.1"
"@polkadot/util" "^5.9.2"
"@polkadot/util-crypto" "^5.9.2"
"@polkadot/api" "^3.6.4"
"@polkadot/util" "^5.4.4"
"@polkadot/util-crypto" "^5.4.4"
"@types/chai" "^4.2.14"
"@types/mocha" "^8.2.0"
chai "^4.2.0"
Expand Down