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(runtime): update nix file and npm command #4238

Merged
merged 19 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions code/integration-tests/runtime-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"test": "tests"
},
"scripts": {
"test:cosmos": "tsc; ts-mocha --grep 'centauri' ./tests/*Tests.ts",
"test": "tsc; ts-mocha --parallel ./tests/*Tests.ts",
"generate-defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces --endpoint ws://localhost:9988",
"generate-meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ws://localhost:9988 --output ./src/interfaces",
"generate-defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package ./src/interfaces --input ./src/interfaces --endpoint picasso-types.json",
"generate-meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package ./src/interfaces --endpoint picasso-types.json --output ./src/interfaces",
"generate-types": "npm run generate-defs && npm run generate-meta"
},
"author": "",
Expand Down
1 change: 1 addition & 0 deletions code/integration-tests/runtime-tests/picasso-types.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions code/integration-tests/runtime-tests/runtime-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
( ${
pkgs.lib.meta.getExe self'.packages.devnet-xc-fresh-background
} 2>&1 & ) | tee devnet-xc.log &

TRIES=0
START_RESULT=1
while test $TRIES -le 64; do
Expand All @@ -29,7 +28,7 @@
curl --header "Content-Type: application/json" --data '{"id":1, "jsonrpc":"2.0", "method" : "assets_listAssets"}' http://127.0.0.1:29988
START_RESULT=$?
fi
set -o errexit
set -o errexit
if test $START_RESULT -eq 0; then
set +o errexit
pkill -SIGTERM process-compose
Expand All @@ -39,14 +38,17 @@
((TRIES=TRIES+1))
sleep 4
done

# here nodes are up and running, binaries in path, npm is here too

