difftreelog
Fixes after review
in: master
6 files changed
.docker/xcm-config/launch-config-xcm-quartz.j2diffbeforeafterboth--- a/.docker/xcm-config/launch-config-xcm-quartz.j2
+++ b/.docker/xcm-config/launch-config-xcm-quartz.j2
@@ -169,7 +169,7 @@
{
"bin": "/astar/target/release/astar",
"id": "2007",
- "chain": "astar-dev",
+ "chain": "shiden-dev",
"balance": "1000000000000000000000000",
"nodes": [
{
@@ -224,12 +224,12 @@
},
{
"sender": 2007,
- "recipient": 1000,
+ "recipient": 2095,
"maxCapacity": 8,
"maxMessageSize": 512
},
{
- "sender": 1000,
+ "sender": 2095,
"recipient": 2007,
"maxCapacity": 8,
"maxMessageSize": 512
.docker/xcm-config/launch-config-xcm-unique.j2diffbeforeafterboth--- a/.docker/xcm-config/launch-config-xcm-unique.j2
+++ b/.docker/xcm-config/launch-config-xcm-unique.j2
@@ -224,12 +224,12 @@
},
{
"sender": 2006,
- "recipient": 1000,
+ "recipient": 2037,
"maxCapacity": 8,
"maxMessageSize": 512
},
{
- "sender": 1000,
+ "sender": 2037,
"recipient": 2006,
"maxCapacity": 8,
"maxMessageSize": 512
tests/src/util/index.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import * as path from 'path';5import * as crypto from 'crypto';6import {IKeyringPair} from '@polkadot/types/types/interfaces';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import chaiSubset from 'chai-subset';10import {Context} from 'mocha';11import config from '../config';12import {ChainHelperBase} from './playgrounds/unique';13import {ILogger} from './playgrounds/types';14import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper, DevShidenHelper} from './playgrounds/unique.dev';15import {dirname} from 'path';16import {fileURLToPath} from 'url';1718chai.use(chaiAsPromised);19chai.use(chaiSubset);20export const expect = chai.expect;2122const getTestHash = (filename: string) => {23 return crypto.createHash('md5').update(filename).digest('hex');24};2526export const getTestSeed = (filename: string) => {27 return `//Alice+${getTestHash(filename)}`;28};2930async function usingPlaygroundsGeneral<T extends ChainHelperBase>(helperType: new(logger: ILogger) => T, url: string, code: (helper: T, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>) {31 const silentConsole = new SilentConsole();32 silentConsole.enable();3334 const helper = new helperType(new SilentLogger());3536 try {37 await helper.connect(url);38 const ss58Format = helper.chain.getChainProperties().ss58Format;39 const privateKey = async (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => {40 if (typeof seed === 'string') {41 return helper.util.fromSeed(seed, ss58Format);42 }43 if (seed.url) {44 const {filename} = makeNames(seed.url);45 seed.filename = filename;46 } else if (seed.filename) {47 // Pass48 } else {49 throw new Error('no url nor filename set');50 }51 const actualSeed = getTestSeed(seed.filename);52 let account = helper.util.fromSeed(actualSeed, ss58Format);53 // here's to hoping that no54 if (!seed.ignoreFundsPresence && ((helper as any)['balance'] == undefined || await (helper as any).balance.getSubstrate(account.address) < MINIMUM_DONOR_FUND)) {55 console.warn(`${path.basename(seed.filename)}: Not enough funds present on the filename account. Using the default one as the donor instead.`);56 account = helper.util.fromSeed('//Alice', ss58Format);57 }58 return account;59 };60 await code(helper, privateKey);61 }62 finally {63 await helper.disconnect();64 silentConsole.disable();65 }66}6768export const usingPlaygrounds = (code: (helper: DevUniqueHelper, privateKey: (seed: string | {filename?: string, url?: string, ignoreFundsPresence?: boolean}) => Promise<IKeyringPair>) => Promise<void>, url: string = config.substrateUrl) => {69 return usingPlaygroundsGeneral<DevUniqueHelper>(DevUniqueHelper, url, code);70};7172export const usingWestmintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {73 return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);74};7576export const usingStateminePlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {77 return usingPlaygroundsGeneral<DevStatemineHelper>(DevWestmintHelper, url, code);78};7980export const usingStatemintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {81 return usingPlaygroundsGeneral<DevStatemintHelper>(DevWestmintHelper, url, code);82};8384export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {85 return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);86};8788export const usingAcalaPlaygrounds = (url: string, code: (helper: DevAcalaHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {89 return usingPlaygroundsGeneral<DevAcalaHelper>(DevAcalaHelper, url, code);90};9192export const usingKaruraPlaygrounds = (url: string, code: (helper: DevKaruraHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {93 return usingPlaygroundsGeneral<DevKaruraHelper>(DevAcalaHelper, url, code);94};9596export const usingMoonbeamPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {97 return usingPlaygroundsGeneral<DevMoonbeamHelper>(DevMoonbeamHelper, url, code);98};99100export const usingMoonriverPlaygrounds = (url: string, code: (helper: DevMoonbeamHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {101 return usingPlaygroundsGeneral<DevMoonriverHelper>(DevMoonriverHelper, url, code);102};103104export const usingAstarPlaygrounds = (url: string, code: (helper: DevAstarHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {105 return usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);106};107108export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {109 return usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);110};111112export const MINIMUM_DONOR_FUND = 100_000n;113export const DONOR_FUNDING = 2_000_000n;114115// App-promotion periods:116export const LOCKING_PERIOD = 12n; // 12 blocks of relay117export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain118119// Native contracts120export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';121export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';122123export enum Pallets {124 Inflation = 'inflation',125 ReFungible = 'refungible',126 Fungible = 'fungible',127 NFT = 'nonfungible',128 Scheduler = 'scheduler',129 AppPromotion = 'apppromotion',130 CollatorSelection = 'collatorselection',131 Session = 'session',132 Identity = 'identity',133 Preimage = 'preimage',134 Maintenance = 'maintenance',135 TestUtils = 'testutils',136}137138export function requirePalletsOrSkip(test: Context, helper: DevUniqueHelper, requiredPallets: string[]) {139 const missingPallets = helper.fetchMissingPalletNames(requiredPallets);140141 if (missingPallets.length > 0) {142 const skipMsg = `\tSkipping test '${test.test?.title}'.\n\tThe following pallets are missing:\n\t- ${missingPallets.join('\n\t- ')}`;143 console.warn('\x1b[38:5:208m%s\x1b[0m', skipMsg);144 test.skip();145 }146}147148export function itSub(name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {149 (opts.only ? it.only :150 opts.skip ? it.skip : it)(name, async function () {151 await usingPlaygrounds(async (helper, privateKey) => {152 if (opts.requiredPallets) {153 requirePalletsOrSkip(this, helper, opts.requiredPallets);154 }155156 await cb({helper, privateKey});157 });158 });159}160export function itSubIfWithPallet(name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {161 return itSub(name, cb, {requiredPallets: required, ...opts});162}163itSub.only = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {only: true});164itSub.skip = (name: string, cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSub(name, cb, {skip: true});165166itSubIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {only: true});167itSubIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSubIfWithPallet(name, required, cb, {skip: true});168itSub.ifWithPallets = itSubIfWithPallet;169170export type SchedKind = 'anon' | 'named';171172export function itSched(173 name: string,174 cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any,175 opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {},176) {177 itSub(name + ' (anonymous scheduling)', (apis) => cb('anon', apis), opts);178 itSub(name + ' (named scheduling)', (apis) => cb('named', apis), opts);179}180itSched.only = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {only: true});181itSched.skip = (name: string, cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any) => itSched(name, cb, {skip: true});182itSched.ifWithPallets = itSchedIfWithPallets;183184function itSchedIfWithPallets(name: string, required: string[], cb: (schedKind: SchedKind, apis: { helper: DevUniqueHelper, privateKey: (seed: string) => Promise<IKeyringPair> }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {185 return itSched(name, cb, {requiredPallets: required, ...opts});186}187188export function describeXCM(title: string, fn: (this: Mocha.Suite) => void, opts: {skip?: boolean} = {}) {189 (process.env.RUN_XCM_TESTS && !opts.skip190 ? describe191 : describe.skip)(title, fn);192}193194describeXCM.skip = (name: string, fn: (this: Mocha.Suite) => void) => describeXCM(name, fn, {skip: true});195196export function sizeOfInt(i: number) {197 if (i < 0 || i > 0xffffffff) throw new Error('out of range');198 if(i < 0b11_1111) {199 return 1;200 } else if (i < 0b11_1111_1111_1111) {201 return 2;202 } else if (i < 0b11_1111_1111_1111_1111_1111_1111_1111) {203 return 4;204 } else {205 return 5;206 }207}208209const UTF8_ENCODER = new TextEncoder();210export function sizeOfEncodedStr(v: string) {211 const encoded = UTF8_ENCODER.encode(v);212 return sizeOfInt(encoded.length) + encoded.length;213}214215export function sizeOfProperty(prop: {key: string, value: string}) {216 return sizeOfEncodedStr(prop.key) + sizeOfEncodedStr(prop.value);217}218219export function makeNames(url: string) {220 const filename = fileURLToPath(url);221 return {222 filename,223 dirname: dirname(filename),224 };225}tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -184,6 +184,17 @@
}
}
+export class DevShidenHelper extends AstarHelper {
+ wait: WaitGroup;
+
+ constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {
+ options.helperBase = options.helperBase ?? DevShidenHelper;
+
+ super(logger, options);
+ this.wait = new WaitGroup(this);
+ }
+}
+
export class DevAcalaHelper extends AcalaHelper {
wait: WaitGroup;
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -18,7 +18,7 @@
import {blake2AsHex} from '@polkadot/util-crypto';
import config from '../config';
import {XcmV2TraitsError} from '../interfaces';
-import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingAstarPlaygrounds} from '../util';
+import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';
const QUARTZ_CHAIN = 2095;
const STATEMINE_CHAIN = 1000;
@@ -983,19 +983,28 @@
describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
let alice: IKeyringPair;
- let randomAccount: IKeyringPair;
+ let sender: IKeyringPair;
+
+ // Quartz -> Shiden
+ const shidenInitialBalance = 1n * (10n ** 18n); // 1 SHD, existencial deposit required in order to perform XCM call
+ const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
+ const qtzToShidenTransferred = 10n * (10n ** 18n); // 10 QTZ
+ const qtzToShidenArrived = 9_999_999_999_088_000_000n; // 9.999 ... QTZ, Shiden takes a commision in foreign tokens
+ const senderIinitialBalanceQTZ = 100n * (10n ** 18n); // How many QTZ sender has initially
+ const senderBalanceAfterXCM = 89_941967662676666465n; // 89.94... QTZ after XCM call
- const shidenInitialBalance = 1n * (10n ** 18n);
- const qtzToShidenAmount = 10n * (10n ** 18n);
+ // Shiden -> Quartz
+ const qtzFromShidenTransfered = 5n * (10n ** 18n); // 5 QTZ
+ const qtzOnShidenLeft = qtzToShidenArrived - qtzFromShidenTransfered; // 4.999_999_999_088_000_000n QTZ
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
alice = await privateKey('//Alice');
- [randomAccount] = await helper.arrange.createAccounts([100n], alice);
- console.log('randomAccount', randomAccount.address);
+ [sender] = await helper.arrange.createAccounts([100n], alice);
+ console.log('sender', sender.address);
});
- await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+ await usingShidenPlaygrounds(shidenUrl, async (helper) => {
console.log('1. Create foreign asset and metadata');
await helper.assets.create(
alice,
@@ -1027,12 +1036,10 @@
await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
console.log('3. Set payment for computation');
- // TODO this is Phala's price, what price will be for Unique?
- const unitsPerSecond = 228_000_000_000n;
await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
console.log('4. Transfer 1 SDN to recepient');
- await helper.balance.transferToSubstrate(alice, randomAccount.address, shidenInitialBalance);
+ await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);
});
});
@@ -1055,7 +1062,7 @@
X1: {
AccountId32: {
network: 'Any',
- id: randomAccount.addressRaw,
+ id: sender.addressRaw,
},
},
},
@@ -1072,34 +1079,42 @@
},
},
fun: {
- Fungible: qtzToShidenAmount,
+ Fungible: qtzToShidenTransferred,
},
},
],
};
- // Initial balance is 100 UNQ
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));
+ // Initial balance is 100 QTZ
+ const balanceBefore = await helper.balance.getSubstrate(sender.address);
+ console.log(`Initial balance is: ${balanceBefore}`);
+ expect(balanceBefore).to.eq(senderIinitialBalanceQTZ);
const feeAssetItem = 0;
- await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
+ await helper.xcm.limitedReserveTransferAssets(sender, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
// Balance after reserve transfer is less than 90
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);
+ const balanceAfter = await helper.balance.getSubstrate(sender.address);
+ console.log(`QTZ Balance on Quartz after XCM is: ${balanceAfter}`);
+ console.log(`Quartz's QTZ commission is: ${balanceBefore - balanceAfter}`);
+ expect(balanceAfter).to.eq(senderBalanceAfterXCM);
- await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+ await usingShidenPlaygrounds(shidenUrl, async (helper) => {
await helper.wait.newBlocks(3);
- const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
- const astarBalance = await helper.balance.getSubstrate(randomAccount.address);
+ const xcQTZbalance = await helper.assets.account(1, sender.address);
+ const shidenBalance = await helper.balance.getSubstrate(sender.address);
- expect(xcUNQbalance).to.eq(9_999_999_999_088_000_000n);
- // Astar balance does not changed
- expect(astarBalance).to.eq(1_000_000_000_000_000_000n);
+ console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
+ console.log(`Shiden's QTZ commission is: ${qtzToShidenTransferred - xcQTZbalance!}`);
+
+ expect(xcQTZbalance).to.eq(qtzToShidenArrived);
+ // SHD balance does not changed:
+ expect(shidenBalance).to.eq(shidenInitialBalance);
});
});
itSub.only('Should connect to Shiden and send QTZ back', async ({helper}) => {
- await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+ await usingShidenPlaygrounds(shidenUrl, async (helper) => {
const destination = {
V1: {
parents: 1,
@@ -1118,7 +1133,7 @@
X1: {
AccountId32: {
network: 'Any',
- id: randomAccount.addressRaw,
+ id: sender.addressRaw,
},
},
},
@@ -1139,30 +1154,35 @@
},
},
fun: {
- Fungible: 5_000_000_000_000_000_000n,
+ Fungible: qtzFromShidenTransfered,
},
},
],
};
// Initial balance is 1 SDN
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
+ const balanceSDNbefore = await helper.balance.getSubstrate(sender.address);
+ console.log(`SDN balance is: ${balanceSDNbefore}, it does not changed`);
+ expect(balanceSDNbefore).to.eq(shidenInitialBalance);
const feeAssetItem = 0;
- await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
+ // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw
+ await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
// Balance after reserve transfer is less than 1 SDN
- const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
- const balanceSDN = await helper.balance.getSubstrate(randomAccount.address);
+ const xcQTZbalance = await helper.assets.account(1, sender.address);
+ const balanceSDN = await helper.balance.getSubstrate(sender.address);
+ console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
- // Assert: xcQTZ balance decreased
- expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
+ // Assert: xcQTZ balance correctly decreased
+ expect(xcQTZbalance).to.eq(qtzOnShidenLeft);
// Assert: SDN balance is 0.996...
expect(balanceSDN / (10n ** 15n)).to.eq(996n);
});
await helper.wait.newBlocks(3);
- const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
- expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
+ const balanceQTZ = await helper.balance.getSubstrate(sender.address);
+ console.log(`QTZ Balance on Quartz after XCM is: ${balanceQTZ}`);
+ expect(balanceQTZ).to.eq(senderBalanceAfterXCM + qtzFromShidenTransfered);
});
});
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -987,8 +987,17 @@
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
- const astarInitialBalance = 1n * (10n ** 18n);
- const unqToAstarAmount = 10n * (10n ** 18n);
+ // Unique -> Astar
+ const astarInitialBalance = 1n * (10n ** 18n); // 1 ASTR. Existencial deposit required in order to perform XCM call
+ const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
+ const unqToAstarTransferred = 10n * (10n ** 18n); // 10 UNQ
+ const unqToAstarArrived = 9_999_999_999_088_000_000n; // 9.999 ... UNQ, Shiden takes a commision in foreign tokens
+ const senderIinitialBalanceUNQ = 100n * (10n ** 18n); // How many UNQ sender has initially
+ const senderBalanceAfterXCM = 89_941967662676666465n; // 89.94... UNQ after XCM call
+
+ // Astar -> Unique
+ const unqFromAstarTransfered = 5n * (10n ** 18n); // 5 UNQ
+ const unqOnAstarLeft = unqToAstarArrived - unqFromAstarTransfered; // 4.999_999_999_088_000_000n UNQ
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
@@ -1029,8 +1038,6 @@
await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
console.log('3. Set payment for computation');
- // TODO this is Phala's price, what price will be for Unique?
- const unitsPerSecond = 228_000_000_000n;
await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
console.log('4. Transfer 1 ASTR to recepient');
@@ -1074,29 +1081,37 @@
},
},
fun: {
- Fungible: unqToAstarAmount,
+ Fungible: unqToAstarTransferred,
},
},
],
};
// Initial balance is 100 UNQ
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));
+ const balanceBefore = await helper.balance.getSubstrate(randomAccount.address);
+ console.log(`Initial balance is: ${balanceBefore}`);
+ expect(balanceBefore).to.eq(senderIinitialBalanceUNQ);
const feeAssetItem = 0;
await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
// Balance after reserve transfer is less than 90
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);
+ const balanceAfter = await helper.balance.getSubstrate(randomAccount.address);
+ console.log(`UNQ Balance on Unique after XCM is: ${balanceAfter}`);
+ console.log(`Unique's UNQ commission is: ${balanceBefore - balanceAfter}`);
+ expect(balanceAfter).to.eq(senderBalanceAfterXCM);
await usingAstarPlaygrounds(astarUrl, async (helper) => {
await helper.wait.newBlocks(3);
const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
const astarBalance = await helper.balance.getSubstrate(randomAccount.address);
- expect(xcUNQbalance).to.eq(9_999_999_999_088_000_000n);
+ console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);
+ console.log(`Astar's UNQ commission is: ${unqToAstarTransferred - xcUNQbalance!}`);
+
+ expect(xcUNQbalance).to.eq(unqToAstarArrived);
// Astar balance does not changed
- expect(astarBalance).to.eq(1_000_000_000_000_000_000n);
+ expect(astarBalance).to.eq(astarInitialBalance);
});
});
@@ -1141,30 +1156,35 @@
},
},
fun: {
- Fungible: 5_000_000_000_000_000_000n,
+ Fungible: unqFromAstarTransfered,
},
},
],
};
// Initial balance is 1 ASTR
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
+ const balanceASTRbefore = await helper.balance.getSubstrate(randomAccount.address);
+ console.log(`ASTR balance is: ${balanceASTRbefore}, it does not changed`);
+ expect(balanceASTRbefore).to.eq(astarInitialBalance);
const feeAssetItem = 0;
+ // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw
await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);
+ console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);
- // Assert: xcUNQ balance decreased
- expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
+ // Assert: xcUNQ balance correctly decreased
+ expect(xcUNQbalance).to.eq(unqOnAstarLeft);
// Assert: ASTR balance is 0.996...
expect(balanceAstar / (10n ** 15n)).to.eq(996n);
});
await helper.wait.newBlocks(3);
const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
- expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
+ console.log(`UNQ Balance on Unique after XCM is: ${balanceUNQ}`);
+ expect(balanceUNQ).to.eq(senderBalanceAfterXCM + unqFromAstarTransfered);
});
itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {
@@ -1208,30 +1228,18 @@
},
},
fun: {
- Fungible: 5_000_000_000_000_000_000n, // TODO set another value
+ Fungible: unqFromAstarTransfered,
},
},
],
};
// Initial balance is 1 ASTAR
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
+ expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(astarInitialBalance);
const feeAssetItem = 0;
+ // TODO: expect rejected:
await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
-
- // Balance after reserve transfer is less than 1 ASTAR
- const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
- const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);
-
- // xcUNQ balance decreased
- expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
- // Astar balance is 0.997...
- expect(balanceAstar / (10n ** 15n)).to.eq(997n);
});
-
- await helper.wait.newBlocks(3);
- const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
- expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
});
});