Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@openzeppelin/contracts": "^3.3.0",
"@openzeppelin/test-helpers": "^0.5.10",
"eth-gas-reporter": "^0.2.22",
"ganache-time-traveler": "1.0.15",
"hardhat": "^2.1.1",
"hardhat-gas-reporter": "^1.0.1",
"npm-run-all": "^4.1.5",
Expand Down
16 changes: 14 additions & 2 deletions packages/contracts/test/BorrowerOperationsTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const deploymentHelper = require("../utils/deploymentHelpers.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');

const BorrowerOperationsTester = artifacts.require("./BorrowerOperationsTester.sol")
const NonPayable = artifacts.require('NonPayable.sol')
Expand Down Expand Up @@ -67,7 +68,7 @@ contract('BorrowerOperations', async accounts => {
})

const testCorpus = ({ withProxy = false }) => {
beforeEach(async () => {
before(async () => {
contracts = await deploymentHelper.deployLiquityCore()
contracts.borrowerOperations = await BorrowerOperationsTester.new()
contracts.troveManager = await TroveManagerTester.new()
Expand Down Expand Up @@ -103,6 +104,17 @@ contract('BorrowerOperations', async accounts => {
BORROWING_FEE_FLOOR = await borrowerOperations.BORROWING_FEE_FLOOR()
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it("addColl(): reverts when top-up would leave trove with ICR < MCR", async () => {
// alice creates a Trove and adds first collateral
await openTrove({ ICR: toBN(dec(2, 18)), extraParams: { from: alice } })
Expand All @@ -117,7 +129,7 @@ contract('BorrowerOperations', async accounts => {

const collTopUp = 1 // 1 wei top up

await assertRevert(borrowerOperations.addColl(alice, alice, { from: alice, value: collTopUp }),
await assertRevert(borrowerOperations.addColl(alice, alice, { from: alice, value: collTopUp }),
"BorrowerOps: An operation that would result in ICR < MCR is not permitted")
})

Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/test/CollSurplusPool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const deploymentHelper = require("../utils/deploymentHelpers.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');
const NonPayable = artifacts.require('NonPayable.sol')

const th = testHelpers.TestHelper
Expand Down Expand Up @@ -27,7 +28,7 @@ contract('CollSurplusPool', async accounts => {
const getOpenTroveLUSDAmount = async (totalDebt) => th.getOpenTroveLUSDAmount(contracts, totalDebt)
const openTrove = async (params) => th.openTrove(contracts, params)

beforeEach(async () => {
before(async () => {
contracts = await deploymentHelper.deployLiquityCore()
contracts.troveManager = await TroveManagerTester.new()
contracts.lusdToken = await LUSDToken.new(
Expand All @@ -46,6 +47,17 @@ contract('CollSurplusPool', async accounts => {
await deploymentHelper.connectLQTYContractsToCore(LQTYContracts, contracts)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it("CollSurplusPool::getETH(): Returns the ETH balance of the CollSurplusPool after redemption", async () => {
const ETH_1 = await collSurplusPool.getETH()
assert.equal(ETH_1, '0')
Expand Down
17 changes: 13 additions & 4 deletions packages/contracts/test/FeeArithmeticTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Decimal = require("decimal.js");
const deploymentHelper = require("../utils/deploymentHelpers.js")
const { BNConverter } = require("../utils/BNConverter.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');
const TroveManagerTester = artifacts.require("./TroveManagerTester.sol")
const LiquityMathTester = artifacts.require("./LiquityMathTester.sol")

Expand Down Expand Up @@ -336,17 +337,25 @@ contract('Fee arithmetic tests', async accounts => {

mathTester = await LiquityMathTester.new()
LiquityMathTester.setAsDeployed(mathTester)
})

beforeEach(async () => {
contracts = await deploymentHelper.deployLiquityCore()
const LQTYContracts = await deploymentHelper.deployLQTYContracts(bountyAddress, lpRewardsAddress, multisig)

await deploymentHelper.connectLQTYContracts(LQTYContracts)
await deploymentHelper.connectCoreContracts(contracts, LQTYContracts)
await deploymentHelper.connectLQTYContractsToCore(LQTYContracts, contracts)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it("minutesPassedSinceLastFeeOp(): returns minutes passed for no time increase", async () => {
await troveManagerTester.setLastFeeOpTimeToNow()
const minutesPassed = await troveManagerTester.minutesPassedSinceLastFeeOp()
Expand Down
19 changes: 14 additions & 5 deletions packages/contracts/test/GasCompensationTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const deploymentHelper = require("../utils/deploymentHelpers.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');
const TroveManagerTester = artifacts.require("./TroveManagerTester.sol")
const BorrowerOperationsTester = artifacts.require("./BorrowerOperationsTester.sol")
const LUSDToken = artifacts.require("LUSDToken")
Expand Down Expand Up @@ -46,9 +47,6 @@ contract('Gas compensation tests', async accounts => {

TroveManagerTester.setAsDeployed(troveManagerTester)
BorrowerOperationsTester.setAsDeployed(borrowerOperationsTester)
})

beforeEach(async () => {
contracts = await deploymentHelper.deployLiquityCore()
contracts.troveManager = await TroveManagerTester.new()
contracts.lusdToken = await LUSDToken.new(
Expand All @@ -57,7 +55,7 @@ contract('Gas compensation tests', async accounts => {
contracts.borrowerOperations.address
)
const LQTYContracts = await deploymentHelper.deployLQTYContracts(bountyAddress, lpRewardsAddress, multisig)

priceFeed = contracts.priceFeedTestnet
lusdToken = contracts.lusdToken
sortedTroves = contracts.sortedTroves
Expand All @@ -66,12 +64,23 @@ contract('Gas compensation tests', async accounts => {
stabilityPool = contracts.stabilityPool
defaultPool = contracts.defaultPool
borrowerOperations = contracts.borrowerOperations

await deploymentHelper.connectLQTYContracts(LQTYContracts)
await deploymentHelper.connectCoreContracts(contracts, LQTYContracts)
await deploymentHelper.connectLQTYContractsToCore(LQTYContracts, contracts)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

// --- Raw gas compensation calculations ---

it('_getCollGasCompensation(): returns the 0.5% of collaterall if it is < $10 in value', async () => {
Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/test/GrowthTokenTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const deploymentHelper = require("../utils/deploymentHelpers.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');

const { keccak256 } = require('@ethersproject/keccak256');
const { defaultAbiCoder } = require('@ethersproject/abi');
Expand Down Expand Up @@ -107,7 +108,7 @@ contract('LQTY Token', async accounts => {
return { v, r, s, tx }
}

beforeEach(async () => {
before(async () => {
contracts = await deploymentHelper.deployLiquityCore()
const LQTYContracts = await deploymentHelper.deployLQTYTesterContractsHardhat(bountyAddress, lpRewardsAddress, multisig)

Expand All @@ -124,6 +125,17 @@ contract('LQTY Token', async accounts => {
await deploymentHelper.connectLQTYContractsToCore(LQTYContracts, contracts)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it('balanceOf(): gets the balance of the account', async () => {
await mintToABC()

Expand Down
16 changes: 12 additions & 4 deletions packages/contracts/test/LQTYIssuanceArithmeticTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Decimal = require("decimal.js");
const deploymentHelper = require("../utils/deploymentHelpers.js")
const { BNConverter } = require("../utils/BNConverter.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');
const StabilityPool = artifacts.require("./StabilityPool.sol")

const th = testHelpers.TestHelper
Expand Down Expand Up @@ -45,10 +46,6 @@ contract('LQTY community issuance arithmetic tests', async accounts => {
const [bountyAddress, lpRewardsAddress, multisig] = accounts.slice(997, 1000)

before(async () => {

})

beforeEach(async () => {
contracts = await deploymentHelper.deployLiquityCore()
const LQTYContracts = await deploymentHelper.deployLQTYTesterContractsHardhat(bountyAddress, lpRewardsAddress, multisig)
contracts.stabilityPool = await StabilityPool.new()
Expand All @@ -65,6 +62,17 @@ contract('LQTY community issuance arithmetic tests', async accounts => {
await deploymentHelper.connectLQTYContractsToCore(LQTYContracts, contracts)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

// Accuracy tests
it("getCumulativeIssuanceFraction(): fraction doesn't increase if less than a minute has passed", async () => {
// progress time 1 week
Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/test/LQTYStakingFeeRewardsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Decimal = require("decimal.js");
const deploymentHelper = require("../utils/deploymentHelpers.js")
const { BNConverter } = require("../utils/BNConverter.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');

const LQTYStakingTester = artifacts.require('LQTYStakingTester')
const TroveManagerTester = artifacts.require("TroveManagerTester")
Expand Down Expand Up @@ -45,7 +46,7 @@ contract('LQTYStaking revenue share tests', async accounts => {

const openTrove = async (params) => th.openTrove(contracts, params)

beforeEach(async () => {
before(async () => {
contracts = await deploymentHelper.deployLiquityCore()
contracts.troveManager = await TroveManagerTester.new()
contracts = await deploymentHelper.deployLUSDTokenTester(contracts)
Expand All @@ -70,6 +71,17 @@ contract('LQTYStaking revenue share tests', async accounts => {
lqtyStaking = LQTYContracts.lqtyStaking
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it('stake(): reverts if amount is zero', async () => {
// FF time one year so owner can transfer LQTY
await th.fastForwardTime(timeValues.SECONDS_IN_ONE_YEAR, web3.currentProvider)
Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/test/LUSDTokenTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const deploymentHelper = require("../utils/deploymentHelpers.js")
const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');

const { keccak256 } = require('@ethersproject/keccak256');
const { defaultAbiCoder } = require('@ethersproject/abi');
Expand Down Expand Up @@ -64,7 +65,7 @@ contract('LUSDToken', async accounts => {
let tokenVersion

const testCorpus = ({ withProxy = false }) => {
beforeEach(async () => {
before(async () => {

const contracts = await deploymentHelper.deployTesterContractsHardhat()

Expand Down Expand Up @@ -105,6 +106,17 @@ contract('LUSDToken', async accounts => {
}
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it('balanceOf(): gets the balance of the account', async () => {
const aliceBalance = (await lusdTokenTester.balanceOf(alice)).toNumber()
const bobBalance = (await lusdTokenTester.balanceOf(bob)).toNumber()
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/LiquitySafeMath128Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const LiquitySafeMath128Tester = artifacts.require("LiquitySafeMath128Tester")
contract('LiquitySafeMath128Tester', async accounts => {
let mathTester

beforeEach(async () => {
before(async () => {
mathTester = await LiquitySafeMath128Tester.new()
})

Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/test/PoolsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DefaultPool = artifacts.require("./DefaultPool.sol")
const NonPayable = artifacts.require("./NonPayable.sol")

const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');

const th = testHelpers.TestHelper
const dec = th.dec
Expand All @@ -18,13 +19,24 @@ contract('StabilityPool', async accounts => {

const [owner, alice] = accounts;

beforeEach(async () => {
before(async () => {
stabilityPool = await StabilityPool.new()
const mockActivePoolAddress = (await NonPayable.new()).address
const dumbContractAddress = (await NonPayable.new()).address
await stabilityPool.setAddresses(dumbContractAddress, dumbContractAddress, mockActivePoolAddress, dumbContractAddress, dumbContractAddress, dumbContractAddress, dumbContractAddress)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

it('getETH(): gets the recorded ETH balance', async () => {
const recordedETHBalance = await stabilityPool.getETH()
assert.equal(recordedETHBalance, 0)
Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/test/PriceFeedTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const MockTellor = artifacts.require("./MockTellor.sol")
const TellorCaller = artifacts.require("./TellorCaller.sol")

const testHelpers = require("../utils/testHelpers.js")
const timeMachine = require('ganache-time-traveler');
const th = testHelpers.TestHelper

const { dec, assertRevert, toBN } = th
Expand All @@ -22,7 +23,7 @@ contract('PriceFeed', async accounts => {
await priceFeed.setAddresses(mockChainlink.address, tellorCaller.address, { from: owner })
}

beforeEach(async () => {
before(async () => {
priceFeedTestnet = await PriceFeedTestnet.new()
PriceFeedTestnet.setAsDeployed(priceFeedTestnet)

Expand Down Expand Up @@ -56,6 +57,17 @@ contract('PriceFeed', async accounts => {
await mockTellor.setUpdateTime(now)
})

let revertToSnapshot;

beforeEach(async() => {
let snapshot = await timeMachine.takeSnapshot();
revertToSnapshot = () => timeMachine.revertToSnapshot(snapshot['result'])
});

afterEach(async() => {
await revertToSnapshot();
});

describe('PriceFeed internal testing contract', async accounts => {
it("fetchPrice before setPrice should return the default price", async () => {
const price = await priceFeedTestnet.getPrice()
Expand Down
Loading