-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/cargo/serde_json-1.0.117
- Loading branch information
Showing
5 changed files
with
220 additions
and
84 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
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,126 @@ | ||
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; | ||
import { RELAY_ASSET_ID, setupRelayAsset, sleep, submitExtrinsic } from "../common"; | ||
|
||
import assert from "node:assert"; | ||
|
||
const TOLERANCE = 10n**10n; | ||
|
||
async function run(nodeName: string, networkInfo: any, _jsArgs: any) { | ||
const { wsUri: regionXUri } = networkInfo.nodesByName[nodeName]; | ||
const { wsUri: rococoUri } = networkInfo.nodesByName["rococo-validator01"]; | ||
|
||
const rococoApi = await ApiPromise.create({ provider: new WsProvider(rococoUri) }); | ||
const regionXApi = await ApiPromise.create({ provider: new WsProvider(regionXUri) }); | ||
|
||
// account to submit tx | ||
const keyring = new Keyring({ type: "sr25519" }); | ||
const alice = keyring.addFromUri("//Alice"); | ||
|
||
const setXcmVersion = rococoApi.tx.xcmPallet.forceDefaultXcmVersion([3]); | ||
await submitExtrinsic(alice, rococoApi.tx.sudo.sudo(setXcmVersion), {}); | ||
|
||
await setupRelayAsset(regionXApi, alice); | ||
|
||
const receiverKeypair = new Keyring(); | ||
receiverKeypair.addFromAddress(alice.address); | ||
|
||
const assertRegionXBalance = async (address: string, balance: bigint) => { | ||
const { free } = ( | ||
await regionXApi.query.tokens.accounts(address, RELAY_ASSET_ID) | ||
).toHuman() as any; | ||
|
||
console.log(`RegionX: ${free}`); | ||
assert(balance - BigInt(free.toString().replace(/,/g, "")) < TOLERANCE); | ||
}; | ||
|
||
const assertRococoBalance = async (address: string, balance: bigint) => { | ||
const { | ||
data: { free }, | ||
} = (await rococoApi.query.system.account(address)).toHuman() as any; | ||
|
||
console.log(`Rococo: ${free}`); | ||
assert(balance - BigInt(free.toString().replace(/,/g, "")) < TOLERANCE); | ||
}; | ||
|
||
await assertRegionXBalance(alice.address, 10n ** 12n); | ||
await assertRococoBalance(alice.address, 10n ** 18n); | ||
|
||
const feeAssetItem = 0; | ||
const weightLimit = "Unlimited"; | ||
const rococoReserveTransfer = rococoApi.tx.xcmPallet.limitedReserveTransferAssets( | ||
{ V3: { parents: 0, interior: { X1: { Parachain: 2000 } } } }, //dest | ||
{ | ||
V3: { | ||
parents: 0, | ||
interior: { | ||
X1: { | ||
AccountId32: { | ||
chain: "Any", | ||
id: receiverKeypair.pairs[0].publicKey, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, //beneficiary | ||
{ | ||
V3: [ | ||
{ | ||
id: { | ||
Concrete: { parents: 0, interior: "Here" }, | ||
}, | ||
fun: { | ||
Fungible: 3n * 10n ** 12n, | ||
}, | ||
}, | ||
], | ||
}, //asset | ||
feeAssetItem, | ||
weightLimit | ||
); | ||
await submitExtrinsic(alice, rococoReserveTransfer, {}); | ||
|
||
await sleep(5 * 1000); | ||
|
||
await assertRegionXBalance(alice.address, 4n * 10n ** 12n); | ||
await assertRococoBalance(alice.address, 10n ** 18n - 3n * 10n ** 12n); | ||
|
||
const regionXReserveTransfer = regionXApi.tx.polkadotXcm.limitedReserveTransferAssets( | ||
{ V3: { parents: 1, interior: "Here" } }, //dest | ||
{ | ||
V3: { | ||
parents: 0, | ||
interior: { | ||
X1: { | ||
AccountId32: { | ||
chain: "Any", | ||
id: receiverKeypair.pairs[0].publicKey, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, //beneficiary | ||
{ | ||
V3: [ | ||
{ | ||
id: { | ||
Concrete: { parents: 1, interior: "Here" }, | ||
}, | ||
fun: { | ||
Fungible: 10n ** 12n, | ||
}, | ||
}, | ||
], | ||
}, //asset | ||
feeAssetItem, | ||
weightLimit | ||
); | ||
|
||
await submitExtrinsic(alice, regionXReserveTransfer, {}); | ||
|
||
await sleep(5 * 1000); | ||
|
||
await assertRegionXBalance(alice.address, 4n * 10n ** 12n); | ||
await assertRococoBalance(alice.address, 10n ** 18n - 3n * 10n ** 12n); | ||
} | ||
|
||
export { run }; |
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,25 @@ | ||
[settings] | ||
timeout = 1000 | ||
|
||
[relaychain] | ||
chain = "rococo-local" | ||
command = "polkadot" | ||
|
||
[[relaychain.nodes]] | ||
name = "rococo-validator01" | ||
args = [ "--log=xcm=trace" ] | ||
validator = true | ||
|
||
[[relaychain.nodes]] | ||
name = "rococo-validator02" | ||
args = [ "--log=xcm=trace" ] | ||
validator = true | ||
|
||
[[parachains]] | ||
id = 2000 | ||
addToGenesis = false | ||
|
||
[parachains.collator] | ||
name = "regionx-collator01" | ||
command = "regionx-node" | ||
args = [ "--log=xcm=trace" ] |
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,11 @@ | ||
Description: Cross chain transfer between RegionX and the relay chain | ||
Network: ./0006-xc-transfer.toml | ||
Creds: config | ||
|
||
rococo-validator01: is up | ||
rococo-validator02: is up | ||
|
||
rococo-validator01: parachain 2000 is registered within 225 seconds | ||
|
||
regionx-collator01: js-script ../e2e_tests/build/xc-transfer/asset-transfer.js return is 0 within 400 seconds | ||
|