Skip to content

Commit 038f1f6

Browse files
committed
Make skill bridging on colony creation more reliable in tests
1 parent a1bc443 commit 038f1f6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

scripts/mockBridgeMonitor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ class MockBridgeMonitor {
8282

8383
close() {} // eslint-disable-line class-methods-use-this
8484

85-
async bridgeSkipped() {
86-
const [bridge, messageId, encodedData] = this.skipped.shift();
85+
async bridgeSkipped(id = 0) {
86+
// remove the id'th element from the array
87+
const [bridge, messageId, encodedData] = this.skipped.splice(id, 1)[0];
8788
const [target, data, gasLimit, sender] = ethers.utils.defaultAbiCoder.decode(["address", "bytes", "uint256", "address"], encodedData);
8889
const tx = await bridge.execute(target, data, gasLimit, messageId, sender);
8990
await tx.wait();

test/cross-chain/cross-chain.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,21 @@ contract("Cross-chain", (accounts) => {
249249
}
250250

251251
beforeEach(async () => {
252-
const tx = await foreignBridge.setBridgeEnabled(true);
252+
let tx = await foreignBridge.setBridgeEnabled(true);
253253
await tx.wait();
254254
// Set up a colony on the home chain. That may or may not be the truffle chain...
255255
homeColony = await setupColony(homeColonyNetwork);
256-
257256
const p = bridgeMonitor.getPromiseForNextBridgedTransaction(2);
258257
foreignColony = await setupColony(foreignColonyNetwork);
259258
await p;
259+
260+
// It's possible these were bridged out of order, so check, and if so, bridge the second skill
261+
const bridgedSkillCount = await homeColonyNetwork.getBridgedSkillCounts(foreignChainId);
262+
const skillCount = await foreignColonyNetwork.getSkillCount();
263+
if (!bridgedSkillCount.eq(skillCount)) {
264+
tx = await homeColonyNetwork.addPendingSkill(homeBridge.address, skillCount, { gasLimit: 1000000 });
265+
await tx.wait();
266+
}
260267
});
261268

262269
afterEach(async () => {
@@ -779,7 +786,13 @@ contract("Cross-chain", (accounts) => {
779786
let p = bridgeMonitor.getPromiseForNextBridgedTransaction(2);
780787
const foreignColony2 = await setupColony(foreignColonyNetwork);
781788
await p;
782-
789+
// It's possible these were bridged out of order, so check, and if so, bridge the second skill
790+
const bridgedSkillCount = await homeColonyNetwork.getBridgedSkillCounts(foreignChainId);
791+
const skillCount = await foreignColonyNetwork.getSkillCount();
792+
if (!bridgedSkillCount.eq(skillCount)) {
793+
const tx = await homeColonyNetwork.addPendingSkill(homeBridge.address, skillCount, { gasLimit: 1000000 });
794+
await tx.wait();
795+
}
783796
let tx = await foreignBridge.setBridgeEnabled(false);
784797
await tx.wait();
785798
tx = await foreignColony.emitDomainReputationReward(1, accounts[0], "0x1338");
@@ -835,6 +848,14 @@ contract("Cross-chain", (accounts) => {
835848
const foreignColony2 = await setupColony(foreignColonyNetwork);
836849
await p;
837850

851+
// It's possible these were bridged out of order, so check, and if so, bridge the second skill
852+
const bridgedSkillCount = await homeColonyNetwork.getBridgedSkillCounts(foreignChainId);
853+
const skillCount = await foreignColonyNetwork.getSkillCount();
854+
if (!bridgedSkillCount.eq(skillCount)) {
855+
const tx = await homeColonyNetwork.addPendingSkill(homeBridge.address, skillCount, { gasLimit: 1000000 });
856+
await tx.wait();
857+
}
858+
838859
bridgeMonitor.skipCount = 1;
839860

840861
// Bridge skills

0 commit comments

Comments
 (0)