From 7f41851498ef9526fc02bd138a20f2344758659e Mon Sep 17 00:00:00 2001 From: bee344 Date: Thu, 11 Jan 2024 20:08:11 -0300 Subject: [PATCH] linting --- e2e-tests/balance.ts | 2 +- e2e-tests/consts.ts | 8 ++-- e2e-tests/executor.ts | 18 ++++---- e2e-tests/tests/assets.ts | 4 +- e2e-tests/tests/foreignAssets.ts | 4 +- e2e-tests/tests/index.ts | 65 +++++++++++------------------ e2e-tests/tests/liquidPools.ts | 35 ++++------------ e2e-tests/tests/local.ts | 5 +-- scripts/testNetworkForeignAssets.ts | 7 +++- src/AssetTransferApi.ts | 22 ++++------ zombienet/medium-network.toml | 6 +-- 11 files changed, 64 insertions(+), 112 deletions(-) diff --git a/e2e-tests/balance.ts b/e2e-tests/balance.ts index 56a73664..0a707d61 100644 --- a/e2e-tests/balance.ts +++ b/e2e-tests/balance.ts @@ -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 { diff --git a/e2e-tests/consts.ts b/e2e-tests/consts.ts index 805188ff..a5b0e510 100644 --- a/e2e-tests/consts.ts +++ b/e2e-tests/consts.ts @@ -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; diff --git a/e2e-tests/executor.ts b/e2e-tests/executor.ts index 95b1f54e..694a9b1a 100644 --- a/e2e-tests/executor.ts +++ b/e2e-tests/executor.ts @@ -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'; @@ -16,7 +16,7 @@ const executor = async (testCase: string) => { let destWsUrl = ''; let testData: IndividualTest[] = []; - console.log(testCase) + console.log(testCase); await cryptoWaitReady(); @@ -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': @@ -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; @@ -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; @@ -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; @@ -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); diff --git a/e2e-tests/tests/assets.ts b/e2e-tests/tests/assets.ts index baa0b557..998f73f9 100644 --- a/e2e-tests/tests/assets.ts +++ b/e2e-tests/tests/assets.ts @@ -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; }; diff --git a/e2e-tests/tests/foreignAssets.ts b/e2e-tests/tests/foreignAssets.ts index 988255d7..849bf089 100644 --- a/e2e-tests/tests/foreignAssets.ts +++ b/e2e-tests/tests/foreignAssets.ts @@ -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; }; diff --git a/e2e-tests/tests/index.ts b/e2e-tests/tests/index.ts index a16bf42f..2e2eacf1 100644 --- a/e2e-tests/tests/index.ts +++ b/e2e-tests/tests/index.ts @@ -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; @@ -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 }', @@ -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 @@ -118,7 +101,7 @@ export const tests: TestGroups = { '0', '0', '//Alice', - BOB_KAH_ADDR, + BOB_ADDR, '[]', '[100000000000000000]', '{ "format": "submittable", "keepAlive": true }', @@ -137,7 +120,7 @@ export const tests: TestGroups = { '1000', '1000', '//Alice', - BOB_ROC_ADDR, + BOB_ADDR, '[1]', '[3000000000000]', '{ "format": "submittable", "keepAlive": true }', @@ -154,7 +137,7 @@ export const tests: TestGroups = { '1000', '1000', '//Bob', - FERDE_KAH_ADDR, + FERDE_ADDR, '[1]', '[200000000000]', '{ "format": "submittable", "keepAlive": true }', diff --git a/e2e-tests/tests/liquidPools.ts b/e2e-tests/tests/liquidPools.ts index f662d6ec..51d7086b 100644 --- a/e2e-tests/tests/liquidPools.ts +++ b/e2e-tests/tests/liquidPools.ts @@ -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; }; @@ -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); diff --git a/e2e-tests/tests/local.ts b/e2e-tests/tests/local.ts index 4d1f9222..4ab1cdc7 100644 --- a/e2e-tests/tests/local.ts +++ b/e2e-tests/tests/local.ts @@ -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': { @@ -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; }; diff --git a/scripts/testNetworkForeignAssets.ts b/scripts/testNetworkForeignAssets.ts index 7e06af6f..286a89fe 100644 --- a/scripts/testNetworkForeignAssets.ts +++ b/scripts/testNetworkForeignAssets.ts @@ -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', { diff --git a/src/AssetTransferApi.ts b/src/AssetTransferApi.ts index 3005eeb9..53d60365 100644 --- a/src/AssetTransferApi.ts +++ b/src/AssetTransferApi.ts @@ -800,7 +800,7 @@ export class AssetTransferApi { 'CheckMortality', 'CheckNonce', 'CheckWeight', - 'ChargeTransactionPayment', + 'ChargeAssetTxPayment', ], tip: this._api.registry.createType('Compact', 0).toHex(), version: tx.version, @@ -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) || diff --git a/zombienet/medium-network.toml b/zombienet/medium-network.toml index 66d76990..a7cd04ae 100644 --- a/zombienet/medium-network.toml +++ b/zombienet/medium-network.toml @@ -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"]