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.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -11,7 +11,7 @@
import config from '../config';
import {ChainHelperBase} from './playgrounds/unique';
import {ILogger} from './playgrounds/types';
-import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper} from './playgrounds/unique.dev';
+import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper, DevShidenHelper} from './playgrounds/unique.dev';
import {dirname} from 'path';
import {fileURLToPath} from 'url';
@@ -105,6 +105,9 @@
return usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);
};
+export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
+ return usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);
+};
export const MINIMUM_DONOR_FUND = 100_000n;
export const DONOR_FUNDING = 2_000_000n;
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.tsdiffbeforeafterboth18import {blake2AsHex} from '@polkadot/util-crypto';18import {blake2AsHex} from '@polkadot/util-crypto';19import config from '../config';19import config from '../config';20import {XcmV2TraitsError} from '../interfaces';20import {XcmV2TraitsError} from '../interfaces';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingAstarPlaygrounds} from '../util';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';222223const QUARTZ_CHAIN = 2095;23const QUARTZ_CHAIN = 2095;24const STATEMINE_CHAIN = 1000;24const STATEMINE_CHAIN = 1000;983983984describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {984describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {985 let alice: IKeyringPair;985 let alice: IKeyringPair;986 let randomAccount: IKeyringPair;986 let sender: IKeyringPair;987987988 // Quartz -> Shiden988 const shidenInitialBalance = 1n * (10n ** 18n);989 const shidenInitialBalance = 1n * (10n ** 18n); // 1 SHD, existencial deposit required in order to perform XCM call990 const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?989 const qtzToShidenAmount = 10n * (10n ** 18n);991 const qtzToShidenTransferred = 10n * (10n ** 18n); // 10 QTZ992 const qtzToShidenArrived = 9_999_999_999_088_000_000n; // 9.999 ... QTZ, Shiden takes a commision in foreign tokens993 const senderIinitialBalanceQTZ = 100n * (10n ** 18n); // How many QTZ sender has initially994 const senderBalanceAfterXCM = 89_941967662676666465n; // 89.94... QTZ after XCM call995996 // Shiden -> Quartz997 const qtzFromShidenTransfered = 5n * (10n ** 18n); // 5 QTZ998 const qtzOnShidenLeft = qtzToShidenArrived - qtzFromShidenTransfered; // 4.999_999_999_088_000_000n QTZ990999991 before(async () => {1000 before(async () => {992 await usingPlaygrounds(async (helper, privateKey) => {1001 await usingPlaygrounds(async (helper, privateKey) => {993 alice = await privateKey('//Alice');1002 alice = await privateKey('//Alice');994 [randomAccount] = await helper.arrange.createAccounts([100n], alice);1003 [sender] = await helper.arrange.createAccounts([100n], alice);995 console.log('randomAccount', randomAccount.address);1004 console.log('sender', sender.address);996 });1005 });9971006998 await usingAstarPlaygrounds(shidenUrl, async (helper) => {1007 await usingShidenPlaygrounds(shidenUrl, async (helper) => {999 console.log('1. Create foreign asset and metadata');1008 console.log('1. Create foreign asset and metadata');1000 await helper.assets.create(1009 await helper.assets.create(1001 alice,1010 alice,1027 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);1036 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);102810371029 console.log('3. Set payment for computation');1038 console.log('3. Set payment for computation');1030 // TODO this is Phala's price, what price will be for Unique?1031 const unitsPerSecond = 228_000_000_000n;1032 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1039 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);103310401034 console.log('4. Transfer 1 SDN to recepient');1041 console.log('4. Transfer 1 SDN to recepient');1035 await helper.balance.transferToSubstrate(alice, randomAccount.address, shidenInitialBalance);1042 await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);1036 });1043 });1037 });1044 });103810451055 X1: {1062 X1: {1056 AccountId32: {1063 AccountId32: {1057 network: 'Any',1064 network: 'Any',1058 id: randomAccount.addressRaw,1065 id: sender.addressRaw,1059 },1066 },1060 },1067 },1061 },1068 },1072 },1079 },1073 },1080 },1074 fun: {1081 fun: {1075 Fungible: qtzToShidenAmount,1082 Fungible: qtzToShidenTransferred,1076 },1083 },1077 },1084 },1078 ],1085 ],1079 };1086 };108010871081 // Initial balance is 100 UNQ1088 // Initial balance is 100 QTZ1082 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));1089 const balanceBefore = await helper.balance.getSubstrate(sender.address);1090 console.log(`Initial balance is: ${balanceBefore}`);1091 expect(balanceBefore).to.eq(senderIinitialBalanceQTZ);108310921084 const feeAssetItem = 0;1093 const feeAssetItem = 0;1085 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');1094 await helper.xcm.limitedReserveTransferAssets(sender, destination, beneficiary, assets, feeAssetItem, 'Unlimited');108610951087 // Balance after reserve transfer is less than 901096 // Balance after reserve transfer is less than 901088 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);1097 const balanceAfter = await helper.balance.getSubstrate(sender.address);1098 console.log(`QTZ Balance on Quartz after XCM is: ${balanceAfter}`);1099 console.log(`Quartz's QTZ commission is: ${balanceBefore - balanceAfter}`);1100 expect(balanceAfter).to.eq(senderBalanceAfterXCM);108911011090 await usingAstarPlaygrounds(shidenUrl, async (helper) => {1102 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1091 await helper.wait.newBlocks(3);1103 await helper.wait.newBlocks(3);1092 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1104 const xcQTZbalance = await helper.assets.account(1, sender.address);1093 const astarBalance = await helper.balance.getSubstrate(randomAccount.address);1105 const shidenBalance = await helper.balance.getSubstrate(sender.address);11061107 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);1108 console.log(`Shiden's QTZ commission is: ${qtzToShidenTransferred - xcQTZbalance!}`);109411091095 expect(xcUNQbalance).to.eq(9_999_999_999_088_000_000n);1110 expect(xcQTZbalance).to.eq(qtzToShidenArrived);1096 // Astar balance does not changed1111 // SHD balance does not changed:1097 expect(astarBalance).to.eq(1_000_000_000_000_000_000n);1112 expect(shidenBalance).to.eq(shidenInitialBalance);1098 });1113 });1099 });1114 });110011151101 itSub.only('Should connect to Shiden and send QTZ back', async ({helper}) => {1116 itSub.only('Should connect to Shiden and send QTZ back', async ({helper}) => {1102 await usingAstarPlaygrounds(shidenUrl, async (helper) => {1117 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1103 const destination = {1118 const destination = {1104 V1: {1119 V1: {1105 parents: 1,1120 parents: 1,1118 X1: {1133 X1: {1119 AccountId32: {1134 AccountId32: {1120 network: 'Any',1135 network: 'Any',1121 id: randomAccount.addressRaw,1136 id: sender.addressRaw,1122 },1137 },1123 },1138 },1124 },1139 },1139 },1154 },1140 },1155 },1141 fun: {1156 fun: {1142 Fungible: 5_000_000_000_000_000_000n,1157 Fungible: qtzFromShidenTransfered,1143 },1158 },1144 },1159 },1145 ],1160 ],1146 };1161 };114711621148 // Initial balance is 1 SDN1163 // Initial balance is 1 SDN1149 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);1164 const balanceSDNbefore = await helper.balance.getSubstrate(sender.address);1165 console.log(`SDN balance is: ${balanceSDNbefore}, it does not changed`);1166 expect(balanceSDNbefore).to.eq(shidenInitialBalance);115011671151 const feeAssetItem = 0;1168 const feeAssetItem = 0;1169 // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw1152 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);1170 await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);115311711154 // Balance after reserve transfer is less than 1 SDN1172 // Balance after reserve transfer is less than 1 SDN1155 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1173 const xcQTZbalance = await helper.assets.account(1, sender.address);1156 const balanceSDN = await helper.balance.getSubstrate(randomAccount.address);1174 const balanceSDN = await helper.balance.getSubstrate(sender.address);1175 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);115711761158 // Assert: xcQTZ balance decreased1177 // Assert: xcQTZ balance correctly decreased1159 expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);1178 expect(xcQTZbalance).to.eq(qtzOnShidenLeft);1160 // Assert: SDN balance is 0.996...1179 // Assert: SDN balance is 0.996...1161 expect(balanceSDN / (10n ** 15n)).to.eq(996n);1180 expect(balanceSDN / (10n ** 15n)).to.eq(996n);1162 });1181 });116311821164 await helper.wait.newBlocks(3);1183 await helper.wait.newBlocks(3);1165 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);1184 const balanceQTZ = await helper.balance.getSubstrate(sender.address);1185 console.log(`QTZ Balance on Quartz after XCM is: ${balanceQTZ}`);1166 expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);1186 expect(balanceQTZ).to.eq(senderBalanceAfterXCM + qtzFromShidenTransfered);1167 });1187 });1168});1188});11691189tests/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);
});
});