sleep 8
set +o errexit
# PATH=$PATH:$(pwd)
# export PATH
# cd code/integration-tests/runtime-tests
# npm install
# npm run generate-types
# npm run test:cosmos
# sleep 8
# set +o errexit
pkill -SIGKILL process-compose
set -o errexit
exit $START_RESULT
exit 0
'';
};
};
Expand Down
4 changes: 2 additions & 2 deletions code/integration-tests/runtime-tests/tests/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"endpoints": {
"picassoEndpoint": "ws://localhost:9988",
"composableEndpoint": "ws://localhost:29988",
"picassoEndpoint": "ws://127.0.0.1:9988",
"composableEndpoint": "ws://127.0.0.1:29988",
"kusamaEndpoint": "ws://localhost:9944"
},
"chains": {
Expand Down
21 changes: 13 additions & 8 deletions code/integration-tests/runtime-tests/tests/multihopTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('MultiHop Tests', function () {
mintAssetsOnRelays([kusamaApi], sudoKey, testWallet.address),
]);
await createRoute(picassoApi, sudoKey, 2, [['picasso', 'composable'], ['composable', 'picasso']]);
await createRoute(picassoApi, sudoKey, 3, [['picasso', 'centauri'], ['centauri', 'osmosis']]);
await createRoute(picassoApi, sudoKey, 3, [['picasso', 'centauri']]);
await Promise.all([
getBalance(picassoAssets, [testWallet.address, feeAddress, substrateEscrowAddress, cosmosEscrowAddress], 'dotsama', picassoApi),
getBalance(composableAssets, [testWallet.address], 'dotsama', composableApi),
Expand All @@ -70,35 +70,40 @@ describe('MultiHop Tests', function () {
})

before('Wait for channel to open on centauri to osmosis', async () => {
await waitForChannelsToOpen(2, 'centauri');
await waitForChannelsToOpen(1, 'centauri');
});

it('Initiates a transfer for kusama => picasso => centauri => osmosis', async () => {
it('Initiates a transfer for kusama => picasso => centauri', async () => {
console.log('TESTS Transfer initiated');
const preSequence = await getNextSequenceForIbc(picassoApi);
const ksm = picassoAssets.find(asset => asset.symbol === 'ksm') as Asset;
await waitForBlocks(picassoApi, 3);
console.log('TESTS Waited for 2 blokcs');
const [preFeeAddressBalance, preTotalIssuance, preEscrowAddressBalance] =
await getBalanceAndIssuanceStats(
ksm,
testWallet.address,
feeAddress,
cosmosEscrowAddress,
picassoApi);
console.log('TESTS xcm initiated');
([ibcEvent,] = await Promise.all([
waitForEvent(picassoApi, picassoApi.events.palletMultihopXcmIbc.SuccessXcmToIbc.is),
initiateXcmTransfer(
kusamaApi,
2087,
3,
testWallet,
3,
2,
ksmTransferAmount,
false,
true,
centauriAddress,
osmosisAddress),
]
));
await waitForBlocks(picassoApi, 1);
console.log('TESTS Events and got');
await waitForBlocks(picassoApi, 2);
const {data: [_origin, _to, amount, _assetId, _memo]} = ibcEvent;
ibcSentAmount = new BigNumber((amount.toString().replaceAll(',', '')));
const nextsequence = await getNextSequenceForIbc(picassoApi);
Expand All @@ -109,7 +114,7 @@ describe('MultiHop Tests', function () {
feeAddress,
cosmosEscrowAddress,
picassoApi);
const feeCharged = new BigNumber((ibcSentAmount.multipliedBy(0.004)).toFixed(0));
const feeCharged = new BigNumber((ibcSentAmount.multipliedBy(0.005)).toFixed(0));
ibcSentAmount = ibcSentAmount.minus(feeCharged);
const diffInTotalIssuance = afterTotalIssuance.minus(preTotalIssuance);
expect(diffInTotalIssuance.toString()).to.be.eq(ksmTransferAmount.toString());
Expand All @@ -131,8 +136,8 @@ describe('MultiHop Tests', function () {
}
await getBalance(ksmOnCent, [centauriAddress], 'cosmos');
const ksmAfterBal = ksmOnCent.balance.get(centauriAddress);
//validate that user balance remains the same
expect(ksmAfterBal).to.be.bignumber.eq(ksmPreBal);
//validate that user balance increases
expect(ksmAfterBal).to.be.bignumber.eq(ksmPreBal.plus(ibcSentAmount));
//validate that total issuance increases
expect(afterTotalIssuance).to.be.bignumber.eq(preTotalIssuance.plus(ibcSentAmount));
});
Expand Down
16 changes: 5 additions & 11 deletions code/integration-tests/runtime-tests/tests/utils/multihopUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,7 @@ export function setBeneficiary(
id: api.createType('AccountId32', bech32.decode(centauriAddress).words),
}
});
networkHops[2] = api.createType("XcmV2Junction", {
AccountId32: {
network: api.createType("XcmV2NetworkId", "Any"),
id: api.createType('AccountId32', bech32.decode(osmosisAddress).words),
}
});
}

if (nbOfHops === 2) {
return api.createType('XcmVersionedMultiLocation', {
V2: api.createType('XcmV2MultiLocation', {
Expand Down Expand Up @@ -337,7 +330,7 @@ export async function waitForEvent<T extends AnyTuple>(api: ApiPromise, filterCa
if (filterCall(event)) {
unsubscribe();
resolve(event);
} else if (index > 70) {
} else if (index > 10) {
unsubscribe();
reject('waited for 70 blocks');
}
Expand Down Expand Up @@ -380,16 +373,17 @@ export async function waitForChannelsToOpen(expectedChannelCount: number, target
}

export async function waitForChannelsOnCentauri(expectedChannelCount: number) {
let {stdout} = await exec(`~/go/bin/centaurid query ibc channel channels --output json`);
let {stdout} = await exec(`centaurid query ibc channel channels --output json`);
let parsed = JSON.parse(stdout);
let channelsLength = parsed.channels.length;
let index = 0;
while (channelsLength < expectedChannelCount && index < 50) {
({stdout} = await exec(`~/go/bin/centaurid query ibc channel channels --output json`));
while (channelsLength < expectedChannelCount && index < 300) {
({stdout} = await exec(`centaurid query ibc channel channels --output json`));
parsed = JSON.parse(stdout);
channelsLength = parsed.channels.length;
index++;
console.log('waiting for channels on osmosis to open');
console.log('channels length is', channelsLength);
await waitForSeconds(8);
}
}
Expand Down
Loading