Skip to content

Commit

Permalink
fix all directions
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Oct 25, 2023
1 parent 98e70b8 commit 4cee611
Show file tree
Hide file tree
Showing 38 changed files with 636 additions and 719 deletions.
4 changes: 2 additions & 2 deletions src/AssetTransferApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ describe('AssetTransferAPI', () => {
describe('feeAssetItem', () => {
it('Should correctly set the feeAssetItem when paysWithFeeDest option is provided for a limitedReserveTransferAssets call', async () => {
const expected =
'{"args":{"dest":{"V3":{"parents":"1","interior":{"X1":{"Parachain":"2,000"}}}},"beneficiary":{"V3":{"parents":"0","interior":{"X1":{"AccountId32":{"network":null,"id":"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"}}}}},"assets":{"V3":[{"id":{"Concrete":{"parents":"0","interior":{"X2":[{"PalletInstance":"50"},{"GeneralIndex":"11"}]}}},"fun":{"Fungible":"10,000,000,000,000"}},{"id":{"Concrete":{"parents":"1","interior":"Here"}},"fun":{"Fungible":"30,000,000,000,000"}}]},"fee_asset_item":"0","weight_limit":{"Limited":{"refTime":"1,000","proofSize":"1,000"}}},"method":"limitedReserveTransferAssets","section":"polkadotXcm"}';
"{\"args\":{\"dest\":{\"V3\":{\"parents\":\"1\",\"interior\":{\"X1\":{\"Parachain\":\"2,000\"}}}},\"beneficiary\":{\"V3\":{\"parents\":\"0\",\"interior\":{\"X1\":{\"AccountId32\":{\"network\":null,\"id\":\"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b\"}}}}},\"assets\":{\"V3\":[{\"id\":{\"Concrete\":{\"parents\":\"1\",\"interior\":\"Here\"}},\"fun\":{\"Fungible\":\"30,000,000,000,000\"}},{\"id\":{\"Concrete\":{\"parents\":\"0\",\"interior\":{\"X2\":[{\"PalletInstance\":\"50\"},{\"GeneralIndex\":\"11\"}]}}},\"fun\":{\"Fungible\":\"10,000,000,000,000\"}}]},\"fee_asset_item\":\"1\",\"weight_limit\":{\"Limited\":{\"refTime\":\"1,000\",\"proofSize\":\"1,000\"}}},\"method\":\"limitedReserveTransferAssets\",\"section\":\"polkadotXcm\"}";

Check failure on line 658 in src/AssetTransferApi.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"{\"args\":{\"dest\":{\"V3\":{\"parents\":\"1\",\"interior\":{\"X1\":{\"Parachain\":\"2,000\"}}}},\"beneficiary\":{\"V3\":{\"parents\":\"0\",\"interior\":{\"X1\":{\"AccountId32\":{\"network\":null,\"id\":\"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b\"}}}}},\"assets\":{\"V3\":[{\"id\":{\"Concrete\":{\"parents\":\"1\",\"interior\":\"Here\"}},\"fun\":{\"Fungible\":\"30,000,000,000,000\"}},{\"id\":{\"Concrete\":{\"parents\":\"0\",\"interior\":{\"X2\":[{\"PalletInstance\":\"50\"},{\"GeneralIndex\":\"11\"}]}}},\"fun\":{\"Fungible\":\"10,000,000,000,000\"}}]},\"fee_asset_item\":\"1\",\"weight_limit\":{\"Limited\":{\"refTime\":\"1,000\",\"proofSize\":\"1,000\"}}},\"method\":\"limitedReserveTransferAssets\",\"section\":\"polkadotXcm\"}"` with `↹'{"args":{"dest":{"V3":{"parents":"1","interior":{"X1":{"Parachain":"2,000"}}}},"beneficiary":{"V3":{"parents":"0","interior":{"X1":{"AccountId32":{"network":null,"id":"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"}}}}},"assets":{"V3":[{"id":{"Concrete":{"parents":"1","interior":"Here"}},"fun":{"Fungible":"30,000,000,000,000"}},{"id":{"Concrete":{"parents":"0","interior":{"X2":[{"PalletInstance":"50"},{"GeneralIndex":"11"}]}}},"fun":{"Fungible":"10,000,000,000,000"}}]},"fee_asset_item":"1","weight_limit":{"Limited":{"refTime":"1,000","proofSize":"1,000"}}},"method":"limitedReserveTransferAssets","section":"polkadotXcm"}'`
const callTxResult = await systemAssetsApi.createTransferTransaction(
'2000',
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
Expand All @@ -677,7 +677,7 @@ describe('AssetTransferAPI', () => {

it('Should correctly set the feeAssetItem when paysWithFeeDest option is provided for a reserveTransferAssets call', async () => {
const expected =
'{"args":{"dest":{"V3":{"parents":"1","interior":{"X1":{"Parachain":"2,000"}}}},"beneficiary":{"V3":{"parents":"0","interior":{"X1":{"AccountId32":{"network":null,"id":"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"}}}}},"assets":{"V3":[{"id":{"Concrete":{"parents":"0","interior":{"X2":[{"PalletInstance":"50"},{"GeneralIndex":"10"}]}}},"fun":{"Fungible":"2,000"}},{"id":{"Concrete":{"parents":"1","interior":"Here"}},"fun":{"Fungible":"100"}}]},"fee_asset_item":"0"},"method":"reserveTransferAssets","section":"polkadotXcm"}';
"{\"args\":{\"dest\":{\"V3\":{\"parents\":\"1\",\"interior\":{\"X1\":{\"Parachain\":\"2,000\"}}}},\"beneficiary\":{\"V3\":{\"parents\":\"0\",\"interior\":{\"X1\":{\"AccountId32\":{\"network\":null,\"id\":\"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b\"}}}}},\"assets\":{\"V3\":[{\"id\":{\"Concrete\":{\"parents\":\"1\",\"interior\":\"Here\"}},\"fun\":{\"Fungible\":\"100\"}},{\"id\":{\"Concrete\":{\"parents\":\"0\",\"interior\":{\"X2\":[{\"PalletInstance\":\"50\"},{\"GeneralIndex\":\"10\"}]}}},\"fun\":{\"Fungible\":\"2,000\"}}]},\"fee_asset_item\":\"1\"},\"method\":\"reserveTransferAssets\",\"section\":\"polkadotXcm\"}";

Check failure on line 680 in src/AssetTransferApi.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"{\"args\":{\"dest\":{\"V3\":{\"parents\":\"1\",\"interior\":{\"X1\":{\"Parachain\":\"2,000\"}}}},\"beneficiary\":{\"V3\":{\"parents\":\"0\",\"interior\":{\"X1\":{\"AccountId32\":{\"network\":null,\"id\":\"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b\"}}}}},\"assets\":{\"V3\":[{\"id\":{\"Concrete\":{\"parents\":\"1\",\"interior\":\"Here\"}},\"fun\":{\"Fungible\":\"100\"}},{\"id\":{\"Concrete\":{\"parents\":\"0\",\"interior\":{\"X2\":[{\"PalletInstance\":\"50\"},{\"GeneralIndex\":\"10\"}]}}},\"fun\":{\"Fungible\":\"2,000\"}}]},\"fee_asset_item\":\"1\"},\"method\":\"reserveTransferAssets\",\"section\":\"polkadotXcm\"}"` with `↹'{"args":{"dest":{"V3":{"parents":"1","interior":{"X1":{"Parachain":"2,000"}}}},"beneficiary":{"V3":{"parents":"0","interior":{"X1":{"AccountId32":{"network":null,"id":"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"}}}}},"assets":{"V3":[{"id":{"Concrete":{"parents":"1","interior":"Here"}},"fun":{"Fungible":"100"}},{"id":{"Concrete":{"parents":"0","interior":{"X2":[{"PalletInstance":"50"},{"GeneralIndex":"10"}]}}},"fun":{"Fungible":"2,000"}}]},"fee_asset_item":"1"},"method":"reserveTransferAssets","section":"polkadotXcm"}'`
const callTxResult = await systemAssetsApi.createTransferTransaction(
'2000',
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { ApiPromise } from '@polkadot/api';

import { Registry } from '../../registry';
import { mockSystemApi } from '../../testHelpers/mockSystemApi';
import { adjustedMockSystemApi } from '../../testHelpers/adjustedMockSystemApi';
import { Direction } from '../../types';
import { limitedReserveTransferAssets } from './limitedReserveTransferAssets';

Expand All @@ -19,7 +19,7 @@ describe('limitedReserveTransferAssets', () => {
const paysWithFeeDest = undefined;
const isForeignAssetsTransfer = false;
const ext = await limitedReserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['1'],
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('limitedReserveTransferAssets', () => {
const paysWithFeeDest = undefined;
const isForeignAssetsTransfer = false;
const ext = await limitedReserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['1'],
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('limitedReserveTransferAssets', () => {
const paysWithFeeDest = undefined;
const isForeignAssetsTransfer = true;
const ext = await limitedReserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'],
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('limitedReserveTransferAssets', () => {
const paysWithFeeDest = undefined;
const isForeignAssetsTransfer = true;
const ext = await limitedReserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ export const limitedReserveTransferAssets = async (
const typeCreator = createXcmTypes[direction];
const beneficiary = typeCreator.createBeneficiary(destAddr, xcmVersion);
const dest = typeCreator.createDest(destChainId, xcmVersion);
const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
const assets = await typeCreator.createAssets(normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api

Check failure on line 52 in src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});
const weightLimitType = typeCreator.createWeightLimit(api, {
isLimited,
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export const limitedTeleportAssets = async (
const typeCreator = createXcmTypes[direction];
const beneficiary = typeCreator.createBeneficiary(destAddr, xcmVersion);
const dest = typeCreator.createDest(destChainId, xcmVersion);
const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
const assets = await typeCreator.createAssets(normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer: false,
api

Check failure on line 50 in src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});
const weightLimitType = typeCreator.createWeightLimit(api, {
isLimited,
Expand Down
8 changes: 4 additions & 4 deletions src/createXcmCalls/polkadotXcm/reserveTransferAssets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { ApiPromise } from '@polkadot/api';

import { Registry } from '../../registry';
import { mockSystemApi } from '../../testHelpers/mockSystemApi';
import { adjustedMockSystemApi } from '../../testHelpers/adjustedMockSystemApi';
import { Direction } from '../../types';
import { reserveTransferAssets } from './reserveTransferAssets';

Expand All @@ -16,7 +16,7 @@ describe('reserveTransferAssets', () => {
const isForeignAssetsTransfer = false;

const ext = await reserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['1'],
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('reserveTransferAssets', () => {
const isForeignAssetsTransfer = true;

const ext = await reserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'],
Expand All @@ -92,7 +92,7 @@ describe('reserveTransferAssets', () => {
const isForeignAssetsTransfer = true;

const ext = await reserveTransferAssets(
mockSystemApi,
adjustedMockSystemApi,
Direction.SystemToPara,
'0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b',
['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'],
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export const reserveTransferAssets = async (
const typeCreator = createXcmTypes[direction];
const beneficiary = typeCreator.createBeneficiary(destAddr, xcmVersion);
const dest = typeCreator.createDest(destChainId, xcmVersion);
const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
const assets = await typeCreator.createAssets(normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api

Check failure on line 50 in src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});

const feeAssetItem = paysWithFeeDest
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/polkadotXcm/teleportAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export const teleportAssets = async (
const typeCreator = createXcmTypes[direction];
const beneficiary = typeCreator.createBeneficiary(destAddr, xcmVersion);
const dest = typeCreator.createDest(destChainId, xcmVersion);
const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
const assets = await typeCreator.createAssets(normalizeArrToStr(amounts), xcmVersion, specName, assetIds, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer: false,
api

Check failure on line 50 in src/createXcmCalls/polkadotXcm/teleportAssets.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});

const feeAssetItem = paysWithFeeDest
Expand Down
3 changes: 2 additions & 1 deletion src/createXcmCalls/xTokens/transferMultiAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ export const transferMultiAsset = async (
const amount = amounts[0];
const assetId = assetIds[0];

const asset = await typeCreator.createXTokensAsset(api, amount, xcmVersion, specName, assetId, {
const asset = await typeCreator.createXTokensAsset(amount, xcmVersion, specName, assetId, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api

Check failure on line 59 in src/createXcmCalls/xTokens/transferMultiAsset.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});
const beneficiary = typeCreator.createXTokensBeneficiary(destChainId, destAddr, xcmVersion);

Expand Down
5 changes: 3 additions & 2 deletions src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ export const transferMultiAssetWithFee = async (
if (typeCreator.createXTokensAsset && typeCreator.createXTokensFeeAssetItem && typeCreator.createXTokensBeneficiary) {
const amount = amounts[0];
const assetId = assetIds[0];
const asset = await typeCreator.createXTokensAsset(api, amount, xcmVersion, specName, assetId, {
const asset = await typeCreator.createXTokensAsset(amount, xcmVersion, specName, assetId, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api

Check failure on line 58 in src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
});
const fee = typeCreator.createXTokensFeeAssetItem(api, {
const fee = typeCreator.createXTokensFeeAssetItem({
registry,
paysWithFeeDest,
xcmVersion,
Expand Down
7 changes: 4 additions & 3 deletions src/createXcmCalls/xTokens/transferMultiAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import type { ApiPromise } from '@polkadot/api';
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { VersionedMultiAssets } from '@polkadot/types/interfaces';
import type { ISubmittableResult } from '@polkadot/types/types';

import { createXcmTypes } from '../../createXcmTypes';
import { UnionXcAssetsMultiAssets } from '../../createXcmTypes/types';
import { BaseError, BaseErrorsEnum } from '../../errors';
import type { Registry } from '../../registry';
import { XCMDestBenificiary, XcmDirection } from '../../types';
Expand Down Expand Up @@ -50,18 +50,19 @@ export const transferMultiAssets = async (
weightLimit,
});

let assets: VersionedMultiAssets;
let assets: UnionXcAssetsMultiAssets;
let beneficiary: XCMDestBenificiary;

if (
typeCreator.createXTokensAssets &&
typeCreator.createXTokensFeeAssetItem &&
typeCreator.createXTokensBeneficiary
) {
assets = await typeCreator.createXTokensAssets(api, amounts, xcmVersion, specName, assetIds, {
assets = await typeCreator.createXTokensAssets(amounts, xcmVersion, specName, assetIds, {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api
});

beneficiary = typeCreator.createXTokensBeneficiary(destChainId, destAddr, xcmVersion);
Expand Down
52 changes: 26 additions & 26 deletions src/createXcmTypes/ParaToPara.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ describe('ParaToPara', () => {
const isForeignAssetsTransfer = false;
it('Should work for V2', async () => {
const assets = await ParaToPara.createAssets(
mockParachainApi,
['1000000000000', '2000000000'],
2,
'moonriver',
Expand All @@ -99,45 +98,45 @@ describe('ParaToPara', () => {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api: mockParachainApi,
}
);

const expectedRes = {
v2: [
V2: [
{
id: {
concrete: {
parents: 1,
interior: {
here: null,
Concrete: {
Parents: 1,
Interior: {
Here: null,
},
},
},
fun: {
fungible: 1000000000000,
Fungible: '1000000000000',
},
},
{
id: {
concrete: {
parents: 1,
interior: {
x3: [{ parachain: 1000 }, { palletInstance: 50 }, { generalIndex: 8 }],
Concrete: {
Parents: 1,
Interior: {
X3: [{ Parachain: 1000 }, { PalletInstance: 50 }, { GeneralIndex: 8 }],
},
},
},
fun: {
fungible: 2000000000,
Fungible: '2000000000',
},
},
],
};

expect(assets.toString()).toEqual(JSON.stringify(expectedRes));
expect(assets).toStrictEqual(expectedRes);
});
it('Should work for V3', async () => {
const assets = await ParaToPara.createAssets(
mockParachainApi,
['1000000', '20000000000'],
3,
'moonriver',
Expand All @@ -146,41 +145,42 @@ describe('ParaToPara', () => {
registry,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
api: mockParachainApi,
}
);

const expectedRes = {
v3: [
V3: [
{
id: {
concrete: {
parents: 1,
interior: {
x3: [{ parachain: 1000 }, { palletInstance: 50 }, { generalIndex: 8 }],
Concrete: {
Parents: 1,
Interior: {
X3: [{ Parachain: 1000 }, { PalletInstance: 50 }, { GeneralIndex: 8 }],
},
},
},
fun: {
fungible: 1000000,
Fungible: '1000000',
},
},
{
id: {
concrete: {
parents: 1,
interior: {
x3: [{ parachain: 1000 }, { palletInstance: 50 }, { generalIndex: 1984 }],
Concrete: {
Parents: 1,
Interior: {
X3: [{ Parachain: 1000 }, { PalletInstance: 50 }, { GeneralIndex: 1984 }],
},
},
},
fun: {
fungible: 20000000000,
Fungible: '20000000000',
},
},
],
};

expect(assets.toString()).toEqual(JSON.stringify(expectedRes));
expect(assets).toStrictEqual(expectedRes);
});
});
describe('WeightLimit', () => {
Expand Down
Loading

0 comments on commit 4cee611

Please sign in to comment.