Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add foreign assets script to test network #272

Merged
merged 16 commits into from
Nov 2, 2023
Prev Previous commit
Next Next commit
abstract functionality into smaller functions
TarikGul committed Sep 6, 2023
commit 84f38266d5e4e4fa3ede2b92617a41cd1b244faa
50 changes: 33 additions & 17 deletions scripts/testNetworkForeignAssets.ts
Original file line number Diff line number Diff line change
@@ -6,12 +6,9 @@ import { cryptoWaitReady } from '@polkadot/util-crypto';
import chalk from 'chalk';

import { KUSAMA_ASSET_HUB_WS_URL, TRAPPIST_WS_URL } from './consts';
import { logWithDate } from './util';
import { awaitBlockProduction, logWithDate } from './util';

const createForeignAssetCall = (
assetHubApi: ApiPromise,
trappistApi: ApiPromise
) => {
const fAssetCreateCall = (assetHubApi: ApiPromise): `0x${string}` => {
const trappistMultiLocation = assetHubApi.registry.createType(
'MultiLocation',
{
@@ -24,22 +21,26 @@ const createForeignAssetCall = (
}
);

const foreignAssetCreateTx = assetHubApi.tx.foreignAssets.create(
const createTx = assetHubApi.tx.foreignAssets.create(
trappistMultiLocation,
'FBeL7DbnXs4AvP7LqG1yiuFYAsPxE9Yiv4wayoLguBH46Bp', // Sibling 1836 -> ParaId
'33333333'
);

const foreignAssetCreateCallHex = assetHubApi.registry
const hexCall = assetHubApi.registry
.createType('Call', {
callIndex: foreignAssetCreateTx.callIndex,
args: foreignAssetCreateTx.args,
callIndex: createTx.callIndex,
args: createTx.args,
})
.toHex();

return hexCall;
};

const sudoCallWrapper = (trappistApi: ApiPromise, call: `0x${string}`) => {
// Double encode the call
const xcmDoubleEncoded = trappistApi.createType('XcmDoubleEncoded', {
encoded: foreignAssetCreateCallHex,
encoded: call,
});

const xcmOriginType = trappistApi.createType('XcmOriginKind', 'Xcm');
@@ -91,8 +92,8 @@ const createForeignAssetCall = (
transact: {
originKind: xcmOriginType,
requireWeightAtMost: {
refTime: 1000000000,
proofSize: 900000,
refTime: 8000000000,
proofSize: 65536,
},
call: xcmDoubleEncoded,
},
@@ -134,6 +135,16 @@ const createForeignAssetCall = (
return xcmCall;
};

const createForeignAssetViaSudo = (
assetHubApi: ApiPromise,
trappistApi: ApiPromise
) => {
const foreignAssetCreateCall = fAssetCreateCall(assetHubApi);
const sudoCall = sudoCallWrapper(trappistApi, foreignAssetCreateCall);

return sudoCall;
};

const main = async () => {
logWithDate(
chalk.yellow('Initializing script to create foreignAssets on chain')
@@ -160,15 +171,17 @@ const main = async () => {
await trappistApi.isReady;
logWithDate(chalk.green('Created a connection to Trappist'));

const createForeignAssetsXcmCall = createForeignAssetCall(
const foreignAssetsCreateSudoXcmCall = createForeignAssetViaSudo(
kusamaAssetHubApi,
trappistApi
);

logWithDate(
'Sending Sudo XCM message from relay chain to execute forceCreate call on Kusama AssetHub'
);
await trappistApi.tx.sudo.sudo(createForeignAssetsXcmCall).signAndSend(alice);
await trappistApi.tx.sudo
.sudo(foreignAssetsCreateSudoXcmCall)
.signAndSend(alice);

await kusamaAssetHubApi.disconnect().then(() => {
logWithDate(
@@ -183,6 +196,9 @@ const main = async () => {
});
};

main()
.catch(console.error)
.finally(() => process.exit());
// eslint-disable-next-line @typescript-eslint/no-floating-promises
awaitBlockProduction(TRAPPIST_WS_URL).then(async () => {
await main()
.catch(console.error)
.finally(() => process.exit());
});
2 changes: 1 addition & 1 deletion scripts/testNetworkSetup.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import { cryptoWaitReady } from '@polkadot/util-crypto';
import chalk from 'chalk';

import { KUSAMA_ASSET_HUB_WS_URL, ROCOCO_ALICE_WS_URL } from './consts';
import { delay, logWithDate, awaitBlockProduction } from './util';
import { awaitBlockProduction, delay, logWithDate } from './util';

/**
* This script is intended to be run after zombienet is running.