Skip to content

Commit

Permalink
Post-review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Apr 9, 2024
1 parent e647d9d commit 0cf80f1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
environment:
NODE_OPTIONS: --max-old-space-size=6144
# name: "Running parity upgrade tests"
# command: npm run test:contracts:upgrade:parity && npm run test:contracts:upgrade:ganache
# command: npm run test:contracts:upgrade:parity
# environment:
# NODE_OPTIONS: --max-old-space-size=6144
- run:
Expand Down
24 changes: 24 additions & 0 deletions helpers/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals artifacts, hre */
const fs = require("fs");
const shortid = require("shortid");
const chai = require("chai");
const { asciiToHex, isBN } = require("web3-utils");
Expand All @@ -17,6 +18,7 @@ const {
MAINNET_CHAINID,
XDAI_CHAINID,
FORKED_XDAI_CHAINID,
CREATEX_ADDRESS,
} = require("./constants");

const IColony = artifacts.require("IColony");
Expand Down Expand Up @@ -1267,6 +1269,28 @@ exports.isXdai = async function isXdai() {
return chainId === XDAI_CHAINID || chainId === FORKED_XDAI_CHAINID;
};

exports.deployCreateXIfNeeded = async function deployCreateXIfNeeded() {
// Deploy CreateX if it's not already deployed
const createXCode = await web3.eth.getCode(CREATEX_ADDRESS);
if (createXCode === "0x") {
const accounts = await web3.eth.getAccounts();
await web3.eth.sendTransaction({
from: accounts[0],
to: "0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5",
value: web3.utils.toWei("0.3", "ether"),
gasPrice: web3.utils.toWei("1", "gwei"),
gas: 300000,
});
const rawTx = fs
.readFileSync("lib/createx/scripts/presigned-createx-deployment-transactions/signed_serialised_transaction_gaslimit_3000000_.json", {
encoding: "utf8",
})
.replace(/"/g, "")
.replace("\n", "");
await web3.eth.sendSignedTransaction(rawTx);
}
};

class TestAdapter {
constructor() {
this.outputs = [];
Expand Down
12 changes: 0 additions & 12 deletions test/cross-chain/cross-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,28 @@ contract("Cross-chain", (accounts) => {
});

beforeEach(async () => {
console.log("beforeEach");
web3HomeProvider = new web3.eth.providers.HttpProvider(ethersHomeSigner.provider.connection.url);
web3ForeignProvider = new web3.eth.providers.HttpProvider(ethersForeignSigner.provider.connection.url);

console.log("beforeEach");
homeSnapshotId = await snapshot(web3HomeProvider);
foreignSnapshotId = await snapshot(web3ForeignProvider);
bridgeMonitor.reset();

console.log("beforeEach");
let tx = await foreignBridge.setBridgeEnabled(true);
await tx.wait();
tx = await homeBridge.setBridgeEnabled(true);
await tx.wait();

console.log("beforeEach");
const foreignMCAddress = await foreignColonyNetwork.getMetaColony();
foreignMetacolony = await new ethers.Contract(foreignMCAddress, IMetaColony.abi, ethersForeignSigner);
const homeMCAddress = await homeColonyNetwork.getMetaColony();
homeMetacolony = await new ethers.Contract(homeMCAddress, IMetaColony.abi, ethersHomeSigner);

console.log("beforeEach");
await setForeignBridgeData(foreignColonyBridge.address);
await setHomeBridgeData(homeColonyBridge.address);

// Bridge over skills that have been created on the foreign chain

console.log("beforeEach");
const latestSkillId = await foreignColonyNetwork.getSkillCount();
const skillId = ethers.BigNumber.from(foreignChainId).mul(ethers.BigNumber.from(2).pow(128)).add(1);
for (let i = skillId; i <= latestSkillId; i = i.add(1)) {
Expand All @@ -198,7 +192,6 @@ contract("Cross-chain", (accounts) => {
// process.exit(1);
}

console.log("beforeEach");
// Set up mining client
client = new ReputationMinerTestWrapper({
loader: contractLoader,
Expand All @@ -209,27 +202,22 @@ contract("Cross-chain", (accounts) => {

await client.initialise(homeColonyNetwork.address);

console.log("beforeEach");
await forwardTime(MINING_CYCLE_DURATION + CHALLENGE_RESPONSE_WINDOW_DURATION, undefined, web3HomeProvider);
await client.addLogContentsToReputationTree();
await client.submitRootHash();
await client.confirmNewHash();

console.log("beforeEach");
await forwardTime(MINING_CYCLE_DURATION + CHALLENGE_RESPONSE_WINDOW_DURATION, undefined, web3HomeProvider);
await client.addLogContentsToReputationTree();
await client.submitRootHash();
await client.confirmNewHash();
console.log("beforerEach");

// Set up a colony on the home chain. That may or may not be the truffle chain...
homeColony = await setupColony(homeColonyNetwork);

console.log("beforerEach");
const p = bridgeMonitor.getPromiseForNextBridgedTransaction(2);
foreignColony = await setupColony(foreignColonyNetwork);
await p;
console.log("beforerEach");
});

async function setupColony(colonyNetworkEthers) {
Expand Down
25 changes: 2 additions & 23 deletions test/truffle-fixture.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* globals artifacts, hre */
const fs = require("fs");

const EtherRouter = artifacts.require("EtherRouter");
const EtherRouterCreate3 = artifacts.require("EtherRouterCreate3");
const Resolver = artifacts.require("Resolver");
Expand Down Expand Up @@ -78,7 +76,7 @@ const {
setupEtherRouter,
} = require("../helpers/upgradable-contracts");
const { FORKED_XDAI_CHAINID, XDAI_CHAINID, UINT256_MAX, CREATEX_ADDRESS } = require("../helpers/constants");
const { getChainId, hardhatRevert, hardhatSnapshot } = require("../helpers/test-helper");
const { getChainId, hardhatRevert, hardhatSnapshot, deployCreateXIfNeeded } = require("../helpers/test-helper");

module.exports = async () => {
if (postFixtureSnapshotId) {
Expand Down Expand Up @@ -139,25 +137,7 @@ async function deployContracts() {
const reputationMiningCycleBinarySearch = await ReputationMiningCycleBinarySearch.new();
ReputationMiningCycleBinarySearch.setAsDeployed(reputationMiningCycleBinarySearch);

// Deploy CreateX if it's not already deployed
const createXCode = await web3.eth.getCode(CREATEX_ADDRESS);
if (createXCode === "0x") {
const accounts = await web3.eth.getAccounts();
await web3.eth.sendTransaction({
from: accounts[0],
to: "0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5",
value: web3.utils.toWei("0.3", "ether"),
gasPrice: web3.utils.toWei("1", "gwei"),
gas: 300000,
});
const rawTx = fs
.readFileSync("lib/createx/scripts/presigned-createx-deployment-transactions/signed_serialised_transaction_gaslimit_3000000_.json", {
encoding: "utf8",
})
.replace(/"/g, "")
.replace("\n", "");
await web3.eth.sendSignedTransaction(rawTx);
}
await deployCreateXIfNeeded();
}

async function setupColonyNetwork() {
Expand All @@ -183,7 +163,6 @@ async function setupColonyNetwork() {
const fakeEtherRouter = await EtherRouterCreate3.at(colonyNetwork.address);
const setOwnerData = fakeEtherRouter.contract.methods.setOwner(accounts[0]).encodeABI();
const tx = await createX.methods["deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256))"](
// `${accounts[0]}001212121212121212121212`,
`0xb77d57f4959eafa0339424b83fcfaf9c15407461005e95d52076387600e2c1e9`,
EtherRouterCreate3.bytecode,
setOwnerData,
Expand Down

0 comments on commit 0cf80f1

Please sign in to comment.