Skip to content

Commit

Permalink
Support for buidler tests (UMAprotocol#1735)
Browse files Browse the repository at this point in the history
* support for buidler tests

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* buidler in ci

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* timeout

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* mocha timeout + builds

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* truffle compile

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* addressed PR, and bumped gas

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* revert solidity-coverage

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* optimize by default

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* truffle test in ci

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* back to buidler

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>

* buidlerevm config

Signed-off-by: Kendrick Tan <kendricktan0814@gmail.com>
  • Loading branch information
kendricktan authored Jul 15, 2020
1 parent 8146cec commit 5ebaf49
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 64 deletions.
5 changes: 4 additions & 1 deletion ci/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ cd $TRUFFLE_DIR
# Truffle compile can take a lot of memory, which I've experienced with the solc-0.6 compatible versions,
# so I explicitly increase the javascript heap size.
# More details here: https://github.com/trufflesuite/truffle/issues/957
node --max-old-space-size=4096 $(npm bin)/truffle run coverage --temp build --network coverage && cat coverage/lcov.info | $(npm bin)/coveralls --verbose
# Truffle compile for DecodeTransactionData
node --max-old-space-size=4096 $(npm bin)/truffle compile
node --max-old-space-size=4096 $(npm bin)/buidler coverage && cat coverage/lcov.info | $(npm bin)/coveralls --verbose

2 changes: 1 addition & 1 deletion ci/run_truffle_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ run_tests() {
check_deployment ./ 1234 ci

# Run standard truffle tests
$(npm bin)/truffle test --network ci
$(npm bin)/buidler test
}

# Run tests for core.
Expand Down
17 changes: 14 additions & 3 deletions common/MigrationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,26 @@ async function deploy(deployer, network, contractType, ...args) {
const willDeploy = txnOptions.overwrite || !contractType.isDeployed();

// Deploy contract.
await deployer.deploy(contractType, ...args);
const contractInstance = await contractType.deployed();
let contractInstance;

// Buidler
if (contractType.setAsDeployed) {
contractInstance = await contractType.new(...args);
contractType.setAsDeployed(contractInstance);
}

// Truffle
else {
await deployer.deploy(contractType, ...args);
contractInstance = await contractType.deployed();
}

// Add to the registry.
await addToTdr(contractInstance, network);

// Return relevant info about the contract.
return {
contract: await contractType.deployed(),
contract: contractInstance,
didDeploy: willDeploy
};
}
Expand Down
2 changes: 2 additions & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache/
artifacts/
46 changes: 46 additions & 0 deletions core/buidler.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const chalkPipe = require("chalk-pipe");
const { usePlugin, task } = require("@nomiclabs/buidler/config");

usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("solidity-coverage");

task("test")
.addFlag("debug", "Compile without optimizer")
.setAction(async (taskArgs, bre, runSuper) => {
const { debug } = taskArgs;

if (debug) {
bre.config.solc.optimizer.enabled = false;
bre.config.solc.optimizer.allowUnlimitedContractSize = true;
bre.config.solc.optimizer.blockGasLimit = 0x1fffffffffffff;
bre.config.solc.optimizer.gas = 12000000;

console.log(chalkPipe("bold.underline")("Running tests in debug mode"));
}

await runSuper(taskArgs);
});

module.exports = {
solc: {
version: "0.6.6",
optimizer: {
enabled: true,
runs: 200
}
},
networks: {
buidlerevm: {
gas: 11500000,
blockGasLimit: 11500000,
allowUnlimitedContractSize: false,
timeout: 1800000
},
localhost: {
url: "http://127.0.0.1:8545"
}
},
mocha: {
timeout: 1800000
}
};
4 changes: 3 additions & 1 deletion core/migrations/10_deploy_designated_voting_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ const { getKeysForNetwork, deploy } = require("../../common/MigrationUtils.js");
module.exports = async function(deployer, network, accounts) {
const keys = getKeysForNetwork(network, accounts);

await deploy(deployer, network, DesignatedVotingFactory, Finder.address, { from: keys.deployer });
const finder = await Finder.deployed();

await deploy(deployer, network, DesignatedVotingFactory, finder.address, { from: keys.deployer });
};
24 changes: 20 additions & 4 deletions core/migrations/14_deploy_expiring_multi_party_creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,30 @@ module.exports = async function(deployer, network, accounts) {
from: keys.deployer
});

