Skip to content

Commit

Permalink
upload for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bee344 committed Jan 10, 2024
1 parent bb2caa8 commit ac66157
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 145 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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 TRAPPIST_WS_URL = 'ws://127.0.0.1:9921';
export const ROCOCO_ASSET_HUB_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';
Expand Down
12 changes: 7 additions & 5 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, TRAPPIST_WS_URL } from './consts';
import { KUSAMA_ASSET_HUB_WS_URL, MOONRIVER_WS_URL, ROCOCO_ALICE_WS_URL, ROCOCO_ASSET_HUB_WS_URL } from './consts';
import { assetTests, foreignAssetsTests, IndividualTest, liquidPoolsTests, localTests, tests } from './tests';
import { verification } from './verification';

Expand Down Expand Up @@ -70,7 +70,10 @@ 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]) as object;
opts = JSON.parse(t.args[6], (key, value) => {
return key === "paysWithFeeOrigin" ? JSON.stringify(value) : value;
}) as object;


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

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

const originApi = api;
Expand Down
16 changes: 15 additions & 1 deletion e2e-tests/tests/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ import { AssetTransferApi } from '../../src';
import { TxResult } from '../../src/types';

const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: number): AssetTransferApi => {
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
const injectedRegistry = {
rococo: {
'1836': {
tokens: ['ROC'],
assetsInfo: {},
foreignAssetsInfo: {},
specName: 'asset-hub-rococo',
poolPairsInfo: {},
},
},
};

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


return assetApi;
};
Expand Down
16 changes: 15 additions & 1 deletion e2e-tests/tests/foreignAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ import { AssetTransferApi } from '../../src';
import { TxResult } from '../../src/types';

