difftreelog
Merge branch 'feature/multi-assets-redone' of https://github.com/UniqueNetwork/unique-chain into feature/multi-assets-redone
in: master
28 files changed
.docker/xcm-config/launch-config-xcm-unique-rococo.jsondiffbeforeafterboth--- /dev/null
+++ b/.docker/xcm-config/launch-config-xcm-unique-rococo.json
@@ -0,0 +1,207 @@
+{
+ "relaychain": {
+ "bin": "/polkadot/target/release/polkadot",
+ "chain": "rococo-local",
+ "chainInitializer": [
+ "chainql",
+ "--tla-code=spec=import '${spec}'",
+ "5validators.jsonnet"
+ ],
+ "nodes": [
+ {
+ "name": "alice",
+ "wsPort": 9844,
+ "rpcPort": 9843,
+ "port": 30444,
+ "flags": [
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "bob",
+ "wsPort": 9855,
+ "rpcPort": 9854,
+ "port": 30555,
+ "flags": [
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "charlie",
+ "wsPort": 9866,
+ "rpcPort": 9865,
+ "port": 30666,
+ "flags": [
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "dave",
+ "wsPort": 9877,
+ "rpcPort": 9876,
+ "port": 30777,
+ "flags": [
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "eve",
+ "wsPort": 9888,
+ "rpcPort": 9887,
+ "port": 30888,
+ "flags": [
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external",
+ "-lparachain::candidate_validation=debug"
+ ]
+ }
+
+ ],
+ "genesis": {
+ "runtime": {
+ "runtime_genesis_config": {
+ "parachainsConfiguration": {
+ "config": {
+ "validation_upgrade_frequency": 1,
+ "validation_upgrade_delay": 1
+ }
+ }
+ }
+ }
+ }
+ },
+ "parachains": [
+ {
+ "bin": "/unique-chain/target/release/unique-collator",
+ "id": "2037",
+ "balance": "1000000000000000000000000",
+ "nodes": [
+ {
+ "port": 31200,
+ "wsPort": 9944,
+ "rpcPort": 9933,
+ "name": "alice",
+ "flags": [
+ "-lruntime=trace",
+ "-lxcm=trace",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ }
+ ]
+ },
+ {
+ "bin": "/acala/target/release/acala",
+ "id": "2000",
+ "chain": "acala-dev",
+ "balance": "1000000000000000000000",
+ "chainInitializer": [
+ "chainql",
+ "-e",
+ "(import '${spec}') {id+: '-local'}"
+ ],
+ "nodes": [
+ {
+ "wsPort": 9946,
+ "port": 31202,
+ "name": "alice",
+ "flags": [
+ "-lruntime=trace",
+ "-lxcm=trace",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ }
+ ]
+ },
+ {
+ "bin": "/moonbeam/target/release/moonbeam",
+ "id": "2004",
+ "balance": "1000000000000000000000",
+ "chain": "moonbeam-local",
+ "nodes": [
+ {
+ "wsPort": 9947,
+ "port": 31203,
+ "name": "alice",
+ "flags": [
+ "-lruntime=trace",
+ "-lxcm=trace",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external",
+ "--",
+ "--execution=wasm"
+ ]
+ }
+ ]
+ },
+ {
+ "bin": "/cumulus/target/release/cumulus",
+ "id": "1000",
+ "chain": "statemint-local",
+ "balance": "1000000000000000000000000",
+ "nodes": [
+ {
+ "wsPort": 9948,
+ "port": 31204,
+ "name": "alice",
+ "flags": [
+ "-lruntime=trace",
+ "-lxcm=trace",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ }
+ ]
+ }
+ ],
+ "simpleParachains": [],
+ "hrmpChannels": [
+ {
+ "sender": 2037,
+ "recipient": 2000,
+ "maxCapacity": 8,
+ "maxMessageSize": 512
+ },
+ {
+ "sender": 2000,
+ "recipient": 2037,
+ "maxCapacity": 8,
+ "maxMessageSize": 512
+ },
+ {
+ "sender": 2037,
+ "recipient": 2004,
+ "maxCapacity": 8,
+ "maxMessageSize": 512
+ },
+ {
+ "sender": 2004,
+ "recipient": 2037,
+ "maxCapacity": 8,
+ "maxMessageSize": 512
+ },
+ {
+ "sender": 2037,
+ "recipient": 1000,
+ "maxCapacity": 8,
+ "maxMessageSize": 512
+ },
+ {
+ "sender": 1000,
+ "recipient": 2037,
+ "maxCapacity": 8,
+ "maxMessageSize": 512
+ }
+ ],
+ "finalization": false
+}
+
.docker/xcm-config/launch-config-xcm-unique.jsondiffbeforeafterboth--- a/.docker/xcm-config/launch-config-xcm-unique.json
+++ b/.docker/xcm-config/launch-config-xcm-unique.json
@@ -101,6 +101,11 @@
"id": "2000",
"chain": "acala-dev",
"balance": "1000000000000000000000",
+ "chainInitializer": [
+ "chainql",
+ "-e",
+ "(import '${spec}') {id+: '-local'}"
+ ],
"nodes": [
{
"wsPort": 9946,
.envdiffbeforeafterboth--- a/.env
+++ b/.env
@@ -15,6 +15,13 @@
POLKADOT_LAUNCH_BRANCH=feature/rewrite-chain-id-in-spec
-ACALA_BUILD_BRANCH=2.9.0
-MOONBEAM_BUILD_BRANCH=v0.25.0
-CUMULUS_BUILD_BRANCH=release-v0.9.230
+KARURA_BUILD_BRANCH=2.9.1
+ACALA_BUILD_BRANCH=2.9.2
+
+MOONRIVER_BUILD_BRANCH=runtime-1701
+MOONBEAM_BUILD_BRANCH=runtime-1701
+
+STATEMINE_BUILD_BRANCH=parachains-v9270
+STATEMINT_BUILD_BRANCH=release-parachains-v9230
+WESTMINT_BUILD_BRANCH=parachains-v9270
+
.github/workflows/ci-develop.ymldiffbeforeafterboth--- a/.github/workflows/ci-develop.yml
+++ b/.github/workflows/ci-develop.yml
@@ -12,27 +12,23 @@
jobs:
yarn-test-dev:
- if: ${{ github.event.pull_request.draft == 'false' }}
uses: ./.github/workflows/dev-build-tests_v2.yml
unit-test:
- if: ${{ github.event.pull_request.draft == 'false' }}
uses: ./.github/workflows/unit-test_v2.yml
-
- forkless:
- if: ${{ contains( github.event.pull_request.labels.*.name, 'forkless') }}
- uses: ./.github/workflows/forkless.yml
canary:
if: ${{ contains( github.event.pull_request.labels.*.name, 'canary') }}
uses: ./.github/workflows/canary.yml
secrets: inherit # pass all secrets
-
xcm:
if: ${{ contains( github.event.pull_request.labels.*.name, 'xcm') }}
uses: ./.github/workflows/xcm.yml
secrets: inherit # pass all secrets
codestyle:
- uses: ./.github/workflows/codestyle_v2.yml
\ No newline at end of file
+ uses: ./.github/workflows/codestyle_v2.yml
+
+ yarn_eslint:
+ uses: ./.github/workflows/test_codestyle_v2.yml
.github/workflows/ci-master.ymldiffbeforeafterboth--- a/.github/workflows/ci-master.yml
+++ b/.github/workflows/ci-master.yml
@@ -12,11 +12,9 @@
jobs:
unit-test:
- if: ${{ github.event.pull_request.draft != 'true' }}
uses: ./.github/workflows/unit-test_v2.yml
node-only-update:
- if: ${{ github.event.pull_request.draft == 'false' }}
uses: ./.github/workflows/node-only-update_v2.yml
forkless:
@@ -34,5 +32,4 @@
secrets: inherit # pass all secrets
codestyle:
- if: ${{ github.event.pull_request.draft == 'false' }}
uses: ./.github/workflows/codestyle_v2.yml
\ No newline at end of file
.github/workflows/dev-build-tests_v2.ymldiffbeforeafterboth--- a/.github/workflows/dev-build-tests_v2.yml
+++ b/.github/workflows/dev-build-tests_v2.yml
@@ -37,23 +37,6 @@
features: "unique-runtime"
steps:
- - name: Skip if pull request is in Draft
- # `if: github.event.pull_request.draft == true` should be kept here, at
- # the step level, rather than at the job level. The latter is not
- # recommended because when the PR is moved from "Draft" to "Ready to
- # review" the workflow will immediately be passing (since it was skipped),
- # even though it hasn't actually ran, since it takes a few seconds for
- # the workflow to start. This is also disclosed in:
- # https://github.community/t/dont-run-actions-on-draft-pull-requests/16817/17
- # That scenario would open an opportunity for the check to be bypassed:
- # 1. Get your PR approved
- # 2. Move it to Draft
- # 3. Push whatever commits you want
- # 4. Move it to "Ready for review"; now the workflow is passing (it was
- # skipped) and "Check reviews" is also passing (it won't be updated
- # until the workflow is finished)
- if: github.event.pull_request.draft == true
- run: exit 1
- name: Clean Workspace
uses: AutoModality/action-clean@v1.1.0
@@ -92,7 +75,6 @@
yarn install
yarn add mochawesome
echo "Ready to start tests"
- node scripts/readyness.js
NOW=$(date +%s) && yarn test --reporter mochawesome --reporter-options reportFilename=test-${NOW}
env:
RPC_URL: http://127.0.0.1:9933/
.github/workflows/test_codestyle_v2.ymldiffbeforeafterboth--- a/.github/workflows/test_codestyle_v2.yml
+++ b/.github/workflows/test_codestyle_v2.yml
@@ -5,7 +5,7 @@
jobs:
code_style:
- runs-on: self-hosted-ci
+ runs-on: [ self-hosted-ci ]
steps:
- uses: actions/checkout@v3
.github/workflows/xcm-testnet-build.ymldiffbeforeafterboth--- a/.github/workflows/xcm-testnet-build.yml
+++ b/.github/workflows/xcm-testnet-build.yml
@@ -18,7 +18,7 @@
name: Prepare execution matrix
- runs-on: XL
+ runs-on: [XL]
outputs:
matrix: ${{ steps.create_matrix.outputs.matrix }}
@@ -40,9 +40,9 @@
id: create_matrix
with:
matrix: |
- network {opal}, runtime {opal}, features {opal-runtime}
- network {quartz}, runtime {quartz}, features {quartz-runtime}
- network {unique}, runtime {unique}, features {unique-runtime}
+ network {opal}, runtime {opal}, features {opal-runtime}, acala_version {${{ env.ACALA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONBEAM_BUILD_BRANCH }}}, cumulus_version {${{ env.WESTMINT_BUILD_BRANCH }}}
+ network {quartz}, runtime {quartz}, features {quartz-runtime}, acala_version {${{ env.KARURA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONRIVER_BUILD_BRANCH }}}, cumulus_version {${{ env.STATEMINE_BUILD_BRANCH }}}
+ network {unique}, runtime {unique}, features {unique-runtime}, acala_version {${{ env.ACALA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONBEAM_BUILD_BRANCH }}}, cumulus_version {${{ env.STATEMINT_BUILD_BRANCH }}}
xcm-build:
@@ -89,9 +89,9 @@
FEATURE=${{ matrix.features }}
RUNTIME=${{ matrix.runtime }}
BRANCH=${{ github.head_ref }}
- ACALA_BUILD_BRANCH=${{ env.ACALA_BUILD_BRANCH }}
- MOONBEAM_BUILD_BRANCH=${{ env.MOONBEAM_BUILD_BRANCH }}
- CUMULUS_BUILD_BRANCH=${{ env.CUMULUS_BUILD_BRANCH }}
+ ACALA_BUILD_BRANCH=${{ matrix.acala_version }}
+ MOONBEAM_BUILD_BRANCH=${{ matrix.moonbeam_version }}
+ CUMULUS_BUILD_BRANCH=${{ matrix.cumulus_version }}
- name: Show build Dockerfile
run: cat .docker/Dockerfile-xcm.${{ matrix.network }}.yml
@@ -114,13 +114,13 @@
password: ${{ secrets.CORE_DOCKERHUB_TOKEN }}
- name: Pull acala docker image
- run: docker pull uniquenetwork/builder-acala:${{ env.ACALA_BUILD_BRANCH }}
+ run: docker pull uniquenetwork/builder-acala:${{ matrix.acala_version }}
- name: Pull moonbeam docker image
- run: docker pull uniquenetwork/builder-moonbeam:${{ env.MOONBEAM_BUILD_BRANCH }}
+ run: docker pull uniquenetwork/builder-moonbeam:${{ matrix.moonbeam_version }}
- name: Pull cumulus docker image
- run: docker pull uniquenetwork/builder-cumulus:${{ env.CUMULUS_BUILD_BRANCH }}
+ run: docker pull uniquenetwork/builder-cumulus:${{ matrix.cumulus_version }}
- name: Pull polkadot docker image
run: docker pull uniquenetwork/builder-polkadot:${{ env.POLKADOT_BUILD_BRANCH }}
.github/workflows/xcm-tests_v2.ymldiffbeforeafterboth--- a/.github/workflows/xcm-tests_v2.yml
+++ b/.github/workflows/xcm-tests_v2.yml
@@ -146,6 +146,7 @@
run: |
yarn install
yarn add mochawesome
+ node scripts/readyness.js
echo "Ready to start tests"
NOW=$(date +%s) && yarn ${{ matrix.runtest }} --reporter mochawesome --reporter-options reportFilename=test-${NOW}
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -302,7 +302,7 @@
[dependencies]
futures = '0.3.17'
-log = '0.4.14'
+log = '0.4.16'
flexi_logger = "0.22.5"
parking_lot = '0.12.1'
clap = "3.1.2"
pallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -8,7 +8,7 @@
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
] }
-log = { default-features = false, version = "0.4.14" }
+log = { default-features = false, version = "0.4.16" }
# Substrate
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
pallets/foreing-assets/Cargo.tomldiffbeforeafterboth--- a/pallets/foreing-assets/Cargo.toml
+++ b/pallets/foreing-assets/Cargo.toml
@@ -5,7 +5,7 @@
edition = "2021"
[dependencies]
-log = { version = "0.4.14", default-features = false }
+log = { version = "0.4.16", default-features = false }
serde = { version = "1.0.136", optional = true }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
pallets/scheduler/Cargo.tomldiffbeforeafterboth--- a/pallets/scheduler/Cargo.toml
+++ b/pallets/scheduler/Cargo.toml
@@ -25,7 +25,7 @@
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.27" }
-log = { version = "0.4.14", default-features = false }
+log = { version = "0.4.16", default-features = false }
[dev-dependencies]
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
runtime/common/construct_runtime/mod.rsdiffbeforeafterboth--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -42,7 +42,7 @@
Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,
Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,
Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,
- #[runtimes(opal)]
+
XTokens: orml_xtokens = 38,
Tokens: orml_tokens = 39,
// Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,
runtime/opal/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/opal/src/xcm_config.rs
+++ b/runtime/opal/src/xcm_config.rs
@@ -498,7 +498,7 @@
impl orml_xtokens::Config for Runtime {
type Event = Event;
type Balance = Balance;
- type CurrencyId = AssetIds;
+ type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdConvert;
type AccountIdToMultiLocation = AccountIdToMultiLocation;
type SelfLocation = SelfLocation;
runtime/quartz/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/quartz/src/xcm_config.rs
+++ b/runtime/quartz/src/xcm_config.rs
@@ -180,11 +180,10 @@
type OnKilledTokenAccount = ();
}
-/*
impl orml_xtokens::Config for Runtime {
type Event = Event;
type Balance = Balance;
- type CurrencyId = AssetIds;
+ type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdConvert;
type AccountIdToMultiLocation = AccountIdToMultiLocation;
type SelfLocation = SelfLocation;
@@ -197,8 +196,8 @@
type MultiLocationsFilter = Everything;
type ReserveProvider = AbsoluteReserveProvider;
}
- */
+
parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: CurrencyId| -> Balance {
match currency_id {
@@ -218,7 +217,7 @@
}
}
-/*
+
pub struct CurrencyIdConvert;
impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
fn convert(id: AssetIds) -> Option<MultiLocation> {
@@ -228,12 +227,11 @@
X1(Parachain(ParachainInfo::get().into())),
)),
AssetIds::NativeAssetId(NativeCurrency::Parent) => Some(MultiLocation::parent()),
- AssetIds::ForeignAssetId(foreign_asset_id) => {
- XcmForeignAssetIdMapping::<Runtime>::get_multi_location(foreign_asset_id)
- }
+ AssetIds::ForeignAssetId(_) => None,
}
}
}
+/*
impl Convert<MultiLocation, Option<CurrencyId>> for CurrencyIdConvert {
fn convert(location: MultiLocation) -> Option<CurrencyId> {
if location == MultiLocation::here()
runtime/unique/src/xcm_config.rsdiffbeforeafterboth--- a/runtime/unique/src/xcm_config.rs
+++ b/runtime/unique/src/xcm_config.rs
@@ -88,6 +88,8 @@
MultiLocation { parents: 1, interior: Here },
// Karura/Acala location
MultiLocation { parents: 1, interior: X1(Parachain(2000)) },
+ // Moonbeam location
+ MultiLocation { parents: 1, interior: X1(Parachain(2004)) },
// Self parachain address
MultiLocation { parents: 1, interior: X1(Parachain(ParachainInfo::get().into())) },
]
@@ -201,10 +203,42 @@
type OnKilledTokenAccount = ();
}
+impl orml_xtokens::Config for Runtime {
+ type Event = Event;
+ type Balance = Balance;
+ type CurrencyId = CurrencyId;
+ type CurrencyIdConvert = CurrencyIdConvert;
+ type AccountIdToMultiLocation = AccountIdToMultiLocation;
+ type SelfLocation = SelfLocation;
+ type XcmExecutor = XcmExecutor<XcmConfig<Self>>;
+ type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
+ type BaseXcmWeight = BaseXcmWeight;
+ type LocationInverter = LocationInverter<Ancestry>;
+ type MaxAssetsForTransfer = MaxAssetsForTransfer;
+ type MinXcmFee = ParachainMinFee;
+ type MultiLocationsFilter = Everything;
+ type ReserveProvider = AbsoluteReserveProvider;
+}
+
+pub struct CurrencyIdConvert;
+impl Convert<AssetIds, Option<MultiLocation>> for CurrencyIdConvert {
+ fn convert(id: AssetIds) -> Option<MultiLocation> {
+ match id {
+ AssetIds::NativeAssetId(NativeCurrency::Here) => Some(MultiLocation::new(
+ 1,
+ X1(Parachain(ParachainInfo::get().into())),
+ )),
+ _ => None,
+ }
+ }
+}
parameter_types! {
pub const BaseXcmWeight: Weight = 100_000_000; // TODO: recheck this
pub const MaxAssetsForTransfer: usize = 2;
+
+ pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
+ pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into())));
}
parameter_type_with_key! {
@@ -223,4 +257,4 @@
})
.into()
}
-}
\ No newline at end of file
+}
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -74,11 +74,12 @@
"testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",
"testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",
"testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",
- "testXcmUnique": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
+ "testXcmUnique": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmUnique.test.ts",
+ "testXcmQuartz": "RUN_XCM_TESTS=1 mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmQuartz.test.ts",
"testXcmOpal": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmOpal.test.ts",
"testXcmTransferAcala": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
"testXcmTransferStatemine": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
- "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts moonbeamId=2000 uniqueId=5000",
+ "testXcmTransferMoonbeam": "mocha --timeout 9999999 -r ts-node/register ./**/xcm/xcmTransferMoonbeam.test.ts",
"testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
"testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
"testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
tests/scripts/readyness.jsdiffbeforeafterboth--- a/tests/scripts/readyness.js
+++ b/tests/scripts/readyness.js
@@ -6,9 +6,9 @@
await api.isReadyOrError;
const head = (await api.rpc.chain.getHeader()).number.toNumber();
+ await api.disconnect();
if(head < 1) throw Error('No block #1');
- await api.disconnect();
}
const sleep = time => {
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -85,7 +85,7 @@
for (const arg of args) {
if (typeof arg !== 'string')
continue;
- if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
+ if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
return;
}
printer(...args);
@@ -169,13 +169,24 @@
/* eslint no-async-promise-executor: "off" */
return new Promise(async (resolve, reject) => {
try {
- await transaction.signAndSend(sender, ({events = [], status}) => {
+ await transaction.signAndSend(sender, ({events = [], status, dispatchError}) => {
const transactionStatus = getTransactionStatus(events, status);
if (transactionStatus === TransactionStatus.Success) {
resolve(events);
} else if (transactionStatus === TransactionStatus.Fail) {
- console.log(`Something went wrong with transaction. Status: ${status}`);
+ let moduleError = null;
+
+ if (dispatchError) {
+ if (dispatchError.isModule) {
+ const modErr = dispatchError.asModule;
+ const errorMeta = dispatchError.registry.findMetaError(modErr);
+
+ moduleError = JSON.stringify(errorMeta, null, 4);
+ }
+ }
+
+ console.log(`Something went wrong with transaction. Status: ${status}\nModule error: ${moduleError}`);
reject(events);
}
});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -1746,6 +1746,12 @@
return (await api.rpc.unique.collectionById(collectionId)).unwrap();
}
+export const describe_xcm = (
+ process.env.RUN_XCM_TESTS
+ ? describe
+ : describe.skip
+);
+
export async function waitNewBlocks(blocksCount = 1): Promise<void> {
await usingApi(async (api) => {
const promise = new Promise<void>(async (resolve) => {
@@ -1762,6 +1768,35 @@
});
}
+export async function waitEvent(
+ api: ApiPromise,
+ maxBlocksToWait: number,
+ eventSection: string,
+ eventMethod: string,
+): Promise<EventRecord | null> {
+
+ const promise = new Promise<EventRecord | null>(async (resolve) => {
+ const unsubscribe = await api.query.system.events(eventRecords => {
+ const neededEvent = eventRecords.find(r => {
+ return r.event.section == eventSection && r.event.method == eventMethod;
+ });
+
+ if (neededEvent) {
+ unsubscribe();
+ resolve(neededEvent);
+ }
+
+ if (maxBlocksToWait > 0) {
+ maxBlocksToWait--;
+ } else {
+ unsubscribe();
+ resolve(null);
+ }
+ });
+ });
+ return promise;
+}
+
export async function repartitionRFT(
api: ApiPromise,
collectionId: number,
tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -26,7 +26,7 @@
for (const arg of args) {
if (typeof arg !== 'string')
continue;
- if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
+ if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
return;
}
printer(...args);
@@ -49,4 +49,4 @@
console.log = consoleLog;
console.warn = consoleWarn;
}
-};
\ No newline at end of file
+};
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -103,7 +103,6 @@
let accountsCreated = false;
// checkBalances retry up to 5 blocks
for (let index = 0; index < 5; index++) {
- console.log(await this.helper.chain.getLatestBlockNumber());
accountsCreated = await checkBalances();
if(accountsCreated) break;
await this.waitNewBlocks(1);
tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmOpal.test.ts
+++ b/tests/src/xcm/xcmOpal.test.ts
@@ -35,7 +35,7 @@
const RELAY_PORT = '9844';
const UNIQUE_PORT = '9944';
-const STATEMINE_PORT = '9946';
+const STATEMINE_PORT = '9948';
const STATEMINE_PALLET_INSTANCE = 50;
const ASSET_ID = 100;
const ASSET_METADATA_DECIMALS = 18;
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -0,0 +1,682 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+
+import {WsProvider, Keyring} from '@polkadot/api';
+import {ApiOptions} from '@polkadot/api/types';
+import {IKeyringPair} from '@polkadot/types/types';
+import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
+import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm} from '../util/helpers';
+import {MultiLocation} from '@polkadot/types/interfaces';
+import {blake2AsHex} from '@polkadot/util-crypto';
+import waitNewBlocks from '../substrate/wait-new-blocks';
+import getBalance from '../substrate/get-balance';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+const QUARTZ_CHAIN = 2095;
+const KARURA_CHAIN = 2000;
+const MOONRIVER_CHAIN = 2023;
+
+const KARURA_PORT = 9946;
+const MOONRIVER_PORT = 9947;
+
+const TRANSFER_AMOUNT = 2000000000000000000000000n;
+
+function parachainApiOptions(port: number): ApiOptions {
+ return {
+ provider: new WsProvider('ws://127.0.0.1:' + port.toString()),
+ };
+}
+
+function karuraOptions(): ApiOptions {
+ return parachainApiOptions(KARURA_PORT);
+}
+
+function moonriverOptions(): ApiOptions {
+ return parachainApiOptions(MOONRIVER_PORT);
+}
+
+describe_xcm('Integration test: Exchanging tokens with Karura', () => {
+ let alice: IKeyringPair;
+ let randomAccount: IKeyringPair;
+
+ let balanceQuartzTokenInit: bigint;
+ let balanceQuartzTokenMiddle: bigint;
+ let balanceQuartzTokenFinal: bigint;
+ let balanceKaruraTokenInit: bigint;
+ let balanceKaruraTokenMiddle: bigint;
+ let balanceKaruraTokenFinal: bigint;
+ let balanceQuartzForeignTokenInit: bigint;
+ let balanceQuartzForeignTokenMiddle: bigint;
+ let balanceQuartzForeignTokenFinal: bigint;
+
+ before(async () => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ alice = privateKeyWrapper('//Alice');
+ randomAccount = generateKeyringPair();
+ });
+
+ // Karura side
+ await usingApi(
+ async (api) => {
+ const destination = {
+ V0: {
+ X2: [
+ 'Parent',
+ {
+ Parachain: QUARTZ_CHAIN,
+ },
+ ],
+ },
+ };
+
+ const metadata = {
+ name: 'QTZ',
+ symbol: 'QTZ',
+ decimals: 18,
+ minimalBalance: 1,
+ };
+
+ const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
+ const sudoTx = api.tx.sudo.sudo(tx as any);
+ const events = await submitTransactionAsync(alice, sudoTx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
+ const events1 = await submitTransactionAsync(alice, tx1);
+ const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
+
+ [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
+ {
+ const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceQuartzForeignTokenInit = BigInt(free);
+ }
+ },
+ karuraOptions(),
+ );
+
+ // Quartz side
+ await usingApi(async (api) => {
+ const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
+ const events0 = await submitTransactionAsync(alice, tx0);
+ const result0 = getGenericResult(events0);
+ expect(result0.success).to.be.true;
+
+ [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
+ });
+ });
+
+ it('Should connect and send QTZ to Karura', async () => {
+
+ // Quartz side
+ await usingApi(async (api) => {
+
+ const destination = {
+ V0: {
+ X2: [
+ 'Parent',
+ {
+ Parachain: KARURA_CHAIN,
+ },
+ ],
+ },
+ };
+
+ const beneficiary = {
+ V0: {
+ X1: {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
+ },
+ },
+ };
+
+ const assets = {
+ V1: [
+ {
+ id: {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
+ },
+ },
+ fun: {
+ Fungible: TRANSFER_AMOUNT,
+ },
+ },
+ ],
+ };
+
+ const feeAssetItem = 0;
+
+ const weightLimit = {
+ Limited: 5000000000,
+ };
+
+ const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+ const events = await submitTransactionAsync(randomAccount, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
+
+ const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
+ console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', qtzFees);
+ expect(qtzFees > 0n).to.be.true;
+ });
+
+ // Karura side
+ await usingApi(
+ async (api) => {
+ await waitNewBlocks(api, 3);
+ const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceQuartzForeignTokenMiddle = BigInt(free);
+
+ [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
+
+ const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
+ const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
+
+ console.log('[Quartz -> Karura] transaction fees on Karura: %s KAR', karFees);
+ console.log('[Quartz -> Karura] income %s QTZ', qtzIncomeTransfer);
+ expect(karFees == 0n).to.be.true;
+ expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ },
+ karuraOptions(),
+ );
+ });
+
+ it('Should connect to Karura and send QTZ back', async () => {
+
+ // Karura side
+ await usingApi(
+ async (api) => {
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: QUARTZ_CHAIN},
+ {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
+ },
+ ],
+ },
+ },
+ };
+
+ const id = {
+ ForeignAsset: 0,
+ };
+
+ const destWeight = 50000000;
+
+ const tx = api.tx.xTokens.transfer(id, TRANSFER_AMOUNT, destination, destWeight);
+ const events = await submitTransactionAsync(randomAccount, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
+ {
+ const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceQuartzForeignTokenFinal = BigInt(free);
+ }
+
+ const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
+ const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
+
+ console.log('[Karura -> Quartz] transaction fees on Karura: %s KAR', karFees);
+ console.log('[Karura -> Quartz] outcome %s QTZ', qtzOutcomeTransfer);
+
+ expect(karFees > 0).to.be.true;
+ expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ },
+ karuraOptions(),
+ );
+
+ // Quartz side
+ await usingApi(async (api) => {
+ await waitNewBlocks(api, 3);
+
+ [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
+ const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
+ expect(actuallyDelivered > 0).to.be.true;
+
+ console.log('[Karura -> Quartz] actually delivered %s QTZ', actuallyDelivered);
+
+ const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
+ console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', qtzFees);
+ expect(qtzFees == 0n).to.be.true;
+ });
+ });
+
+ it('Quartz rejects KAR tokens from Karura', async () => {
+ // This test is relevant only when the foreign asset pallet is disabled
+
+ await usingApi(async (api) => {
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: QUARTZ_CHAIN},
+ {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
+ },
+ ],
+ },
+ },
+ };
+
+ const id = {
+ Token: 'KAR',
+ };
+
+ const destWeight = 50000000;
+
+ const tx = api.tx.xTokens.transfer(id, 100_000_000_000, destination, destWeight);
+ const events = await submitTransactionAsync(alice, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+ }, karuraOptions());
+
+ await usingApi(async api => {
+ const maxWaitBlocks = 3;
+ const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');
+
+ expect(
+ xcmpQueueFailEvent != null,
+ 'Only native token is supported when the Foreign-Assets pallet is not connected',
+ ).to.be.true;
+ });
+ });
+});
+
+describe_xcm('Integration test: Exchanging QTZ with Moonriver', () => {
+
+ // Quartz constants
+ let quartzAlice: IKeyringPair;
+ let quartzAssetLocation;
+
+ let randomAccountQuartz: IKeyringPair;
+ let randomAccountMoonriver: IKeyringPair;
+
+ // Moonriver constants
+ let assetId: string;
+
+ const moonriverKeyring = new Keyring({type: 'ethereum'});
+ const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';
+ const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';
+ const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';
+
+ const alithAccount = moonriverKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');
+ const baltatharAccount = moonriverKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');
+ const dorothyAccount = moonriverKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');
+
+ const councilVotingThreshold = 2;
+ const technicalCommitteeThreshold = 2;
+ const votingPeriod = 3;
+ const delayPeriod = 0;
+
+ const quartzAssetMetadata = {
+ name: 'xcQuartz',
+ symbol: 'xcQTZ',
+ decimals: 18,
+ isFrozen: false,
+ minimalBalance: 1,
+ };
+
+ let balanceQuartzTokenInit: bigint;
+ let balanceQuartzTokenMiddle: bigint;
+ let balanceQuartzTokenFinal: bigint;
+ let balanceForeignQtzTokenInit: bigint;
+ let balanceForeignQtzTokenMiddle: bigint;
+ let balanceForeignQtzTokenFinal: bigint;
+ let balanceMovrTokenInit: bigint;
+ let balanceMovrTokenMiddle: bigint;
+ let balanceMovrTokenFinal: bigint;
+
+ before(async () => {
+ await usingApi(async (api, privateKeyWrapper) => {
+ quartzAlice = privateKeyWrapper('//Alice');
+ randomAccountQuartz = generateKeyringPair();
+ randomAccountMoonriver = generateKeyringPair('ethereum');
+
+ balanceForeignQtzTokenInit = 0n;
+ });
+
+ await usingApi(
+ async (api) => {
+
+ // >>> Sponsoring Dorothy >>>
+ console.log('Sponsoring Dorothy.......');
+ const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
+ const events0 = await submitTransactionAsync(alithAccount, tx0);
+ const result0 = getGenericResult(events0);
+ expect(result0.success).to.be.true;
+ console.log('Sponsoring Dorothy.......DONE');
+ // <<< Sponsoring Dorothy <<<
+
+ const sourceLocation: MultiLocation = api.createType(
+ 'MultiLocation',
+ {
+ parents: 1,
+ interior: {X1: {Parachain: QUARTZ_CHAIN}},
+ },
+ );
+
+ quartzAssetLocation = {XCM: sourceLocation};
+ const existentialDeposit = 1;
+ const isSufficient = true;
+ const unitsPerSecond = '1';
+ const numAssetsWeightHint = 0;
+
+ const registerTx = api.tx.assetManager.registerForeignAsset(
+ quartzAssetLocation,
+ quartzAssetMetadata,
+ existentialDeposit,
+ isSufficient,
+ );
+ console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
+
+ const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
+ quartzAssetLocation,
+ unitsPerSecond,
+ numAssetsWeightHint,
+ );
+ console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
+
+ const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
+ console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
+
+ // >>> Note motion preimage >>>
+ console.log('Note motion preimage.......');
+ const encodedProposal = batchCall?.method.toHex() || '';
+ const proposalHash = blake2AsHex(encodedProposal);
+ console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
+ console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
+ console.log('Encoded length %d', encodedProposal.length);
+
+ const tx1 = api.tx.democracy.notePreimage(encodedProposal);
+ const events1 = await submitTransactionAsync(baltatharAccount, tx1);
+ const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
+ console.log('Note motion preimage.......DONE');
+ // <<< Note motion preimage <<<
+
+ // >>> Propose external motion through council >>>
+ console.log('Propose external motion through council.......');
+ const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
+ const tx2 = api.tx.councilCollective.propose(
+ councilVotingThreshold,
+ externalMotion,
+ externalMotion.encodedLength,
+ );
+ const events2 = await submitTransactionAsync(baltatharAccount, tx2);
+ const result2 = getGenericResult(events2);
+ expect(result2.success).to.be.true;
+
+ const encodedMotion = externalMotion?.method.toHex() || '';
+ const motionHash = blake2AsHex(encodedMotion);
+ console.log('Motion hash is %s', motionHash);
+
+ const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
+ {
+ const events3 = await submitTransactionAsync(dorothyAccount, tx3);
+ const result3 = getGenericResult(events3);
+ expect(result3.success).to.be.true;
+ }
+ {
+ const events3 = await submitTransactionAsync(baltatharAccount, tx3);
+ const result3 = getGenericResult(events3);
+ expect(result3.success).to.be.true;
+ }
+
+ const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
+ const events4 = await submitTransactionAsync(dorothyAccount, tx4);
+ const result4 = getGenericResult(events4);
+ expect(result4.success).to.be.true;
+ console.log('Propose external motion through council.......DONE');
+ // <<< Propose external motion through council <<<
+
+ // >>> Fast track proposal through technical committee >>>
+ console.log('Fast track proposal through technical committee.......');
+ const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
+ const tx5 = api.tx.techCommitteeCollective.propose(
+ technicalCommitteeThreshold,
+ fastTrack,
+ fastTrack.encodedLength,
+ );
+ const events5 = await submitTransactionAsync(alithAccount, tx5);
+ const result5 = getGenericResult(events5);
+ expect(result5.success).to.be.true;
+
+ const encodedFastTrack = fastTrack?.method.toHex() || '';
+ const fastTrackHash = blake2AsHex(encodedFastTrack);
+ console.log('FastTrack hash is %s', fastTrackHash);
+
+ const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
+ const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
+ {
+ const events6 = await submitTransactionAsync(baltatharAccount, tx6);
+ const result6 = getGenericResult(events6);
+ expect(result6.success).to.be.true;
+ }
+ {
+ const events6 = await submitTransactionAsync(alithAccount, tx6);
+ const result6 = getGenericResult(events6);
+ expect(result6.success).to.be.true;
+ }
+
+ const tx7 = api.tx.techCommitteeCollective
+ .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
+ const events7 = await submitTransactionAsync(baltatharAccount, tx7);
+ const result7 = getGenericResult(events7);
+ expect(result7.success).to.be.true;
+ console.log('Fast track proposal through technical committee.......DONE');
+ // <<< Fast track proposal through technical committee <<<
+
+ // >>> Referendum voting >>>
+ console.log('Referendum voting.......');
+ const tx8 = api.tx.democracy.vote(
+ 0,
+ {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
+ );
+ const events8 = await submitTransactionAsync(dorothyAccount, tx8);
+ const result8 = getGenericResult(events8);
+ expect(result8.success).to.be.true;
+ console.log('Referendum voting.......DONE');
+ // <<< Referendum voting <<<
+
+ // >>> Acquire Quartz AssetId Info on Moonriver >>>
+ console.log('Acquire Quartz AssetId Info on Moonriver.......');
+
+ // Wait for the democracy execute
+ await waitNewBlocks(api, 5);
+
+ assetId = (await api.query.assetManager.assetTypeId({
+ XCM: sourceLocation,
+ })).toString();
+
+ console.log('QTZ asset ID is %s', assetId);
+ console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
+ // >>> Acquire Quartz AssetId Info on Moonriver >>>
+
+ // >>> Sponsoring random Account >>>
+ console.log('Sponsoring random Account.......');
+ const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
+ const events10 = await submitTransactionAsync(baltatharAccount, tx10);
+ const result10 = getGenericResult(events10);
+ expect(result10.success).to.be.true;
+ console.log('Sponsoring random Account.......DONE');
+ // <<< Sponsoring random Account <<<
+
+ [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);
+ },
+ moonriverOptions(),
+ );
+
+ await usingApi(async (api) => {
+ const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
+ const events0 = await submitTransactionAsync(quartzAlice, tx0);
+ const result0 = getGenericResult(events0);
+ expect(result0.success).to.be.true;
+
+ [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);
+ });
+ });
+
+ it('Should connect and send QTZ to Moonriver', async () => {
+ await usingApi(async (api) => {
+ const currencyId = {
+ NativeAssetId: 'Here',
+ };
+ const dest = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: MOONRIVER_CHAIN},
+ {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},
+ ],
+ },
+ },
+ };
+ const amount = TRANSFER_AMOUNT;
+ const destWeight = 850000000;
+
+ const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);
+ const events = await submitTransactionAsync(randomAccountQuartz, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
+ expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
+
+ const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
+ console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', transactionFees);
+ expect(transactionFees > 0).to.be.true;
+ });
+
+ await usingApi(
+ async (api) => {
+ await waitNewBlocks(api, 3);
+
+ [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
+
+ const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
+ console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR', movrFees);
+ expect(movrFees == 0n).to.be.true;
+
+ const qtzRandomAccountAsset = (
+ await api.query.assets.account(assetId, randomAccountMoonriver.address)
+ ).toJSON()! as any;
+
+ balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
+ const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
+ console.log('[Quartz -> Moonriver] income %s QTZ', qtzIncomeTransfer);
+ expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ },
+ moonriverOptions(),
+ );
+ });
+
+ it('Should connect to Moonriver and send QTZ back', async () => {
+ await usingApi(
+ async (api) => {
+ const asset = {
+ V1: {
+ id: {
+ Concrete: {
+ parents: 1,
+ interior: {
+ X1: {Parachain: QUARTZ_CHAIN},
+ },
+ },
+ },
+ fun: {
+ Fungible: TRANSFER_AMOUNT,
+ },
+ },
+ };
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: QUARTZ_CHAIN},
+ {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
+ ],
+ },
+ },
+ };
+ const destWeight = 50000000;
+
+ const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);
+ const events = await submitTransactionAsync(randomAccountMoonriver, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
+
+ const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
+ console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', movrFees);
+ expect(movrFees > 0).to.be.true;
+
+ const qtzRandomAccountAsset = (
+ await api.query.assets.account(assetId, randomAccountMoonriver.address)
+ ).toJSON()! as any;
+
+ expect(qtzRandomAccountAsset).to.be.null;
+
+ balanceForeignQtzTokenFinal = 0n;
+
+ const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
+ console.log('[Quartz -> Moonriver] outcome %s QTZ', qtzOutcomeTransfer);
+ expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ },
+ moonriverOptions(),
+ );
+
+ await usingApi(async (api) => {
+ await waitNewBlocks(api, 3);
+
+ [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
+ const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
+ expect(actuallyDelivered > 0).to.be.true;
+
+ console.log('[Moonriver -> Quartz] actually delivered %s QTZ', actuallyDelivered);
+
+ const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
+ console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', qtzFees);
+ expect(qtzFees == 0n).to.be.true;
+ });
+ });
+});
tests/src/xcm/xcmTransferMoonbeam.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmTransferMoonbeam.test.ts
+++ b/tests/src/xcm/xcmTransferMoonbeam.test.ts
@@ -50,7 +50,7 @@
});
const UNIQUE_PORT = '9944';
-const MOONBEAM_PORT = '9946';
+const MOONBEAM_PORT = '9947';
const TRANSFER_AMOUNT = 2000000000000000000000000n;
describe('Integration test: Exchanging UNQ with Moonbeam', () => {
tests/src/xcm/xcmTransferStatemine.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmTransferStatemine.test.ts
+++ b/tests/src/xcm/xcmTransferStatemine.test.ts
@@ -53,7 +53,7 @@
const RELAY_PORT = '9844';
const UNIQUE_PORT = '9944';
-const STATEMINE_PORT = '9946';
+const STATEMINE_PORT = '9948';
const STATEMINE_PALLET_INSTANCE = 50;
const ASSET_ID = 100;
const ASSET_METADATA_DECIMALS = 18;
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth17import chai from 'chai';17import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';191920import {WsProvider} from '@polkadot/api';20import {WsProvider, Keyring} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';23import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';24import {getGenericResult, generateKeyringPair} from '../util/helpers';24import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm} from '../util/helpers';25import {MultiLocation} from '@polkadot/types/interfaces';26import {blake2AsHex} from '@polkadot/util-crypto';25import waitNewBlocks from '../substrate/wait-new-blocks';27import waitNewBlocks from '../substrate/wait-new-blocks';26import getBalance from '../substrate/get-balance';28import getBalance from '../substrate/get-balance';2729303231const UNIQUE_CHAIN = 2037;33const UNIQUE_CHAIN = 2037;32const ACALA_CHAIN = 2000;34const ACALA_CHAIN = 2000;35const MOONBEAM_CHAIN = 2004;333634const ACALA_PORT = '9946';37const ACALA_PORT = 9946;38const MOONBEAM_PORT = 9947;353936const TRANSFER_AMOUNT = 2000000000000000000000000n;40const TRANSFER_AMOUNT = 2000000000000000000000000n;374142function parachainApiOptions(port: number): ApiOptions {43 return {44 provider: new WsProvider('ws://127.0.0.1:' + port.toString()),45 };46}4748function acalaOptions(): ApiOptions {49 return parachainApiOptions(ACALA_PORT);50}5152function moonbeamOptions(): ApiOptions {53 return parachainApiOptions(MOONBEAM_PORT);54}5538describe('Integration test: Exchanging UNQ with Acala', () => {56describe_xcm('Integration test: Exchanging tokens with Acala', () => {39 let alice: IKeyringPair;57 let alice: IKeyringPair;40 let randomAccount: IKeyringPair;58 let randomAccount: IKeyringPair;41 59 42 let balanceUniqueTokenBefore: bigint;60 let balanceUniqueTokenInit: bigint;43 let balanceUniqueTokenAfter: bigint;61 let balanceUniqueTokenMiddle: bigint;44 let balanceUniqueTokenFinal: bigint;62 let balanceUniqueTokenFinal: bigint;45 let balanceAcalaTokenBefore: bigint;63 let balanceAcalaTokenInit: bigint;46 let balanceAcalaTokenAfter: bigint;64 let balanceAcalaTokenMiddle: bigint;47 let balanceAcalaTokenFinal: bigint;65 let balanceAcalaTokenFinal: bigint;48 let balanceUniqueForeignTokenAfter: bigint;66 let balanceUniqueForeignTokenInit: bigint;49 let balanceUniqueForeignTokenBefore: bigint;67 let balanceUniqueForeignTokenMiddle: bigint;50 let balanceUniqueForeignTokenFinal: bigint;68 let balanceUniqueForeignTokenFinal: bigint;51 69 52 before(async () => {70 before(async () => {53 await usingApi(async (api, privateKeyWrapper) => {71 await usingApi(async (api, privateKeyWrapper) => {54 alice = privateKeyWrapper('//Alice');72 alice = privateKeyWrapper('//Alice');55 randomAccount = generateKeyringPair();73 randomAccount = generateKeyringPair();56 });74 });57 7558 const acalaApiOptions: ApiOptions = {59 provider: new WsProvider('ws://127.0.0.1:' + ACALA_PORT),60 };61 62 // Acala side76 // Acala side63 await usingApi(77 await usingApi(64 async (api) => {78 async (api) => {91 const result1 = getGenericResult(events1);105 const result1 = getGenericResult(events1);92 expect(result1.success).to.be.true;106 expect(result1.success).to.be.true;93 107 94 [balanceAcalaTokenBefore] = await getBalance(api, [randomAccount.address]);108 [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);95 {109 {96 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;110 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;97 balanceUniqueForeignTokenBefore = BigInt(free);111 balanceUniqueForeignTokenInit = BigInt(free);98 }112 }99 },113 },100 acalaApiOptions,114 acalaOptions(),101 );115 );102 116 103 // Unique side117 // Unique side107 const result0 = getGenericResult(events0);121 const result0 = getGenericResult(events0);108 expect(result0.success).to.be.true;122 expect(result0.success).to.be.true;109 123 110 [balanceUniqueTokenBefore] = await getBalance(api, [randomAccount.address]);124 [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);111 });125 });112 });126 });113 127 165 const result = getGenericResult(events);179 const result = getGenericResult(events);166 expect(result.success).to.be.true;180 expect(result.success).to.be.true;167 181 168 [balanceUniqueTokenAfter] = await getBalance(api, [randomAccount.address]);182 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);169 183 170 const unqFees = balanceUniqueTokenBefore - balanceUniqueTokenAfter;184 const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;171 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', unqFees);185 console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', unqFees);172 expect(unqFees > 0n).to.be.true;186 expect(unqFees > 0n).to.be.true;173 });187 });174 188 175 // Acala side189 // Acala side176 await usingApi(190 await usingApi(177 async (api) => {191 async (api) => {178 // todo do something about instant sealing, where there might not be any new blocks179 await waitNewBlocks(api, 3);192 await waitNewBlocks(api, 3);180 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;193 const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;181 balanceUniqueForeignTokenAfter = BigInt(free);194 balanceUniqueForeignTokenMiddle = BigInt(free);182 195 183 [balanceAcalaTokenAfter] = await getBalance(api, [randomAccount.address]);196 [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);184197185 const acaFees = balanceAcalaTokenBefore - balanceAcalaTokenAfter;198 const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;186 const unqDiffAfterIncomeTransfer = balanceUniqueForeignTokenAfter - balanceUniqueForeignTokenBefore;199 const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;187200188 const unqFees = unqDiffAfterIncomeTransfer - TRANSFER_AMOUNT;189190 console.log('[Unique -> Acala] transaction fees on Acala: %s ACA', acaFees);201 console.log('[Unique -> Acala] transaction fees on Acala: %s ACA', acaFees);191 console.log('[Unique -> Acala] transaction fees on Acala: %s UNQ', unqFees);202 console.log('[Unique -> Acala] income %s UNQ', unqIncomeTransfer);192 expect(acaFees == 0n).to.be.true;203 expect(acaFees == 0n).to.be.true;193 expect(unqFees == 0n).to.be.true;204 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;194 },205 },195 {provider: new WsProvider('ws://127.0.0.1:' + ACALA_PORT)},206 acalaOptions(),196 );207 );197 });208 });198 209 221 const id = {232 const id = {222 ForeignAsset: 0,233 ForeignAsset: 0,223 };234 };224 235225 const amount = TRANSFER_AMOUNT;226 const destWeight = 50000000;236 const destWeight = 50000000;227 237 228 const tx = api.tx.xTokens.transfer(id, amount, destination, destWeight);238 const tx = api.tx.xTokens.transfer(id, TRANSFER_AMOUNT, destination, destWeight);229 const events = await submitTransactionAsync(randomAccount, tx);239 const events = await submitTransactionAsync(randomAccount, tx);230 const result = getGenericResult(events);240 const result = getGenericResult(events);231 expect(result.success).to.be.true;241 expect(result.success).to.be.true;236 balanceUniqueForeignTokenFinal = BigInt(free);246 balanceUniqueForeignTokenFinal = BigInt(free);237 }247 }238 248 239 const acaFees = balanceAcalaTokenAfter - balanceAcalaTokenFinal;249 const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;240 const unqDiffAfterOutcomeTransfer = balanceUniqueForeignTokenAfter - TRANSFER_AMOUNT;250 const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;241251242 const unqFees = unqDiffAfterOutcomeTransfer - balanceUniqueForeignTokenFinal;243244 console.log('[Acala -> Unique] transaction fees on Acala: %s ACA', acaFees);252 console.log('[Acala -> Unique] transaction fees on Acala: %s ACA', acaFees);245 console.log('[Acala -> Unique] transaction fees on Acala: %s UNQ', unqFees);253 console.log('[Acala -> Unique] outcome %s UNQ', unqOutcomeTransfer);246254247 expect(acaFees > 0).to.be.true;255 expect(acaFees > 0).to.be.true;248 expect(unqFees == 0n).to.be.true;256 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;249 },257 },250 {provider: new WsProvider('ws://127.0.0.1:' + ACALA_PORT)},258 acalaOptions(),251 );259 );252260253 // Unique side261 // Unique side254 await usingApi(async (api) => {262 await usingApi(async (api) => {255 // todo do something about instant sealing, where there might not be any new blocks256 await waitNewBlocks(api, 3);263 await waitNewBlocks(api, 3);257 264 258 [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);265 [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);259 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenAfter;266 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;260 expect(actuallyDelivered > 0).to.be.true;267 expect(actuallyDelivered > 0).to.be.true;268269 console.log('[Acala -> Unique] actually delivered %s UNQ', actuallyDelivered);261 270 262 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;271 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;263 console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', unqFees);272 console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', unqFees);273 expect(unqFees == 0n).to.be.true;274 });275 });276277 it('Unique rejects ACA tokens from Acala', async () => {278 // This test is relevant only when the foreign asset pallet is disabled279280 await usingApi(async (api) => {281 const destination = {282 V1: {283 parents: 1,284 interior: {285 X2: [286 {Parachain: UNIQUE_CHAIN},287 {288 AccountId32: {289 network: 'Any',290 id: randomAccount.addressRaw,291 },292 },293 ],294 },295 },296 };297298 const id = {299 Token: 'ACA',300 };301302 const destWeight = 50000000;303304 const tx = api.tx.xTokens.transfer(id, 100_000_000_000, destination, destWeight);305 const events = await submitTransactionAsync(alice, tx);306 const result = getGenericResult(events);307 expect(result.success).to.be.true;308 }, acalaOptions());309310 await usingApi(async api => {311 const maxWaitBlocks = 3;312 const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');313314 expect(315 xcmpQueueFailEvent != null,316 'Only native token is supported when the Foreign-Assets pallet is not connected',317 ).to.be.true;318 });319 });320});321322describe_xcm('Integration test: Exchanging UNQ with Moonbeam', () => {323324 // Unique constants325 let uniqueAlice: IKeyringPair;326 let uniqueAssetLocation;327328 let randomAccountUnique: IKeyringPair;329 let randomAccountMoonbeam: IKeyringPair;330331 // Moonbeam constants332 let assetId: string;333334 const moonbeamKeyring = new Keyring({type: 'ethereum'});335 const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';336 const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';337 const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';338339 const alithAccount = moonbeamKeyring.addFromUri(alithPrivateKey, undefined, 'ethereum');340 const baltatharAccount = moonbeamKeyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');341 const dorothyAccount = moonbeamKeyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');342343 const councilVotingThreshold = 2;344 const technicalCommitteeThreshold = 2;345 const votingPeriod = 3;346 const delayPeriod = 0;347348 const uniqueAssetMetadata = {349 name: 'xcUnique',350 symbol: 'xcUNQ',351 decimals: 18,352 isFrozen: false,353 minimalBalance: 1,354 };355356 let balanceUniqueTokenInit: bigint;357 let balanceUniqueTokenMiddle: bigint;358 let balanceUniqueTokenFinal: bigint;359 let balanceForeignUnqTokenInit: bigint;360 let balanceForeignUnqTokenMiddle: bigint;361 let balanceForeignUnqTokenFinal: bigint;362 let balanceGlmrTokenInit: bigint;363 let balanceGlmrTokenMiddle: bigint;364 let balanceGlmrTokenFinal: bigint;365366 before(async () => {367 await usingApi(async (api, privateKeyWrapper) => {368 uniqueAlice = privateKeyWrapper('//Alice');369 randomAccountUnique = generateKeyringPair();370 randomAccountMoonbeam = generateKeyringPair('ethereum');371372 balanceForeignUnqTokenInit = 0n;373 });374375 await usingApi(376 async (api) => {377378 // >>> Sponsoring Dorothy >>>379 console.log('Sponsoring Dorothy.......');380 const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);381 const events0 = await submitTransactionAsync(alithAccount, tx0);382 const result0 = getGenericResult(events0);383 expect(result0.success).to.be.true;384 console.log('Sponsoring Dorothy.......DONE');385 // <<< Sponsoring Dorothy <<<386387 const sourceLocation: MultiLocation = api.createType(388 'MultiLocation',389 {390 parents: 1,391 interior: {X1: {Parachain: UNIQUE_CHAIN}},392 },393 );394395 uniqueAssetLocation = {XCM: sourceLocation};396 const existentialDeposit = 1;397 const isSufficient = true;398 const unitsPerSecond = '1';399 const numAssetsWeightHint = 0;400401 const registerTx = api.tx.assetManager.registerForeignAsset(402 uniqueAssetLocation,403 uniqueAssetMetadata,404 existentialDeposit,405 isSufficient,406 );407 console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');408409 const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(410 uniqueAssetLocation,411 unitsPerSecond,412 numAssetsWeightHint,413 );414 console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');415416 const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);417 console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');418419 // >>> Note motion preimage >>>420 console.log('Note motion preimage.......');421 const encodedProposal = batchCall?.method.toHex() || '';422 const proposalHash = blake2AsHex(encodedProposal);423 console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);424 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);425 console.log('Encoded length %d', encodedProposal.length);426427 const tx1 = api.tx.democracy.notePreimage(encodedProposal);428 const events1 = await submitTransactionAsync(baltatharAccount, tx1);429 const result1 = getGenericResult(events1);430 expect(result1.success).to.be.true;431 console.log('Note motion preimage.......DONE');432 // <<< Note motion preimage <<<433434 // >>> Propose external motion through council >>>435 console.log('Propose external motion through council.......');436 const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);437 const tx2 = api.tx.councilCollective.propose(438 councilVotingThreshold,439 externalMotion,440 externalMotion.encodedLength,441 );442 const events2 = await submitTransactionAsync(baltatharAccount, tx2);443 const result2 = getGenericResult(events2);444 expect(result2.success).to.be.true;445446 const encodedMotion = externalMotion?.method.toHex() || '';447 const motionHash = blake2AsHex(encodedMotion);448 console.log('Motion hash is %s', motionHash);449450 const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);451 {452 const events3 = await submitTransactionAsync(dorothyAccount, tx3);453 const result3 = getGenericResult(events3);454 expect(result3.success).to.be.true;455 }456 {457 const events3 = await submitTransactionAsync(baltatharAccount, tx3);458 const result3 = getGenericResult(events3);459 expect(result3.success).to.be.true;460 }461462 const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);463 const events4 = await submitTransactionAsync(dorothyAccount, tx4);464 const result4 = getGenericResult(events4);465 expect(result4.success).to.be.true;466 console.log('Propose external motion through council.......DONE');467 // <<< Propose external motion through council <<<468469 // >>> Fast track proposal through technical committee >>>470 console.log('Fast track proposal through technical committee.......');471 const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);472 const tx5 = api.tx.techCommitteeCollective.propose(473 technicalCommitteeThreshold,474 fastTrack,475 fastTrack.encodedLength,476 );477 const events5 = await submitTransactionAsync(alithAccount, tx5);478 const result5 = getGenericResult(events5);479 expect(result5.success).to.be.true;480481 const encodedFastTrack = fastTrack?.method.toHex() || '';482 const fastTrackHash = blake2AsHex(encodedFastTrack);483 console.log('FastTrack hash is %s', fastTrackHash);484485 const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;486 const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);487 {488 const events6 = await submitTransactionAsync(baltatharAccount, tx6);489 const result6 = getGenericResult(events6);490 expect(result6.success).to.be.true;491 }492 {493 const events6 = await submitTransactionAsync(alithAccount, tx6);494 const result6 = getGenericResult(events6);495 expect(result6.success).to.be.true;496 }497498 const tx7 = api.tx.techCommitteeCollective499 .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);500 const events7 = await submitTransactionAsync(baltatharAccount, tx7);501 const result7 = getGenericResult(events7);502 expect(result7.success).to.be.true;503 console.log('Fast track proposal through technical committee.......DONE');504 // <<< Fast track proposal through technical committee <<<505506 // >>> Referendum voting >>>507 console.log('Referendum voting.......');508 const tx8 = api.tx.democracy.vote(509 0,510 {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},511 );512 const events8 = await submitTransactionAsync(dorothyAccount, tx8);513 const result8 = getGenericResult(events8);514 expect(result8.success).to.be.true;515 console.log('Referendum voting.......DONE');516 // <<< Referendum voting <<<517518 // >>> Acquire Unique AssetId Info on Moonbeam >>>519 console.log('Acquire Unique AssetId Info on Moonbeam.......');520521 // Wait for the democracy execute522 await waitNewBlocks(api, 5);523524 assetId = (await api.query.assetManager.assetTypeId({525 XCM: sourceLocation,526 })).toString();527528 console.log('UNQ asset ID is %s', assetId);529 console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');530 // >>> Acquire Unique AssetId Info on Moonbeam >>>531532 // >>> Sponsoring random Account >>>533 console.log('Sponsoring random Account.......');534 const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);535 const events10 = await submitTransactionAsync(baltatharAccount, tx10);536 const result10 = getGenericResult(events10);537 expect(result10.success).to.be.true;538 console.log('Sponsoring random Account.......DONE');539 // <<< Sponsoring random Account <<<540541 [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);542 },543 moonbeamOptions(),544 );545546 await usingApi(async (api) => {547 const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);548 const events0 = await submitTransactionAsync(uniqueAlice, tx0);549 const result0 = getGenericResult(events0);550 expect(result0.success).to.be.true;551552 [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);553 });554 });555556 it('Should connect and send UNQ to Moonbeam', async () => {557 await usingApi(async (api) => {558 const currencyId = {559 NativeAssetId: 'Here',560 };561 const dest = {562 V1: {563 parents: 1,564 interior: {565 X2: [566 {Parachain: MOONBEAM_CHAIN},567 {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},568 ],569 },570 },571 };572 const amount = TRANSFER_AMOUNT;573 const destWeight = 850000000;574575 const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);576 const events = await submitTransactionAsync(randomAccountUnique, tx);577 const result = getGenericResult(events);578 expect(result.success).to.be.true;579580 [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);581 expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;582583 const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;584 console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', transactionFees);585 expect(transactionFees > 0).to.be.true;586 });587588 await usingApi(589 async (api) => {590 await waitNewBlocks(api, 3);591592 [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);593594 const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;595 console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', glmrFees);596 expect(glmrFees == 0n).to.be.true;597598 const unqRandomAccountAsset = (599 await api.query.assets.account(assetId, randomAccountMoonbeam.address)600 ).toJSON()! as any;601602 balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);603 const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;604 console.log('[Unique -> Moonbeam] income %s UNQ', unqIncomeTransfer);605 expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;606 },607 moonbeamOptions(),608 );609 });610611 it('Should connect to Moonbeam and send UNQ back', async () => {612 await usingApi(613 async (api) => {614 const asset = {615 V1: {616 id: {617 Concrete: {618 parents: 1,619 interior: {620 X1: {Parachain: UNIQUE_CHAIN},621 },622 },623 },624 fun: {625 Fungible: TRANSFER_AMOUNT,626 },627 },628 };629 const destination = {630 V1: {631 parents: 1,632 interior: {633 X2: [634 {Parachain: UNIQUE_CHAIN},635 {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},636 ],637 },638 },639 };640 const destWeight = 50000000;641642 const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);643 const events = await submitTransactionAsync(randomAccountMoonbeam, tx);644 const result = getGenericResult(events);645 expect(result.success).to.be.true;646647 [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);648649 const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;650 console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', glmrFees);651 expect(glmrFees > 0).to.be.true;652653 const unqRandomAccountAsset = (654 await api.query.assets.account(assetId, randomAccountMoonbeam.address)655 ).toJSON()! as any;656657 expect(unqRandomAccountAsset).to.be.null;658659 balanceForeignUnqTokenFinal = 0n;660661 const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;662 console.log('[Unique -> Moonbeam] outcome %s UNQ', unqOutcomeTransfer);663 expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;664 },665 moonbeamOptions(),666 );667668 await usingApi(async (api) => {669 await waitNewBlocks(api, 3);670671 [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);672 const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;673 expect(actuallyDelivered > 0).to.be.true;674675 console.log('[Moonbeam -> Unique] actually delivered %s UNQ', actuallyDelivered);676677 const unqFees = TRANSFER_AMOUNT - actuallyDelivered;678 console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', unqFees);264 expect(unqFees == 0n).to.be.true;679 expect(unqFees == 0n).to.be.true;265 });680 });266 });681 });