await collateralCurrencyWhitelist.addToWhitelist(TestnetERC20.address);
const testnetERC20 = await TestnetERC20.deployed();
await collateralCurrencyWhitelist.addToWhitelist(testnetERC20.address);

const timer = await Timer.deployed();
const finder = await Finder.deployed();
const tokenFactory = await TokenFactory.deployed();
const registry = await Registry.deployed();

// Deploy EMPLib and link to EMPCreator.
await deploy(deployer, network, ExpiringMultiPartyLib);
await deployer.link(ExpiringMultiPartyLib, ExpiringMultiPartyCreator);

// Buidler
if (ExpiringMultiPartyLib.setAsDeployed) {
const { contract: empLib } = await deploy(deployer, network, ExpiringMultiPartyLib);

// Due to how truffle-plugin works, it statefully links it
// and throws an error if its already linked. So we'll just ignore it...
try {
await ExpiringMultiPartyCreator.link(empLib);
} catch (e) {}
} else {
// Truffle
await deploy(deployer, network, ExpiringMultiPartyLib);
await deployer.link(ExpiringMultiPartyLib, ExpiringMultiPartyCreator);
}

const { contract: expiringMultiPartyCreator } = await deploy(
deployer,
Expand All @@ -34,7 +50,7 @@ module.exports = async function(deployer, network, accounts) {
finder.address,
collateralCurrencyWhitelist.address,
tokenFactory.address,
controllableTiming ? Timer.address : "0x0000000000000000000000000000000000000000",
controllableTiming ? timer.address : "0x0000000000000000000000000000000000000000",
{ from: keys.deployer }
);

Expand Down
4 changes: 3 additions & 1 deletion core/migrations/5_deploy_voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = async function(deployer, network, accounts) {
const keys = getKeysForNetwork(network, accounts);
const controllableTiming = enableControllableTiming(network);

const timer = await Timer.deployed();

// Deploy whitelist of identifiers
const { contract: identifierWhitelist } = await deploy(deployer, network, IdentifierWhitelist, {
from: keys.deployer
Expand Down Expand Up @@ -41,7 +43,7 @@ module.exports = async function(deployer, network, accounts) {
rewardsExpirationTimeout,
votingToken.address,
finder.address,
controllableTiming ? Timer.address : "0x0000000000000000000000000000000000000000",
controllableTiming ? timer.address : "0x0000000000000000000000000000000000000000",
{ from: keys.deployer }
);

Expand Down
4 changes: 3 additions & 1 deletion core/migrations/8_deploy_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = async function(deployer, network, accounts) {
const keys = getKeysForNetwork(network, accounts);
const controllableTiming = enableControllableTiming(network);

const timer = await Timer.deployed();

// Initialize both fees to 0.
const initialFixedOracleFeePerSecondPerPfc = { rawValue: "0" };
const initialWeeklyDelayFeePerSecondPerPfc = { rawValue: "0" };
Expand All @@ -19,7 +21,7 @@ module.exports = async function(deployer, network, accounts) {
Store,
initialFixedOracleFeePerSecondPerPfc,
initialWeeklyDelayFeePerSecondPerPfc,
controllableTiming ? Timer.address : "0x0000000000000000000000000000000000000000",
controllableTiming ? timer.address : "0x0000000000000000000000000000000000000000",
{ from: keys.deployer }
);

Expand Down
7 changes: 5 additions & 2 deletions core/migrations/9_deploy_governor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ module.exports = async function(deployer, network, accounts) {
const controllableTiming = enableControllableTiming(network);
const startingId = "0";

const timer = await Timer.deployed();
const finder = await Finder.deployed();

const { contract: governor } = await deploy(
deployer,
network,
Governor,
Finder.address,
finder.address,
startingId,
controllableTiming ? Timer.address : "0x0000000000000000000000000000000000000000",
controllableTiming ? timer.address : "0x0000000000000000000000000000000000000000",
{
from: keys.deployer
}
Expand Down
12 changes: 9 additions & 3 deletions core/test/common/Testable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ const TestableTest = artifacts.require("TestableTest");
const Timer = artifacts.require("Timer");

contract("Testable", function() {
let timer;

before(async () => {
timer = await Timer.deployed();
});

it("isTest on", async function() {
const testable = await TestableTest.new(Timer.address);
const testable = await TestableTest.new(timer.address);

await testable.setCurrentTime(0);
assert.equal(await testable.getCurrentTime(), 0);
Expand All @@ -23,8 +29,8 @@ contract("Testable", function() {
});

it("In test environment, different Testable contracts reference the same Timer", async function() {
const testable1 = await TestableTest.new(Timer.address);
const testable2 = await TestableTest.new(Timer.address);
const testable1 = await TestableTest.new(timer.address);
const testable2 = await TestableTest.new(timer.address);

// Set time on testable1, should be the same on testable2.
await testable1.setCurrentTime(0);
Expand Down
14 changes: 11 additions & 3 deletions core/test/financial-templates/ExpiringMultiParty.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ const Token = artifacts.require("ExpandedERC20");
const Timer = artifacts.require("Timer");

contract("ExpiringMultiParty", function(accounts) {
let finder, timer, tokenFactory;

beforeEach(async () => {
timer = await Timer.deployed();
finder = await Finder.deployed();
tokenFactory = await TokenFactory.deployed();
});

it("Can deploy", async function() {
const collateralToken = await Token.new("UMA", "UMA", 18, { from: accounts[0] });

const constructorParams = {
expirationTimestamp: (Math.round(Date.now() / 1000) + 1000).toString(),
withdrawalLiveness: "1000",
collateralAddress: collateralToken.address,
finderAddress: Finder.address,
tokenFactoryAddress: TokenFactory.address,
finderAddress: finder.address,
tokenFactoryAddress: tokenFactory.address,
priceFeedIdentifier: web3.utils.utf8ToHex("UMATEST"),
syntheticName: "Test UMA Token",
syntheticSymbol: "UMATEST",
Expand All @@ -29,7 +37,7 @@ contract("ExpiringMultiParty", function(accounts) {
sponsorDisputeRewardPct: { rawValue: toWei("0.1") },
disputerDisputeRewardPct: { rawValue: toWei("0.1") },
minSponsorTokens: { rawValue: toWei("1") },
timerAddress: Timer.address
timerAddress: timer.address
};

identifierWhitelist = await IdentifierWhitelist.deployed();
Expand Down
3 changes: 2 additions & 1 deletion core/test/financial-templates/ExpiringMultiPartyCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ contract("ExpiringMultiPartyCreator", function(accounts) {
});

it("TokenFactory address should be set on construction", async function() {
assert.equal(await expiringMultiPartyCreator.tokenFactoryAddress(), (await TokenFactory.deployed()).address);
const tokenFactory = await TokenFactory.deployed();
assert.equal(await expiringMultiPartyCreator.tokenFactoryAddress(), tokenFactory.address);
});

it("Expiration timestamp must be one of the allowed timestamps", async function() {
Expand Down
10 changes: 6 additions & 4 deletions core/test/financial-templates/Liquidatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ contract("Liquidatable", function(accounts) {
const timer = await Timer.deployed();
await timer.setCurrentTime(startTime);

const tokenFactory = await TokenFactory.deployed();

// Create Collateral and Synthetic ERC20's
collateralToken = await Token.new("UMA", "UMA", 18, { from: contractDeployer });

Expand All @@ -109,7 +111,7 @@ contract("Liquidatable", function(accounts) {

// Create a mockOracle and get the deployed finder. Register the mockMoracle with the finder.
finder = await Finder.deployed();
mockOracle = await MockOracle.new(finder.address, Timer.address, {
mockOracle = await MockOracle.new(finder.address, timer.address, {
from: contractDeployer
});

Expand All @@ -122,8 +124,8 @@ contract("Liquidatable", function(accounts) {
expirationTimestamp: expirationTimestamp,
withdrawalLiveness: withdrawalLiveness.toString(),
collateralAddress: collateralToken.address,
finderAddress: Finder.address,
tokenFactoryAddress: TokenFactory.address,
finderAddress: finder.address,
tokenFactoryAddress: tokenFactory.address,
priceFeedIdentifier: priceFeedIdentifier,
syntheticName: "Test UMA Token",
syntheticSymbol: "UMAETH",
Expand All @@ -133,7 +135,7 @@ contract("Liquidatable", function(accounts) {
sponsorDisputeRewardPct: { rawValue: sponsorDisputeRewardPct.toString() },
disputerDisputeRewardPct: { rawValue: disputerDisputeRewardPct.toString() },
minSponsorTokens: { rawValue: minSponsorTokens.toString() },
timerAddress: Timer.address
timerAddress: timer.address
};

// Deploy liquidation contract and set global params
Expand Down
Loading

0 comments on commit 5ebaf49

Please sign in to comment.