const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: number): AssetTransferApi => {
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
const injectedRegistry = {
rococo: {
'1836': {
tokens: ['ROC'],
assetsInfo: {},
foreignAssetsInfo: {},
specName: 'asset-hub-rococo',
poolPairsInfo: {},
},
},
};

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


return assetApi;
};
Expand Down
94 changes: 47 additions & 47 deletions e2e-tests/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const tests: TestGroups = {
'1000',
'//Alice',
BOB_KAH_ADDR,
'[{ "parents": "1", "interior": { "X2": [{ "Parachain": "2500" }, { "GeneralIndex": "0" }]}}]',
'[{ "parents": "1", "interior": { "X2": [{ "Parachain": "1836" }, { "GeneralIndex": "0" }]}}]',
'[200000000000]',
'{ "format": "submittable", "xcmVersion": 3 }',
],
Expand All @@ -40,79 +40,79 @@ 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: 'createLocalTransferTransaction',
test: 'createPayFeesTransaction',
// This will be all the args for the above call
args: [
'1000',
'1000',
'//Alice',
BOB_KAH_ADDR,
'[0]',
'[2000]',
'{ "format": "submittable", "transferLiquidToken": true }',
'[30000]',
'{ "format": "payload", "xcmVersion": 3, "transferLiquidToken": true, "paysWithFeeOrigin": { "parents": "0", "interior": { "X2": [{"PalletInstance": "50"}, { "GeneralIndex": "1" }]}}, "sendersAddr": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" }',
],
// 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]'],
verification: ['[0]', '[30000]'],
},
],
local: [
{
// This will declare the call to use
test: 'createPayFeesTransaction',
test: 'createLocalTransferTransaction',
// This will be all the args for the above call
args: [
'1000',
'1000',
'//Alice',
BOB_KAH_ADDR,
'[0]',
'[30000]',
'{ "format": "submittable", "transferLiquidToken": true }',
'[]',
'[10000000000000]',
'{ "format": "submittable", "keepAlive": 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]', '[10000000000000]'],
},
{
// This will declare the call to use
test: 'createLocalTransferTransaction',
// This will be all the args for the above call
args: [
'1836',
'1836',
'//Alice',
BOB_KAH_ADDR,
'[]',
'[100000000000000000]',
'{ "format": "submittable", "keepAlive": 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]', '[10000000000000]'],
},
],
local: [
// {
// // This will declare the call to use
// test: 'createSystemLocalTransferTransaction',
// // This will be all the args for the above call
// args: [
// '1000',
// '1000',
// '//Alice',
// BOB_KAH_ADDR,
// '[]',
// '[10000000000000]',
// '{ "format": "submittable", "keepAlive": 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]', '[10000000000000]'],
// },
// {
// // This will declare the call to use
// test: 'createSystemLocalTransferTransaction',
// // This will be all the args for the above call
// args: [
// '1836',
// '1836',
// '//Alice',
// BOB_KAH_ADDR,
// '[]',
// '[100000000000000000]',
// '{ "format": "submittable", "keepAlive": 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]', '[10000000000000]'],
// },
{
// This will declare the call to use
test: 'createSystemLocalTransferTransaction',
test: 'createLocalTransferTransaction',
// This will be all the args for the above call
args: [
'0',
Expand Down
44 changes: 40 additions & 4 deletions e2e-tests/tests/liquidPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ import { AssetTransferApi } from '../../src';
import { TxResult } from '../../src/types';

const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: number): AssetTransferApi => {
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
const injectedRegistry = {
rococo: {
'1836': {
tokens: ['ROC'],
assetsInfo: {},
foreignAssetsInfo: {},
specName: 'asset-hub-rococo',
poolPairsInfo: {},
},
},
};

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


return assetApi;
};
Expand Down Expand Up @@ -40,17 +54,39 @@ const createPayFeesTransaction = async (
destAddr: string,
assetIds: string[],
amounts: string[],
opts: object,
opts: {},
api: ApiPromise,
specName: string,
safeXcmVersion: number,
) => {
const assetApi = createAssetApi(api, specName, safeXcmVersion);

let localTransferInfo: TxResult<'submittable'>;
let localTransferInfo: TxResult<'payload'>;
try {
localTransferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);
await localTransferInfo.tx.signAndSend(origin);
const signature = api.registry
.createType('ExtrinsicPayload', localTransferInfo, {
version: 4,
})
.sign(origin).signature as unknown as `0x${string}`;

const extrinsic = api.registry.createType(
'Extrinsic',
{ method: localTransferInfo.method },
{ version: 4 }
);

let sender: string;
if (opts["sendersAddr"] === undefined) {
sender = ''
} else {
sender = opts["sendersAddr"];
}

const signed = extrinsic.addSignature(sender, signature, localTransferInfo as unknown as `0x${string}`).toHex()

await api.rpc.author.submitExtrinsic(signed)

} catch (e) {
console.error(e);
throw Error(e as string);
Expand Down
55 changes: 3 additions & 52 deletions e2e-tests/tests/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TxResult } from '../../src/types';
const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: number): AssetTransferApi => {

const injectedRegistry = {
kusama: {
rococo: {
'1836': {
tokens: ['ROC'],
assetsInfo: {},
Expand All @@ -27,54 +27,7 @@ const createAssetApi = (api: ApiPromise, specName: string, safeXcmVersion: numbe
return assetApi;
};

const createSystemLocalTransferTransaction = async (
origin: KeyringPair,
destChainId: string,
destAddr: string,
assetIds: string[],
amounts: string[],
opts: object,
api: ApiPromise,
specName: string,
safeXcmVersion: number,
) => {
const assetApi = createAssetApi(api, specName, safeXcmVersion);

let localTransferInfo: TxResult<'submittable'>;
try {
localTransferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);
console.log(localTransferInfo.direction)
await localTransferInfo.tx.signAndSend(origin);
} catch (e) {
console.error(e);
throw Error(e as string);
}
};

const createRelayLocalTransferTransaction = async (
origin: KeyringPair,
destChainId: string,
destAddr: string,
assetIds: string[],
amounts: string[],
opts: object,
api: ApiPromise,
specName: string,
safeXcmVersion: number,
) => {
const assetApi = createAssetApi(api, specName, safeXcmVersion);

let localTransferInfo: TxResult<'submittable'>;
try {
localTransferInfo = await assetApi.createTransferTransaction(destChainId, destAddr, assetIds, amounts, opts);
await localTransferInfo.tx.signAndSend(origin);
} catch (e) {
console.error(e);
throw Error(e as string);
}
};

const createRelayToSystemTransferTransaction = async (
const createLocalTransferTransaction = async (
origin: KeyringPair,
destChainId: string,
destAddr: string,
Expand All @@ -98,7 +51,5 @@ const createRelayToSystemTransferTransaction = async (
};

export const localTests: { [K: string]: Function } = {
createSystemLocalTransferTransaction,
createRelayLocalTransferTransaction,
createRelayToSystemTransferTransaction,
createLocalTransferTransaction,
};
2 changes: 1 addition & 1 deletion scripts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

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 TRAPPIST_WS_URL = 'ws://127.0.0.1:9921';
export const ROCOCO_ASSET_HUB_WS_URL = 'ws://127.0.0.1:9921';
export const MOONRIVER_WS_URL = 'ws://127.0.0.1:9931';
Loading

0 comments on commit ac66157

Please sign in to comment.