From 9d21d162f0c0c332b97ecb47dfa0ce4e4f3666bd Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:41:22 +0100 Subject: [PATCH] feat: add initial TODO for testing WETH --- .../chopsticks/overrides/polkadot-hub.ts | 1 + integration-tests/chopsticks/src/constants.ts | 14 +++--- integration-tests/chopsticks/src/setup.ts | 1 + .../chopsticks/src/transfers/HubToPolimec.ts | 2 +- .../src/transfers/PolkadotToPolimec.ts | 1 - integration-tests/chopsticks/src/types.ts | 16 +++++++ integration-tests/chopsticks/src/utils.ts | 45 ++++++++++--------- 7 files changed, 52 insertions(+), 28 deletions(-) diff --git a/integration-tests/chopsticks/overrides/polkadot-hub.ts b/integration-tests/chopsticks/overrides/polkadot-hub.ts index be4e465ca..9fb9a8a41 100644 --- a/integration-tests/chopsticks/overrides/polkadot-hub.ts +++ b/integration-tests/chopsticks/overrides/polkadot-hub.ts @@ -37,4 +37,5 @@ export const polkadot_hub_storage = { ], ], }, + // TODO: Add the foreignAssets storage to give to ALICE WETH = INITIAL_BALANCES.WETH } as const; diff --git a/integration-tests/chopsticks/src/constants.ts b/integration-tests/chopsticks/src/constants.ts index b36870118..4c8b2f611 100644 --- a/integration-tests/chopsticks/src/constants.ts +++ b/integration-tests/chopsticks/src/constants.ts @@ -1,15 +1,17 @@ import { Accounts } from '@/types'; export const INITIAL_BALANCES = { - USDT: 52000000000n, - USDC: 66600000000n, - DOT: 10000000000000000n, - PLMC: 10000000000000000n, + USDT: 52000n * 10n ** 6n, + USDC: 66000n * 10n ** 6n, + DOT: 1000000n * 10n ** 10n, + PLMC: 1000000n * 10n ** 10n, + WETH: 2n * 10n ** 18n, } as const; export const TRANSFER_AMOUNTS = { - TOKENS: 2000000n, - NATIVE: 20000000000n, + TOKENS: 2n * 10n ** 6n, // e.g. 2 USDC + NATIVE: 2n * 10n ** 10n, // e.g. 2 DOT + BRIDGED: 1n * 10n ** 17n, // e.g. 0.1 WETH } as const; export const DERIVE_PATHS = { diff --git a/integration-tests/chopsticks/src/setup.ts b/integration-tests/chopsticks/src/setup.ts index fc49c8657..5f2119656 100644 --- a/integration-tests/chopsticks/src/setup.ts +++ b/integration-tests/chopsticks/src/setup.ts @@ -60,6 +60,7 @@ export class ChainSetup { private async setupPolimec(polimec_storage: unknown) { const file = Bun.file(POLIMEC_WASM); + // Note: the tests are inteded to use a pre-production, locally compiled runtime, that's why we throw an error. if (!(await file.exists())) { throw new Error( 'Polimec runtime not found! Please build it by running `cargo b -r -p polimec-runtime` before executing the tests.', diff --git a/integration-tests/chopsticks/src/transfers/HubToPolimec.ts b/integration-tests/chopsticks/src/transfers/HubToPolimec.ts index fb28ee785..f3793759f 100644 --- a/integration-tests/chopsticks/src/transfers/HubToPolimec.ts +++ b/integration-tests/chopsticks/src/transfers/HubToPolimec.ts @@ -62,7 +62,7 @@ export class HubToPolimecTransfer extends BaseTransferTest { async verifyFinalBalances( initialBalances: PolimecBalanceCheck, finalBalances: PolimecBalanceCheck, - { amount, asset }: HubTransferOptions, + { asset }: HubTransferOptions, ) { // TODO: At the moment we exclude fees from the balance check since the PAPI team is wotking on some utilies to calculate fees. const initialBalance = diff --git a/integration-tests/chopsticks/src/transfers/PolkadotToPolimec.ts b/integration-tests/chopsticks/src/transfers/PolkadotToPolimec.ts index cf44260c8..7e777019f 100644 --- a/integration-tests/chopsticks/src/transfers/PolkadotToPolimec.ts +++ b/integration-tests/chopsticks/src/transfers/PolkadotToPolimec.ts @@ -54,7 +54,6 @@ export class PolkadotToPolimecTransfer extends BaseTransferTest { ]); }; -const createHubAssets = (amount: bigint, assetIndex?: bigint): XcmVersionedAssets => +// TODO: Modify this function to allow the creation of an XcmVersionedAssets that supports also WETH/bridged assets. +const createHubAssets = ({ + amount, + assetIndex, + isFromBridge, +}: CreateAssetsParams): XcmVersionedAssets => XcmVersionedAssets.V3([ { fun: XcmV3MultiassetFungibility.Fungible(amount), @@ -67,7 +78,7 @@ const createHubAssets = (amount: bigint, assetIndex?: bigint): XcmVersionedAsset }, ]); -const createDotAssets = (amount: bigint): XcmVersionedAssets => +const createDotAssets = ({ amount }: CreateAssetsParams): XcmVersionedAssets => XcmVersionedAssets.V3([ { fun: XcmV3MultiassetFungibility.Fungible(amount), @@ -78,8 +89,11 @@ const createDotAssets = (amount: bigint): XcmVersionedAssets => }, ]); -const createPolimecAssets = (amount: bigint, assetIndex = 1984n): XcmVersionedAssets => - XcmVersionedAssets.V3([ +const createPolimecAssets = ({ amount, assetIndex }: CreateAssetsParams): XcmVersionedAssets => { + if (!assetIndex) { + throw new Error('You need to specify an Asset ID while creating an asset for Polimec'); + } + return XcmVersionedAssets.V3([ { id: XcmV3MultiassetAssetId.Concrete({ parents: 1, @@ -95,14 +109,7 @@ const createPolimecAssets = (amount: bigint, assetIndex = 1984n): XcmVersionedAs fun: XcmV3MultiassetFungibility.Fungible(amount), }, ]); - -interface TransferDataParams { - amount: bigint; - toChain: Chains; - assetIndex?: bigint; - recv?: Accounts; - isMultiHop?: boolean; -} +}; export const createTransferData = ({ amount, toChain, assetIndex, recv }: TransferDataParams) => { if (toChain === Chains.Polkadot) { @@ -128,24 +135,22 @@ export const createTransferData = ({ amount, toChain, assetIndex, recv }: Transf beneficiary, assets: toChain === Chains.PolkadotHub - ? createPolimecAssets(amount, assetIndex) - : createHubAssets(amount, assetIndex), + ? createPolimecAssets({ amount, assetIndex }) + : createHubAssets({ amount, assetIndex }), fee_asset_item: 0, weight_limit: XcmV3WeightLimit.Unlimited(), }; }; -export const createMultiHopTransferData = ({ amount, toChain }: TransferDataParams) => { - if (toChain === Chains.Polkadot) { - throw new Error('The Multi Hop destination cannot be Polkadot'); - } +export const createMultiHopTransferData = ({ amount }: TransferDataParams) => { const dest = XcmVersionedLocation.V3({ parents: 0, interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(ParaId[Chains.PolkadotHub])), }); + return { dest, - assets: createDotAssets(amount), + assets: createDotAssets({ amount }), assets_transfer_type: Enum('Teleport'), remote_fees_id: XcmVersionedAssetId.V3( XcmV3MultiassetAssetId.Concrete({