Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 committed Jan 11, 2024
1 parent e0ea727 commit 7f41851
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 112 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const balanceTracker = async (
if (!balance) {
for (const assetId of assetIds) {
accountInfo = await api.query.poolAssets.account(assetId, address);
console.log(accountInfo.value.toHuman())
console.log(accountInfo.value.toHuman());
if (accountInfo.isNone) {
balances.initial.push([assetId, 0]);
} else {
Expand Down
8 changes: 3 additions & 5 deletions e2e-tests/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

export const KUSAMA_ASSET_HUB_WS_URL = 'ws://127.0.0.1:9911';
export const ROCOCO_ALICE_WS_URL = 'ws://127.0.0.1:9900';
export const ROCOCO_ASSET_HUB_WS_URL = 'ws://127.0.0.1:9921';
export const TRAPPIST_WS_URL = 'ws://127.0.0.1:9921';
export const MOONRIVER_WS_URL = 'ws://127.0.0.1:9931';

export const BOB_ROC_ADDR = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
export const FERDE_ROC_ADDR = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';
export const BOB_KAH_ADDR = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
export const FERDE_KAH_ADDR = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';
export const BOB_ADDR = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
export const FERDE_ADDR = '5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL';

export const ASSET_ID = 1;

Expand Down
18 changes: 8 additions & 10 deletions e2e-tests/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cryptoWaitReady } from '@polkadot/util-crypto';
import { delay } from '../scripts/util';
import { constructApiPromise } from '../src';
import { balanceTracker, IBalance } from './balance';
import { KUSAMA_ASSET_HUB_WS_URL, MOONRIVER_WS_URL, ROCOCO_ALICE_WS_URL, ROCOCO_ASSET_HUB_WS_URL } from './consts';
import { KUSAMA_ASSET_HUB_WS_URL, MOONRIVER_WS_URL, ROCOCO_ALICE_WS_URL, TRAPPIST_WS_URL } from './consts';
import { assetTests, foreignAssetsTests, IndividualTest, liquidPoolsTests, localTests, tests } from './tests';
import { verification } from './verification';

Expand All @@ -16,7 +16,7 @@ const executor = async (testCase: string) => {
let destWsUrl = '';

let testData: IndividualTest[] = [];
console.log(testCase)
console.log(testCase);

await cryptoWaitReady();

Expand Down Expand Up @@ -70,10 +70,9 @@ const executor = async (testCase: string) => {
destAddr = t.args[3];
assetIds = t.args[4].slice(1, -1).split(',');
amounts = t.args[5].slice(1, -1).split(',');
opts = JSON.parse(t.args[6], (key, value) => {
return key === "paysWithFeeOrigin" ? JSON.stringify(value) : value;
}) as object;

opts = JSON.parse(t.args[6], (key: string, value: string) => {
return key === 'paysWithFeeOrigin' ? JSON.stringify(value) : value;
}) as object;

switch (originChainId) {
case '0':
Expand All @@ -83,7 +82,7 @@ const executor = async (testCase: string) => {
originWsUrl = KUSAMA_ASSET_HUB_WS_URL;
break;
case '1836':
originWsUrl = ROCOCO_ASSET_HUB_WS_URL;
originWsUrl = TRAPPIST_WS_URL;
break;
case '4000':
originWsUrl = MOONRIVER_WS_URL;
Expand All @@ -101,7 +100,7 @@ const executor = async (testCase: string) => {
destWsUrl = KUSAMA_ASSET_HUB_WS_URL;
break;
case '1836':
destWsUrl = ROCOCO_ASSET_HUB_WS_URL;
destWsUrl = TRAPPIST_WS_URL;
break;
case '4000':
destWsUrl = MOONRIVER_WS_URL;
Expand All @@ -110,7 +109,6 @@ const executor = async (testCase: string) => {
}
const { api, specName, safeXcmVersion } = await constructApiPromise(originWsUrl);

let sanitizedSpecName = originChainId === '1836' ? 'asset-hub-rococo' : specName;
await api.isReady;

const originApi = api;
Expand All @@ -127,7 +125,7 @@ const executor = async (testCase: string) => {
const originKeyring = keyring.addFromUri(originAddr);

//eslint-disable-next-line @typescript-eslint/no-unsafe-call
await n[t.test](originKeyring, destChainId, destAddr, assetIds, amounts, opts, api, sanitizedSpecName, safeXcmVersion);
await n[t.test](originKeyring, destChainId, destAddr, assetIds, amounts, opts, api, specName, safeXcmVersion);

await delay(24000);

Expand Down
4 changes: 1 addition & 3 deletions e2e-tests/tests/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: numbe
},
};

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion,
{ injectedRegistry });

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion, { injectedRegistry });

return assetApi;
};
Expand Down
4 changes: 1 addition & 3 deletions e2e-tests/tests/foreignAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: numbe
},
};

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion,
{ injectedRegistry });

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion, { injectedRegistry });

