mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 13:21:01 +00:00
2e6067d768
extracted useful code from #2982 This PR: - adds test 2 for Rococo <> Westend bridge: checks that relayer doesn't submit any extra headers while there are no any messages; - adds test 3 for Rococo <> Westend bridge: checks that relayer doesn't submit any extra headers when there are messages; - fixes most of comments from #2439 (like: log names, ability to run specify test number when calling `run-tests.sh`). Right now of all our tests, only test 2 is working (until BHs will be upgraded to use async backing), so you can test it with `./bridges/zombienet/run-tests.sh --test 2` locally.
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
const utils = require("./utils");
|
|
|
|
async function run(nodeName, networkInfo, args) {
|
|
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName];
|
|
const api = await zombie.connect(wsUri, userDefinedTypes);
|
|
|
|
// parse arguments
|
|
const exitAfterSeconds = Number(args[0]);
|
|
const bridgedChain = require("./chains/" + args[1]);
|
|
|
|
// start listening to new blocks
|
|
let totalGrandpaHeaders = 0;
|
|
let totalParachainHeaders = 0;
|
|
api.rpc.chain.subscribeNewHeads(async function (header) {
|
|
const apiAtParent = await api.at(header.parentHash);
|
|
const apiAtCurrent = await api.at(header.hash);
|
|
const currentEvents = await apiAtCurrent.query.system.events();
|
|
|
|
totalGrandpaHeaders += await utils.ensureOnlyMandatoryGrandpaHeadersImported(
|
|
bridgedChain,
|
|
apiAtParent,
|
|
apiAtCurrent,
|
|
currentEvents,
|
|
);
|
|
totalParachainHeaders += await utils.ensureOnlyInitialParachainHeaderImported(
|
|
bridgedChain,
|
|
apiAtParent,
|
|
apiAtCurrent,
|
|
currentEvents,
|
|
);
|
|
});
|
|
|
|
// wait given time
|
|
await new Promise(resolve => setTimeout(resolve, exitAfterSeconds * 1000));
|
|
// if we haven't seen any new GRANDPA or parachain headers => fail
|
|
if (totalGrandpaHeaders == 0) {
|
|
throw new Error("No bridged relay chain headers imported");
|
|
}
|
|
if (totalParachainHeaders == 0) {
|
|
throw new Error("No bridged parachain headers imported");
|
|
}
|
|
}
|
|
|
|
module.exports = { run }
|