Skip to content

Commit

Permalink
Migrate TruffleLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Dec 7, 2023
1 parent 65ec64b commit 286c493
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
15 changes: 8 additions & 7 deletions packages/package-utils/TruffleLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ class TruffleContractLoader {
return true;
}

constructor({ contractDir } = {}) {
assert(typeof contractDir === "string" && contractDir, "A `contractDir` option must be provided");
this._contractDir = contractDir;
constructor({ contractRoot } = {}) {
assert(typeof contractRoot === "string" && contractRoot, "A `contractRoot` option must be provided");
this._contractRoot = contractRoot;
}

async _load(query = {}) {
const { contractName = "" } = query;
const { contractDir = "", contractName = "" } = query;

assert(!!contractDir, "A `contractDir` option must be provided");
assert(!!contractName, "A `contractName` option must be provided");

const file = path.resolve(this._contractDir, `${contractName}.json`);
const file = path.resolve(this._contractRoot, contractDir, `${contractName}.sol`, `${contractName}.json`);
return new Promise((resolve, reject) => {
jsonfile.readFile(file, (error, contents) => {
let transformed;
Expand All @@ -72,13 +73,13 @@ class TruffleContractLoader {
}

async load(query, requiredProps = DEFAULT_REQUIRED_CONTRACT_PROPS) {
const { contractName, contractAddress, routerName, routerAddress, ...otherQuery } = query;
const { contractDir, contractName, contractAddress, routerName, routerAddress, ...otherQuery } = query;

if (!(contractName || contractAddress)) throw new TypeError("The field `contractName` or `contractAddress` must be supplied");

// Load the contract definition by either the contract name or address
const firstQuery = {
...(contractName ? { contractName } : { contractAddress }),
...(contractName ? { contractDir, contractName } : { contractAddress }),
...otherQuery,
};
const result = await this._load(firstQuery);
Expand Down
18 changes: 11 additions & 7 deletions packages/reputation-miner/ReputationMiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ class ReputationMiner {
* @return {Promise}
*/
async initialise(colonyNetworkAddress) {
this.colonyNetworkContractDef = await this.loader.load({ contractName: "IColonyNetwork" }, { abi: true, address: false });
this.repCycleContractDef = await this.loader.load({ contractName: "IReputationMiningCycle" }, { abi: true, address: false });
this.tokenLockingContractDef = await this.loader.load({ contractName: "ITokenLocking" }, { abi: true, address: false });
this.colonyContractDef = await this.loader.load({ contractName: "IColony" }, { abi: true, address: false });
const flags = { abi: true, address: false };

this.colonyNetworkContractDef = await this.loader.load({ contractDir: "colonyNetwork", contractName: "IColonyNetwork" }, flags);
this.repCycleContractDef = await this.loader.load({ contractDir: "reputationMiningCycle", contractName: "IReputationMiningCycle" }, flags);
this.tokenLockingContractDef = await this.loader.load({ contractDir: "tokenLocking", contractName: "ITokenLocking" }, flags);
this.colonyContractDef = await this.loader.load({ contractDir: "colony", contractName: "IColony" }, flags);

this.colonyNetwork = new ethers.Contract(colonyNetworkAddress, this.colonyNetworkContractDef.abi, this.realWallet);
const tokenLockingAddress = await this.colonyNetwork.getTokenLocking();
Expand All @@ -85,11 +87,13 @@ class ReputationMiner {
const metaColony = new ethers.Contract(metaColonyAddress, this.colonyContractDef.abi, this.realWallet);
this.clnyAddress = await metaColony.getToken();


if (!this.useJsTree) {
this.patriciaTreeContractDef = await this.loader.load({ contractName: "PatriciaTree" }, { abi: true, address: false, bytecode: true });
this.patriciaTreeContractDef = await this.loader.load(
{ contractDir: "patriciaTree", contractName: "PatriciaTree" },
{ ...flags, bytecode: true }
);
this.patriciaTreeNoHashContractDef = await this.loader.load(
{ contractName: "PatriciaTreeNoHash" },
{ contractDir: "patriciaTree", contractName: "PatriciaTreeNoHash" },
{ abi: true, address: false, bytecode: true }
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/reputation-miner/patricia-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const IColonyNetwork = artifacts.require("IColonyNetwork");
const PatriciaTree = artifacts.require("PatriciaTree");

const contractLoader = new TruffleLoader({
contractDir: path.resolve(__dirname, "..", "..", "build", "contracts")
contractRoot: path.resolve(__dirname, "../..", "artifacts", "contracts"),
});

contract("Javascript Patricia Tree", accounts => {
Expand Down
2 changes: 1 addition & 1 deletion test-gas-costs/gasCosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const IVotingReputation = artifacts.require("IVotingReputation");
const REAL_PROVIDER_PORT = process.env.SOLIDITY_COVERAGE ? 8555 : 8545;

const contractLoader = new TruffleLoader({
contractDir: path.resolve(__dirname, "..", "build", "contracts"),
contractRoot: path.resolve(__dirname, "../..", "artifacts", "contracts"),
});

contract("All", function (accounts) {
Expand Down
2 changes: 1 addition & 1 deletion test/contracts-network/colony-network-recovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const Resolver = artifacts.require("Resolver");
const ContractEditing = artifacts.require("ContractEditing");

const contractLoader = new TruffleLoader({
contractDir: path.resolve(__dirname, "../..", "build", "contracts"),
contractRoot: path.resolve(__dirname, "../..", "artifacts", "contracts"),
});

const REAL_PROVIDER_PORT = process.env.SOLIDITY_COVERAGE ? 8555 : 8545;
Expand Down
2 changes: 1 addition & 1 deletion test/contracts-network/colony-reward-payouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Token = artifacts.require("Token");
const DSRoles = artifacts.require("DSRoles");

const contractLoader = new TruffleLoader({
contractDir: path.resolve(__dirname, "../..", "build", "contracts"),
contractRoot: path.resolve(__dirname, "../..", "artifacts", "contracts"),
});

const REAL_PROVIDER_PORT = process.env.SOLIDITY_COVERAGE ? 8555 : 8545;
Expand Down
2 changes: 1 addition & 1 deletion test/contracts-network/token-locking.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const TestVotingToken = artifacts.require("TestVotingToken");
const Resolver = artifacts.require("Resolver");

const contractLoader = new TruffleLoader({
contractDir: path.resolve(__dirname, "../..", "build", "contracts"),
contractRoot: path.resolve(__dirname, "../..", "artifacts", "contracts"),
});

const REAL_PROVIDER_PORT = process.env.SOLIDITY_COVERAGE ? 8555 : 8545;
Expand Down

0 comments on commit 286c493

Please sign in to comment.