return assetApi;
};
Expand Down
65 changes: 24 additions & 41 deletions e2e-tests/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { assetTests } from './assets';
export { foreignAssetsTests } from './foreignAssets';
export { liquidPoolsTests } from './liquidPools';
export { localTests } from './local';
import { BOB_KAH_ADDR, BOB_ROC_ADDR, FERDE_KAH_ADDR } from '../consts';
import { BOB_ADDR, FERDE_ADDR } from '../consts';

export interface IndividualTest {
test: string;
Expand All @@ -29,7 +29,7 @@ export const tests: TestGroups = {
'1836',
'1000',
'//Alice',
BOB_KAH_ADDR,
BOB_ADDR,
'[{ "parents": "1", "interior": { "X2": [{ "Parachain": "1836" }, { "GeneralIndex": "0" }]}}]',
'[200000000000]',
'{ "format": "submittable", "xcmVersion": 3 }',
Expand All @@ -40,70 +40,53 @@ export const tests: TestGroups = {
},
],
liquidPools: [
// {
// // This will declare the call to use
// test: 'createLocalTransferTransaction',
// // This will be all the args for the above call
// args: [
// '1000',
// '1000',
// '//Alice',
// BOB_KAH_ADDR,
// '[0]',
// '[2000]',
// '{ "format": "submittable", "transferLiquidToken": true }',
// ],
// // This will be a tuple that will allow us to verify if the xcm message
// // succesfully went through on the other end
// verification: ['[0]', '[2000]'],
// },
{
// This will declare the call to use
test: 'createPayFeesTransaction',
test: 'createLocalTransferTransaction',
// This will be all the args for the above call
args: [
'1000',
'1000',
'//Bob',
FERDE_KAH_ADDR,
'//Alice',
BOB_ADDR,
'[0]',
'[30000]',
'{ "format": "payload", "xcmVersion": 3, "transferLiquidToken": true, "paysWithFeeOrigin": { "parents": "0", "interior": { "X2": [{"PalletInstance": "50"}, { "GeneralIndex": "1" }]}}, "sendersAddr": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" }',
'[20000]',
'{ "format": "submittable", "transferLiquidToken": true }',
],
// This will be a tuple that will allow us to verify if the xcm message
// succesfully went through on the other end
verification: ['[0]', '[30000]'],
verification: ['[0]', '[2000]'],
},
],
local: [
{
// This will declare the call to use
test: 'createLocalTransferTransaction',
test: 'createPayFeesTransaction',
// This will be all the args for the above call
args: [
'1000',
'1000',
'//Alice',
BOB_KAH_ADDR,
'[]',
'[10000000000000]',
'{ "format": "submittable", "keepAlive": true }',
'//Bob',
FERDE_ADDR,
'[0]',
'[3000000]',
'{ "format": "payload", "xcmVersion": 3, "transferLiquidToken": true, "paysWithFeeOrigin": { "parents": "0", "interior": { "X2": [{"PalletInstance": "50"}, { "GeneralIndex": "1" }]}}, "sendersAddr": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" }',
],
// This will be a tuple that will allow us to verify if the xcm message
// succesfully went through on the other end
verification: ['[0]', '[10000000000000]'],
verification: ['[0]', '[3000000]'],
},
],
local: [
{
// This will declare the call to use
test: 'createLocalTransferTransaction',
// This will be all the args for the above call
args: [
'1836',
'1836',
'1000',
'1000',
'//Alice',
BOB_KAH_ADDR,
BOB_ADDR,
'[]',
'[100000000000000000]',
'[100000000000]',
'{ "format": "submittable", "keepAlive": true }',
],
// This will be a tuple that will allow us to verify if the xcm message
Expand All @@ -118,7 +101,7 @@ export const tests: TestGroups = {
'0',
'0',
'//Alice',
BOB_KAH_ADDR,
BOB_ADDR,
'[]',
'[100000000000000000]',
'{ "format": "submittable", "keepAlive": true }',
Expand All @@ -137,7 +120,7 @@ export const tests: TestGroups = {
'1000',
'1000',
'//Alice',
BOB_ROC_ADDR,
BOB_ADDR,
'[1]',
'[3000000000000]',
'{ "format": "submittable", "keepAlive": true }',
Expand All @@ -154,7 +137,7 @@ export const tests: TestGroups = {
'1000',
'1000',
'//Bob',
FERDE_KAH_ADDR,
FERDE_ADDR,
'[1]',
'[200000000000]',
'{ "format": "submittable", "keepAlive": true }',
Expand Down
35 changes: 7 additions & 28 deletions e2e-tests/tests/liquidPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: numbe
},
};

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion,
{ injectedRegistry });

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion, { injectedRegistry });

return assetApi;
};
Expand Down Expand Up @@ -61,36 +59,17 @@ const createPayFeesTransaction = async (
) => {
const assetApi = createAssetApi(api, specName, safeXcmVersion);

let localTransferInfo: TxResult<'payload'>;
let transferInfo: TxResult<'payload'>;
try {
let sender: string;
if (opts["sendersAddr"] === undefined) {
sender = ''
} else {
sender = opts["sendersAddr"];
}

localTransferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);
console.log(localTransferInfo.tx)
transferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);

const payload = api.createType('ExtrinsicPayload', localTransferInfo.tx, {
const payload = api.createType('ExtrinsicPayload', transferInfo.tx, {
version: 4,
})

const message = payload.toU8a({ method: true });

const signat = origin.sign(message, { withType: true });

const extrinsic = api.createType(
'Extrinsic',
{ method: localTransferInfo.method },
{ version: 4 }
).addSignature(sender, signat, localTransferInfo.tx);

const tx = extrinsic.toHex()
});

await api.rpc.author.submitExtrinsic(tx);
const extrinsic = api.registry.createType('Extrinsic', { method: payload.method }, { version: 4 });

await api.tx(extrinsic).signAndSend(origin);
} catch (e) {
console.error(e);
throw Error(e as string);
Expand Down
5 changes: 1 addition & 4 deletions e2e-tests/tests/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { AssetTransferApi } from '../../src';
import { TxResult } from '../../src/types';

const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: number): AssetTransferApi => {

const injectedRegistry = {
rococo: {
'1836': {
Expand All @@ -20,9 +19,7 @@ const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: numbe
},
};

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion,
{ injectedRegistry });

const assetApi = new AssetTransferApi(api, specName, safeXcmVersion, { injectedRegistry });

return assetApi;
};
Expand Down
7 changes: 6 additions & 1 deletion scripts/testNetworkForeignAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ const fAssetSetMetadataCall = (assetHubApi: ApiPromise): `0x${string}` => {
},
};

