This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add xcm_teleport_assets.ts #432
Merged
+324
−5
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
efbc45e
feat: add xcm_teleport_assets.ts
kratico 8bd58a5
feat: improve xcm teleport asset example
kratico 8de6447
feat: improve zombienet node client configuration
kratico cc2815e
feat: add GH setup-binary action
kratico b29c078
chore: add polkadot explorer urls for relaychain/parachain nodes
kratico 997111c
chore: update words.txt
kratico 2d3fbfa
Merge branch 'main' into feat/xcm-example
harrysolovay f2bb202
chore: format toml and remove extra console.log messages
kratico a4dfaae
chore: ignore xcm_teleport_assets example
kratico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,28 @@ | ||
name: "Setup Binary" | ||
description: "Setup Binary" | ||
inputs: | ||
binary-name: | ||
description: "Binary name" | ||
required: true | ||
binary-version: | ||
description: "Binary version" | ||
required: true | ||
binary-github: | ||
description: "Binary github repository url" | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Cache Binary | ||
uses: actions/cache@v3 | ||
id: cache-binary | ||
with: | ||
path: | | ||
/usr/local/bin/${{ inputs.binary-name }} | ||
key: binary-${{ inputs.binary-name }}-${{ inputs.binary-version }} | ||
- if: ${{ steps.cache-binary.outputs.cache-hit != 'true' }} | ||
name: Download Binary | ||
run: | | ||
curl -L -o /usr/local/bin/${{ inputs.binary-name }} ${{ inputs.binary-github }}/releases/download/${{ inputs.binary-version }}/${{ inputs.binary-name }} | ||
chmod +x /usr/local/bin/${{ inputs.binary-name }} | ||
shell: bash |
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
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,24 @@ | ||
[relaychain] | ||
default_image = "docker.io/paritypr/polkadot-debug:master" | ||
default_command = "polkadot" | ||
default_args = ["-lparachain=debug"] | ||
chain = "rococo-local" | ||
|
||
[[relaychain.nodes]] | ||
name = "alice" | ||
validator = true | ||
|
||
[[relaychain.nodes]] | ||
name = "bob" | ||
validator = true | ||
|
||
[[parachains]] | ||
id = 1000 | ||
cumulus_based = true | ||
chain = "statemine-local" | ||
|
||
[parachains.collator] | ||
name = "collator01" | ||
image = "docker.io/parity/polkadot-parachain:latest" | ||
command = "polkadot-parachain" | ||
args = ["-lparachain=debug"] |
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,151 @@ | ||
// This example requires zombienet-macos/zombienet-linux, polkadot and polkadot-parachain binaries in the PATH | ||
|
||
import * as path from "http://localhost:5646/@local/deps/std/path.ts" | ||
import * as C from "http://localhost:5646/@local/mod.ts" | ||
import * as T from "http://localhost:5646/@local/test_util/mod.ts" | ||
import * as U from "http://localhost:5646/@local/util/mod.ts" | ||
|
||
const configFile = path.join( | ||
path.dirname(path.fromFileUrl(import.meta.url)), | ||
"xcm_teleport_assets.toml", | ||
) | ||
const zombienet = await T.zombienet.start(configFile) | ||
|
||
Deno.addSignalListener("SIGINT", async () => { | ||
try { | ||
await zombienet.close() | ||
} finally { | ||
Deno.exit() | ||
} | ||
}) | ||
|
||
// see xcm_teleport_asset.toml for node names | ||
const relaychainClient = zombienet.clients.byName["alice"]! | ||
const parachainClient = zombienet.clients.byName["collator01"]! | ||
|
||
const teleportAssetsTx = C.extrinsic(relaychainClient)({ | ||
sender: T.alice.address, | ||
call: { | ||
type: "XcmPallet", | ||
value: { | ||
type: "limitedTeleportAssets", | ||
dest: { | ||
type: "V1", | ||
value: { | ||
parents: 0, | ||
interior: { | ||
type: "X1", | ||
value: { | ||
type: "Parachain", | ||
value: 1000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
beneficiary: { | ||
type: "V1", | ||
value: { | ||
parents: 0, | ||
interior: { | ||
type: "X1", | ||
value: { | ||
type: "AccountId32", | ||
id: T.alice.address.value, | ||
network: { | ||
type: "Any", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
assets: { | ||
type: "V1", | ||
value: [{ | ||
id: { | ||
type: "Concrete", | ||
value: { | ||
parents: 0, | ||
interior: { | ||
type: "Here", | ||
}, | ||
}, | ||
}, | ||
fun: { | ||
type: "Fungible", | ||
value: 500_000_000_000_000n, | ||
}, | ||
}], | ||
}, | ||
feeAssetItem: 0, | ||
weightLimit: { | ||
type: "Unlimited", | ||
}, | ||
}, | ||
}, | ||
}) | ||
.signed(T.alice.sign) | ||
.watch(({ end }) => { | ||
return (status) => { | ||
console.log(status) | ||
if (typeof status !== "string" && status.finalized) { | ||
return end(status.finalized) | ||
} else if (C.rpc.known.TransactionStatus.isTerminal(status)) { | ||
return end(new Error()) | ||
} | ||
return | ||
} | ||
}) | ||
|
||
const aliceParachainBalance = () => | ||
C.entryRead(parachainClient)("System", "Account", [T.alice.publicKey]) | ||
.access("value") | ||
.access("data") | ||
.access("free") | ||
|
||
const watchForDownwardMessagesProcessed = C.entryWatch(parachainClient)( | ||
"System", | ||
"Events", | ||
[], | ||
({ end }) => { | ||
return (entry: any) => { | ||
for (const [_hash, events] of entry) { | ||
if (!events) return | ||
for (const { event } of events) { | ||
if ( | ||
event.type === "ParachainSystem" && event.value.type === "DownwardMessagesProcessed" | ||
) { | ||
return end(event) | ||
} | ||
} | ||
} | ||
return | ||
} | ||
}, | ||
) | ||
|
||
const watchForDownwardMessagesProcessedPending = watchForDownwardMessagesProcessed.run() | ||
|
||
const watchForParachainBlocksPending = C.blockWatch(parachainClient)( | ||
({ end }) => { | ||
let i = 0 | ||
return () => { | ||
if (i === 1) { | ||
return end() | ||
} | ||
i++ | ||
return | ||
} | ||
}, | ||
).run() | ||
|
||
console.log("Alice parachain balance before XcmPallet.limitedTeleportAssets") | ||
console.log(U.throwIfError(await aliceParachainBalance().run())) | ||
U.throwIfError(await teleportAssetsTx.run()) | ||
console.log("waiting for parachain ParachainSystem.DownwardMessagesProcessed event") | ||
console.log(U.throwIfError(await watchForDownwardMessagesProcessedPending)) | ||
console.log("waiting for parachain to start generating blocks") | ||
U.throwIfError(await watchForParachainBlocksPending) | ||
console.log("Alice parachain balance after XcmPallet.limitedTeleportAssets") | ||
console.log(U.throwIfError(await aliceParachainBalance().run())) | ||
|
||
await zombienet.close() |
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,88 @@ | ||
import * as Z from "../deps/zones.ts" | ||
import * as C from "../mod.ts" | ||
|
||
export const start = async (configFile: string, env?: Record<string, string>) => { | ||
const networkFilesPath = await Deno.makeTempDir({ prefix: "capi_zombienet" }) | ||
const process = Deno.run({ | ||
cmd: [ | ||
zombienetBinary(), | ||
"-d", | ||
networkFilesPath, | ||
"--provider", | ||
"native", | ||
"--force", | ||
"spawn", | ||
configFile, | ||
], | ||
stdout: "piped", | ||
env, | ||
}) | ||
// TODO: improve Network launched detection | ||
// Deno.watchFs on `${networkFilesPath}/zombie.json` could be an alternative | ||
const buffer = new Uint8Array(1024) | ||
while (true) { | ||
await process.stdout?.read(buffer) | ||
const text = new TextDecoder().decode(buffer) | ||
if (text.includes("Network launched")) { | ||
process.stdout.close() | ||
break | ||
} | ||
} | ||
const close = async () => { | ||
process.kill("SIGINT") | ||
await process.status() | ||
process.close() | ||
Deno.remove(networkFilesPath, { recursive: true }) | ||
} | ||
const config = JSON.parse(await Deno.readTextFile(`${networkFilesPath}/zombie.json`)) | ||
const clients = { | ||
relay: config.relay.map((node: any) => new NodeClientEffect(node.wsUri)) as NodeClientEffect[], | ||
paras: Object.entries(config.paras) | ||
.reduce( | ||
(acc, [name, { nodes }]: any) => { | ||
acc[name] = nodes.map((node: any) => new NodeClientEffect(node.wsUri)) | ||
return acc | ||
}, | ||
{} as Record<string, NodeClientEffect[]>, | ||
), | ||
byName: Object.entries(config.nodesByName) | ||
.reduce( | ||
(acc, [name, node]: any) => { | ||
acc[name] = new NodeClientEffect(node.wsUri) | ||
return acc | ||
}, | ||
{} as Record<string, NodeClientEffect>, | ||
), | ||
} | ||
return { close, config, clients } | ||
} | ||
|
||
export class NodeClientEffect extends Z.Effect<C.rpc.Client<string, Event, Event, Event>, Error> { | ||
constructor(readonly url: string) { | ||
super({ | ||
kind: "Client", | ||
impl: Z | ||
.call(() => { | ||
try { | ||
return new C.rpc.Client(C.rpc.proxyProvider, url) | ||
} catch (e) { | ||
return e | ||
} | ||
}) | ||
.impl, | ||
items: [url], | ||
memoize: true, | ||
}) | ||
} | ||
} | ||
|
||
function zombienetBinary() { | ||
switch (Deno.build.os) { | ||
case "darwin": | ||
return "zombienet-macos" | ||
case "linux": | ||
return "zombienet-linux" | ||
default: | ||
throw new Error(`zombienet does not support ${Deno.build.os} OS`) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -205,4 +205,7 @@ xxhash | |
xxnetwork | ||
zio | ||
zombienet | ||
relaychain | ||
paritypr | ||
lparachain | ||
unioned |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a nit... nevertheless