const setMetadataTx = assetHubApi.tx.foreignAssets.setMetadata(rockmineMultilocatino, 'Asset Hub Rococo Hop', 'Hop', 12);
const setMetadataTx = assetHubApi.tx.foreignAssets.setMetadata(
rockmineMultilocatino,
'Asset Hub Rococo Hop',
'Hop',
12,
);

const hexCall = assetHubApi.registry
.createType('Call', {
Expand Down
22 changes: 9 additions & 13 deletions src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ export class AssetTransferApi {
'CheckMortality',
'CheckNonce',
'CheckWeight',
'ChargeTransactionPayment',
'ChargeAssetTxPayment',
],
tip: this._api.registry.createType('Compact<Balance>', 0).toHex(),
version: tx.version,
Expand Down Expand Up @@ -898,20 +898,16 @@ export class AssetTransferApi {

if (this._api.query.assetConversion !== undefined) {
try {
for (const poolPairsData of await this._api.query.assetConversion.pools.keys()) {
const poolStorageKeyData = poolPairsData.toHuman();
for (const poolPairsData of await this._api.query.assetConversion.pools.entries()) {
const tokenPairs = poolPairsData[0];

// remove any commas from multilocation key values e.g. Parachain: 2,125 -> Parachain: 2125
const poolAssetDataStr = JSON.stringify(poolStorageKeyData).replace(/(\d),/g, '$1');
const firstLpTokenSlice = poolAssetDataStr.slice(2, -2).slice(0, poolAssetDataStr.indexOf('},{"p') -1);
const secondLpTokenSlice = poolAssetDataStr.slice(2, -2).slice(poolAssetDataStr.indexOf('},{"p'));

const firstLpToken = sanitizeKeys(
JSON.parse(firstLpTokenSlice),
) as UnionXcmMultiLocation;
const secondLpToken = sanitizeKeys(
JSON.parse(secondLpTokenSlice),
) as UnionXcmMultiLocation;
const sanitizedTokenPairs = JSON.stringify(tokenPairs).replace(/(\d),/g, '$1');
const firstLpTokenSlice = sanitizedTokenPairs.slice(1, -1).slice(0, sanitizedTokenPairs.indexOf('},{"p'));
const secondLpTokenSlice = sanitizedTokenPairs.slice(1, -1).slice(sanitizedTokenPairs.indexOf(',{"p'));

const firstLpToken = sanitizeKeys(JSON.parse(firstLpTokenSlice)) as UnionXcmMultiLocation;
const secondLpToken = sanitizeKeys(JSON.parse(secondLpTokenSlice)) as UnionXcmMultiLocation;

if (
JSON.stringify(firstLpToken) == JSON.stringify(feeAsset) ||
Expand Down
6 changes: 3 additions & 3 deletions zombienet/medium-network.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ cumulus_based = true
id = 1836
add_to_genesis = true
cumulus_based = true
chain = "asset-hub-rococo-local"
chain = "trappist-local"

[[parachains.collators]]
name = "rockmine-collator01"
command = "./zombienet/bin/polkadot-parachain"
command = "./zombienet/bin/trappist-node"
ws_port = 9920
args = ["--log=xcm=trace,pallet-assets=trace"]

[[parachains.collators]]
name = "rockmine-collator02"
command = "./zombienet/bin/polkadot-parachain"
command = "./zombienet/bin/trappist-node"
ws_port = 9921
args = ["--log=xcm=trace,pallet-assets=trace"]

Expand Down

0 comments on commit 7f41851

Please sign in to comment.