From ea70633ad671b04931f9ef1192e9b82a78137850 Mon Sep 17 00:00:00 2001 From: elenadimitrova Date: Fri, 16 Oct 2020 16:42:57 +0300 Subject: [PATCH] Fixing tests including: - Calling overloaded functions with different syntax due to an issue with truffle - Changing .mul to BigNumber.times - Change ethers.utils.parseEther to web3.utils.toWei - Fix an issue finding events from the Relayer --- scripts/deploy_defi.js | 10 +- test/baseWallet.js | 29 ++--- test/compoundManager_invest.js | 50 ++++---- test/compoundManager_loan.js | 207 ++++++++++++++++----------------- test/makerV2Manager_invest.js | 4 +- test/makerV2Manager_loan.js | 8 +- test/multisig.js | 2 +- test/transferManager.js | 4 +- utils/defi-deployer.js | 4 +- utils/relay-manager.js | 1 + utils/utilities.js | 2 +- 11 files changed, 162 insertions(+), 159 deletions(-) diff --git a/scripts/deploy_defi.js b/scripts/deploy_defi.js index f7a48001a..259877e1a 100644 --- a/scripts/deploy_defi.js +++ b/scripts/deploy_defi.js @@ -17,10 +17,10 @@ const DSValue = artifacts.require("DSValue"); const RAY = new BigNumber("1000000000000000000000000000"); // 10**27 const WAD = new BigNumber("1000000000000000000"); // 10**18 const USD_PER_DAI = RAY; // 1 DAI = 1 USD -const USD_PER_ETH = WAD.mul(250); // 1 ETH = 250 USD -const USD_PER_MKR = WAD.mul(700); // 1 MKR = 700 USD +const USD_PER_ETH = WAD.times(250); // 1 ETH = 250 USD +const USD_PER_MKR = WAD.times(700); // 1 MKR = 700 USD -const ETH_PER_MKR = WAD.mul(USD_PER_MKR).div(USD_PER_ETH); // 1 MKR = 2.8 ETH +const ETH_PER_MKR = WAD.times(USD_PER_MKR).div(USD_PER_ETH); // 1 MKR = 2.8 ETH async function getTimestamp(deployer) { const block = await deployer.provider.getBlock("latest"); @@ -71,7 +71,7 @@ async function deploy() { // set the total DAI debt ceiling to 50,000 DAI await tub.mold(formatBytes32String("cap"), parseEther("50000")); // set the liquidity ratio to 150% - await tub.mold(formatBytes32String("mat"), RAY.mul(3).div(2)); + await tub.mold(formatBytes32String("mat"), RAY.times(3).div(2)); // set the governance fee to 7.5% APR await tub.mold(formatBytes32String("fee"), "1000000002293273137447730714", { gasLimit: 150000 }); // set the liquidation penalty to 13% @@ -86,7 +86,7 @@ async function deploy() { /* *************** create MKR exchange ***************** */ const ethLiquidity = parseEther("1"); - const mkrLiquidity = ethLiquidity.mul(WAD).div(ETH_PER_MKR); + const mkrLiquidity = ethLiquidity.times(WAD).div(ETH_PER_MKR); await gov["mint(address,uint256)"](manager, mkrLiquidity); await uniswapFactory.createExchange(gov.address, { gasLimit: 450000 }); diff --git a/test/baseWallet.js b/test/baseWallet.js index a6a70400d..16a07ff7e 100644 --- a/test/baseWallet.js +++ b/test/baseWallet.js @@ -1,5 +1,6 @@ /* global artifacts */ const ethers = require("ethers"); +const { BigNumber } = require("bignumber.js"); const Proxy = artifacts.require("Proxy"); const BaseWallet = artifacts.require("BaseWallet"); @@ -29,13 +30,13 @@ contract("BaseWallet", (accounts) => { let lockStorage; async function deployTestModule() { - const module = await deployer.deploy(VersionManager, {}, + const module = await VersionManager.new( registry.address, lockStorage.address, guardianStorage.address, ethers.constants.AddressZero, ethers.constants.AddressZero); - const feature = await deployer.deploy(TestFeature, {}, + const feature = await TestFeature.new( lockStorage.address, module.address, true, @@ -64,7 +65,7 @@ contract("BaseWallet", (accounts) => { it("should register a module with the correct info", async () => { const name = ethers.utils.formatBytes32String("module1"); await registry.registerModule(module1.address, name); - const isRegistered = await registry.isRegisteredModule(module1.address); + const isRegistered = await registry.contract.methods['isRegisteredModule(address)'](module1.address).call(); assert.isTrue(isRegistered, "module should be registered"); const info = await registry.moduleInfo(module1.address); assert.equal(name, info, "name should be correct"); @@ -73,10 +74,10 @@ contract("BaseWallet", (accounts) => { it("should deregister a module", async () => { const name = ethers.utils.formatBytes32String("module2"); await registry.registerModule(module2.address, name); - let isRegistered = await registry.isRegisteredModule(module2.address); + let isRegistered = await registry.contract.methods['isRegisteredModule(address)'](module2.address).call(); assert.isTrue(isRegistered, "module should be registered"); await registry.deregisterModule(module2.address); - isRegistered = await registry.isRegisteredModule(module2.address); + isRegistered = await registry.contract.methods['isRegisteredModule(address)'](module2.address).call(); assert.isFalse(isRegistered, "module should be deregistered"); }); @@ -148,7 +149,7 @@ contract("BaseWallet", (accounts) => { it("should accept ETH with data", async () => { const before = await getBalance(wallet.address); - await wallet.send(50000000, { data: 0x1234 }); + await web3.eth.sendTransaction({ from: accounts[0], to: wallet.address, data: "0x1234", value: 50000000 }); const after = await getBalance(wallet.address); assert.equal(after.sub(before).toNumber(), 50000000, "should have received ETH"); }); @@ -174,10 +175,10 @@ contract("BaseWallet", (accounts) => { await module1.upgradeWallet(wallet.address, await module1.lastVersion(), { from: owner }); const module1IsAuthorised = await wallet.authorised(module1.address); assert.equal(module1IsAuthorised, true, "module1 should be authorised"); - const walletAsFeature = deployer.wrapDeployedContract(TestFeature, wallet.address); - const boolVal = await walletAsFeature.contract.getBoolean(); - const uintVal = await walletAsFeature.contract.getUint(); - const addressVal = await walletAsFeature.contract.getAddress(nonowner); + const walletAsFeature = await TestFeature.at(wallet.address); + const boolVal = await walletAsFeature.getBoolean(); + const uintVal = await walletAsFeature.getUint(); + const addressVal = await walletAsFeature.getAddress(nonowner); assert.equal(boolVal, true, "should have the correct bool"); assert.equal(uintVal, 42, "should have the correct uint"); assert.equal(addressVal, nonowner, "should have the address"); @@ -190,7 +191,7 @@ contract("BaseWallet", (accounts) => { assert.equal(module1IsAuthorised, true, "module1 should be authorised"); // removing module 1 - const upgrader = await deployer.deploy(SimpleUpgrader, {}, + const upgrader = await SimpleUpgrader.new( registry.address, lockStorage.address, [module1.address], []); await registry.registerModule(upgrader.address, ethers.utils.formatBytes32String("Removing module1")); await module1.addModule(wallet.address, upgrader.address, { from: owner }); @@ -199,14 +200,14 @@ contract("BaseWallet", (accounts) => { // trying to execute static call delegated to module1 (it should fail) const walletAsModule = await TestFeature.at(wallet.address); - await assertRevert(walletAsModule.getBoolean(), "BW: must be an authorised module for static call"); + await assertRevert(walletAsModule.contract.methods.getBoolean(), "BW: must be an authorised module for static call"); }); }); }); describe("Old BaseWallet V1.3", () => { it("should work with new modules", async () => { - const oldWallet = await deployer.deploy(OldWalletV13); + const oldWallet = await OldWalletV13.new(); await oldWallet.init(owner, [module1.address]); await module1.upgradeWallet(oldWallet.address, await module1.lastVersion(), { from: owner }); await feature1.callDapp(oldWallet.address); @@ -217,7 +218,7 @@ contract("BaseWallet", (accounts) => { describe("Old BaseWallet V1.6", () => { it("should work with new modules", async () => { - const oldWallet = await deployer.deploy(OldWalletV16); + const oldWallet = await OldWalletV16.new(); await oldWallet.init(owner, [module1.address]); await module1.upgradeWallet(oldWallet.address, await module1.lastVersion(), { from: owner }); await feature1.callDapp(oldWallet.address); diff --git a/test/compoundManager_invest.js b/test/compoundManager_invest.js index c0328a0ff..6cc334082 100644 --- a/test/compoundManager_invest.js +++ b/test/compoundManager_invest.js @@ -1,7 +1,7 @@ /* global artifacts */ -const { parseEther, formatBytes32String } = require("ethers").utils; +const { formatBytes32String } = require("ethers").utils; const ethers = require("ethers"); -const { BigNumber } = require("bignumber.js"); +const { BN } = require("bn.js"); const utils = require("../utils/utilities.js"); const GuardianStorage = artifacts.require("GuardianStorage"); @@ -23,8 +23,8 @@ const CEther = artifacts.require("CEther"); const CErc20 = artifacts.require("CErc20"); const CompoundRegistry = artifacts.require("CompoundRegistry"); -const WAD = new BigNumber("1000000000000000000"); // 10**18 -const ETH_EXCHANGE_RATE = new BigNumber("200000000000000000000000000"); +const WAD = new BN("1000000000000000000"); // 10**18 +const ETH_EXCHANGE_RATE = new BN("200000000000000000000000000"); const ERC20 = artifacts.require("TestERC20"); @@ -62,9 +62,9 @@ contract("Invest Manager with Compound", (accounts) => { const comptrollerImpl = await Comptroller.new(); await comptrollerProxy._setPendingImplementation(comptrollerImpl.address); await comptrollerImpl._become(comptrollerProxy.address, oracle.address, WAD.div(10), 5, false); - comptroller = Comptroller.at(comptrollerProxy.address); + comptroller = await Comptroller.at(comptrollerProxy.address); // deploy Interest rate model - const interestModel = await InterestModel.new(WAD.mul(250).div(10000), WAD.mul(2000).div(10000)); + const interestModel = await InterestModel.new(WAD.times(250).div(10000), WAD.times(2000).div(10000)); // deploy CEther cEther = await CEther.new( comptrollerProxy.address, @@ -100,9 +100,10 @@ contract("Invest Manager with Compound", (accounts) => { await comptroller._setCollateralFactor(cEther.address, WAD.div(10)); // add liquidity to tokens - await cEther.mint({ value: parseEther("100"), from: liquidityProvider }); - await token.approve(cToken.address, parseEther("100"), { from: liquidityProvider }); - await cToken.mint(parseEther("10"), { from: liquidityProvider }); + const tenEther = await web3.utils.toWei("10", "ether"); + await cEther.mint({ value: tenEther, from: liquidityProvider }); + await token.approve(cToken.address, tenEther, { from: liquidityProvider }); + await cToken.mint(web3.utils.toWei("1", "ether"), { from: liquidityProvider }); /* Deploy Argent Architecture */ @@ -158,6 +159,7 @@ contract("Invest Manager with Compound", (accounts) => { const cOracle = await comptroller.oracle(); assert.isTrue(cOracle === oracleProxy.address, "oracle should be registered"); const cTokenPrice = await oracleProxy.getUnderlyingPrice(cToken.address); + console.log("cTokenPrice", cTokenPrice) assert.isTrue(cTokenPrice.eq(WAD.div(10)), "cToken price should be 1e17"); const cEtherPrice = await oracleProxy.getUnderlyingPrice(cEther.address); assert.isTrue(cEtherPrice.eq(WAD), "cEther price should be 1e18"); @@ -170,13 +172,13 @@ contract("Invest Manager with Compound", (accounts) => { // generate borrows to create interests await comptroller.enterMarkets([cEther.address, cToken.address], { from: borrower }); if (investInEth) { - await token.approve(cToken.address, parseEther("20"), { from: borrower }); - await cToken.mint(parseEther("20"), { from: borrower }); - tx = await cEther.borrow(parseEther("0.1"), { from: borrower }); + await token.approve(cToken.address, web3.utils.toWei("20", "ether"), { from: borrower }); + await cToken.mint(web3.utils.toWei("20", "ether"), { from: borrower }); + tx = await cEther.borrow(web3.utils.toWei("0.1", "ether"), { from: borrower }); await utils.hasEvent(tx.receipt, "Borrow"); } else { - await cEther.mint({ value: parseEther("2"), from: borrower }); - tx = await cToken.borrow(parseEther("0.1"), { from: borrower }); + await cEther.mint({ value: web3.utils.toWei("2", "ether"), from: borrower }); + tx = await cToken.borrow(web3.utils.toWei("0.1", "ether"), { from: borrower }); await utils.hasEvent(tx.receipt, "Borrow"); } // increase time to accumulate interests @@ -203,7 +205,7 @@ contract("Invest Manager with Compound", (accounts) => { txReceipt = tx.receipt; } - await utils.hasEvent(txReceipt, "InvestmentAdded"); + await utils.hasEvent(txReceipt, "CompoundManager.InvestmentAdded"); await accrueInterests(days, investInEth); @@ -218,7 +220,7 @@ contract("Invest Manager with Compound", (accounts) => { txReceipt; const investInEth = (tokenAddress === ETH_TOKEN); - await addInvestment(tokenAddress, parseEther("0.1"), 365, false); + await addInvestment(tokenAddress, web3.utils.toWei("0.1", "ether"), 365, false); const before = investInEth ? await cEther.balanceOf(wallet.address) : await cToken.balanceOf(wallet.address); const params = [wallet.address, tokenAddress, fraction]; @@ -238,25 +240,25 @@ contract("Invest Manager with Compound", (accounts) => { // Successes it("should invest in ERC20 for 1 year and gain interests (blockchain tx)", async () => { - await addInvestment(token.address, parseEther("1"), 365, false); + await addInvestment(token.address, web3.utils.toWei("1", "ether"), 365, false); }); it("should invest in ERC20 for 1 year and gain interests (relay tx)", async () => { - await addInvestment(token.address, parseEther("1"), 365, true); + await addInvestment(token.address, web3.utils.toWei("1", "ether"), 365, true); }); it("should invest in ETH for 1 year and gain interests (blockchain tx)", async () => { - await addInvestment(ETH_TOKEN, parseEther("1"), 365, false); + await addInvestment(ETH_TOKEN, web3.utils.toWei("1", "ether"), 365, false); }); it("should invest in ETH for 1 year and gain interests (relay tx)", async () => { - await addInvestment(ETH_TOKEN, parseEther("1"), 365, true); + await addInvestment(ETH_TOKEN, web3.utils.toWei("1", "ether"), 365, true); }); // Reverts it("should fail to invest in ERC20 with an unknown token", async () => { - const params = [wallet.address, ethers.constants.AddressZero, parseEther("1"), 0]; + const params = [wallet.address, ethers.constants.AddressZero, web3.utils.toWei("1", "ether"), 0]; await utils.assertRevert(investManager.addInvestment(...params, { from: owner }), "CM: No market for target token"); }); @@ -266,7 +268,7 @@ contract("Invest Manager with Compound", (accounts) => { }); it("should fail to invest in ERC20 when not holding any ERC20", async () => { - const params = [wallet.address, token.address, parseEther("1"), 0]; + const params = [wallet.address, token.address, web3.utils.toWei("1", "ether"), 0]; await utils.assertRevert(investManager.addInvestment(...params, { from: owner }), "CM: mint failed"); }); }); @@ -305,8 +307,8 @@ contract("Invest Manager with Compound", (accounts) => { }); it("should fail to remove all of an ERC20 investment when it collateralizes a loan", async () => { - const collateralAmount = parseEther("1"); - const debtAmount = parseEther("0.001"); + const collateralAmount = await web3.utils.toWei("1", "ether"); + const debtAmount = await web3.utils.toWei("0.001", "ether"); await token.transfer(wallet.address, collateralAmount); const openLoanParams = [ wallet.address, diff --git a/test/compoundManager_loan.js b/test/compoundManager_loan.js index 3740fa9c2..d888d4f61 100644 --- a/test/compoundManager_loan.js +++ b/test/compoundManager_loan.js @@ -1,7 +1,6 @@ /* global artifacts */ const ethers = require("ethers"); -const { parseEther } = require("ethers").utils; const { BigNumber } = require("bignumber.js"); const utils = require("../utils/utilities.js"); @@ -70,7 +69,7 @@ contract("Loan Module", (accounts) => { await comptrollerImpl._become(comptrollerProxy.address, oracle.address, WAD.div(10), 5, false); comptroller = await Comptroller.at(comptrollerProxy.address); // deploy Interest rate model - const interestModel = await InterestModel.new(WAD.mul(250).div(10000), WAD.mul(2000).div(10000)); + const interestModel = await InterestModel.new(WAD.times(250).div(10000), WAD.times(2000).div(10000)); // deploy CEther cEther = await CEther.new( comptroller.address, @@ -120,11 +119,11 @@ contract("Loan Module", (accounts) => { await comptroller._setCollateralFactor(cEther.address, WAD.div(10)); // add liquidity to tokens - await cEther.mint({ value: parseEther("100"), from: liquidityProvider }); - await token1.approve(cToken1.address, parseEther("10"), { from: liquidityProvider }); - await cToken1.mint(parseEther("10"), { from: liquidityProvider }); - await token2.approve(cToken2.address, parseEther("10"), { from: liquidityProvider }); - await cToken2.mint(parseEther("10"), { from: liquidityProvider }); + await cEther.mint({ value: web3.utils.toWei("100", "ether"), from: liquidityProvider }); + await token1.approve(cToken1.address, web3.utils.toWei("10", "ether"), { from: liquidityProvider }); + await cToken1.mint(web3.utils.toWei("10", "ether"), { from: liquidityProvider }); + await token2.approve(cToken2.address, web3.utils.toWei("10", "ether"), { from: liquidityProvider }); + await cToken2.mint(web3.utils.toWei("10", "ether"), { from: liquidityProvider }); /* Deploy Argent Architecture */ @@ -284,8 +283,8 @@ contract("Loan Module", (accounts) => { describe("Open Loan", () => { it("should borrow token with ETH as collateral (blockchain tx)", async () => { - const collateralAmount = parseEther("0.1"); - const debtAmount = parseEther("0.05"); + const collateralAmount = await web3.utils.toWei("0.1"); + const debtAmount = await web3.utils.toWei("0.05"); await fundWallet({ ethAmount: collateralAmount, token1Amount: 0 }); await testOpenLoan({ collateral: ETH_TOKEN, collateralAmount, debt: token1, debtAmount, relayed: false, @@ -293,8 +292,8 @@ contract("Loan Module", (accounts) => { }); it("should borrow ETH with token as collateral (blockchain tx)", async () => { - const collateralAmount = parseEther("0.5"); - const debtAmount = parseEther("0.001"); + const collateralAmount = await web3.utils.toWei("0.5"); + const debtAmount = await web3.utils.toWei("0.001"); await fundWallet({ ethAmount: 0, token1Amount: collateralAmount }); await testOpenLoan({ collateral: token1, collateralAmount, debt: ETH_TOKEN, debtAmount, relayed: false, @@ -302,8 +301,8 @@ contract("Loan Module", (accounts) => { }); it("should borrow token with ETH as collateral (relay tx)", async () => { - const collateralAmount = parseEther("0.1"); - const debtAmount = parseEther("0.05"); + const collateralAmount = await web3.utils.toWei("0.1"); + const debtAmount = await web3.utils.toWei("0.05"); await fundWallet({ ethAmount: collateralAmount, token1Amount: 0 }); await testOpenLoan({ collateral: ETH_TOKEN, collateralAmount, debt: token1, debtAmount, relayed: true, @@ -311,8 +310,8 @@ contract("Loan Module", (accounts) => { }); it("should borrow ETH with token as collateral (relay tx)", async () => { - const collateralAmount = parseEther("0.5"); - const debtAmount = parseEther("0.001"); + const collateralAmount = await web3.utils.toWei("0.5"); + const debtAmount = await web3.utils.toWei("0.001"); await fundWallet({ ethAmount: 0, token1Amount: collateralAmount }); await testOpenLoan({ collateral: token1, collateralAmount, debt: ETH_TOKEN, debtAmount, relayed: true, @@ -320,8 +319,8 @@ contract("Loan Module", (accounts) => { }); it("should get the info of a loan", async () => { - const collateralAmount = parseEther("0.1"); - const debtAmount = parseEther("0.01"); + const collateralAmount = await web3.utils.toWei("0.1"); + const debtAmount = await web3.utils.toWei("0.01"); await fundWallet({ ethAmount: collateralAmount, token1Amount: 0 }); await testOpenLoan({ collateral: ETH_TOKEN, collateralAmount, debt: token1, debtAmount, relayed: false, @@ -329,7 +328,7 @@ contract("Loan Module", (accounts) => { let loan = await loanManager.getLoan(wallet.address, ZERO_BYTES32); assert.isTrue(loan._status === 1 && loan._ethValue.gt(0), "should have obtained the liquidity info of the loan"); - await oracle.setUnderlyingPrice(cToken1.address, WAD.mul(10)); + await oracle.setUnderlyingPrice(cToken1.address, WAD.times(10)); loan = await loanManager.getLoan(wallet.address, ZERO_BYTES32); assert.isTrue(loan._status === 2 && loan._ethValue.gt(0), "should have obtained the shortfall info of the loan"); @@ -346,250 +345,250 @@ contract("Loan Module", (accounts) => { // Successes it("should add ETH collateral to a loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.2"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.2"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.1"), debt: token1, debtAmount: parseEther("0.05"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.1"), debt: token1, debtAmount: web3.utils.toWei("0.05"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: ETH_TOKEN, amount: parseEther("0.1"), add: true, relayed: false, + loanId, collateral: ETH_TOKEN, amount: web3.utils.toWei("0.1"), add: true, relayed: false, }); }); it("should add ETH collateral to a loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.2"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.2"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.1"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.1"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: ETH_TOKEN, amount: parseEther("0.1"), add: true, relayed: true, + loanId, collateral: ETH_TOKEN, amount: web3.utils.toWei("0.1"), add: true, relayed: true, }); }); it("should remove ETH collateral from a loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.2"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.2", "ether"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.2"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.2", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: ETH_TOKEN, amount: parseEther("0.001"), add: false, relayed: false, + loanId, collateral: ETH_TOKEN, amount: web3.utils.toWei("0.001"), add: false, relayed: false, }); }); it("should remove ETH collateral from a loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.2"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.2"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.1"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.1"), debt: token1, debtAmount: web3.utils.toWei("0.01"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: ETH_TOKEN, amount: parseEther("0.001"), add: false, relayed: true, + loanId, collateral: ETH_TOKEN, amount: web3.utils.toWei("0.001"), add: false, relayed: true, }); }); it("should add token collateral to a loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.6") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.6") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: token1, amount: parseEther("0.1"), add: true, relayed: false, + loanId, collateral: token1, amount: web3.utils.toWei("0.1"), add: true, relayed: false, }); }); it("should add token collateral to a loan (relayed tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.6") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.6") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: token1, amount: parseEther("0.1"), add: true, relayed: true, + loanId, collateral: token1, amount: web3.utils.toWei("0.1"), add: true, relayed: true, }); }); it("should remove token collateral from a loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: token1, amount: parseEther("0.1"), add: false, relayed: false, + loanId, collateral: token1, amount: web3.utils.toWei("0.1"), add: false, relayed: false, }); }); it("should remove token collateral from a loan (relayed tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.5", "ether") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testChangeCollateral({ - loanId, collateral: token1, amount: parseEther("0.1"), add: false, relayed: true, + loanId, collateral: token1, amount: web3.utils.toWei("0.1", "ether"), add: false, relayed: true, }); }); // Reverts it("should fail to borrow an unknown token", async () => { - const params = [wallet.address, ZERO_BYTES32, ethers.constants.AddressZero, parseEther("1")]; + const params = [wallet.address, ZERO_BYTES32, ethers.constants.AddressZero, web3.utils.toWei("1", "ether")]; await utils.assertRevert(loanManager.addDebt(...params, { from: owner }), "CM: No market for target token"); }); it("should fail to borrow 0 token", async () => { - const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, parseEther("0")]; + const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, 0]; await utils.assertRevert(loanManager.addDebt(...params, { from: owner }), "CM: amount cannot be 0"); }); it("should fail to borrow token with no collateral", async () => { - const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, parseEther("1")]; + const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, web3.utils.toWei("1", "ether")]; await utils.assertRevert(loanManager.addDebt(...params, { from: owner }), "CM: borrow failed"); }); it("should fail to repay an unknown token", async () => { - const params = [wallet.address, ZERO_BYTES32, ethers.constants.AddressZero, parseEther("1")]; + const params = [wallet.address, ZERO_BYTES32, ethers.constants.AddressZero, web3.utils.toWei("1", "ether")]; await utils.assertRevert(loanManager.removeDebt(...params, { from: owner }), "CM: No market for target token"); }); it("should fail to repay 0 token", async () => { - const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, parseEther("0")]; + const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, 0]; await utils.assertRevert(loanManager.removeDebt(...params, { from: owner }), "CM: amount cannot be 0"); }); it("should fail to repay too much debt token", async () => { - const collateralAmount = parseEther("1"); - const debtAmount = parseEther("0.001"); + const collateralAmount = await web3.utils.toWei("1", "ether"); + const debtAmount = await web3.utils.toWei("0.001", "ether"); await fundWallet({ ethAmount: collateralAmount, token1Amount: 0 }); const loanId = await testOpenLoan({ collateral: ETH_TOKEN, collateralAmount, debt: token1, debtAmount, relayed: false, }); - const removeDebtParams = [wallet.address, loanId, token1.address, parseEther("0.002")]; + const removeDebtParams = [wallet.address, loanId, token1.address, web3.utils.toWei("0.002", "ether")]; await utils.assertRevert(loanManager.removeDebt(...removeDebtParams, { from: owner }), "CM: repayBorrow failed"); }); it("should fail to remove an unknown collateral token", async () => { - const params = [wallet.address, ZERO_BYTES32, ethers.constants.AddressZero, parseEther("1")]; + const params = [wallet.address, ZERO_BYTES32, ethers.constants.AddressZero, web3.utils.toWei("1", "ether")]; await utils.assertRevert(loanManager.removeCollateral(...params, { from: owner }), "CM: No market for target token"); }); it("should fail to remove 0 collateral token", async () => { - const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, parseEther("0")]; + const params = [wallet.address, ZERO_BYTES32, ETH_TOKEN, web3.utils.toWei("0", "ether")]; await utils.assertRevert(loanManager.removeCollateral(...params, { from: owner }), "CM: amount cannot be 0"); }); it("should fail to remove too much collateral token", async () => { - const collateralAmount = parseEther("1"); - const debtAmount = parseEther("0.001"); + const collateralAmount = await web3.utils.toWei("1", "ether"); + const debtAmount = await web3.utils.toWei("0.001", "ether"); await fundWallet({ ethAmount: collateralAmount, token1Amount: 0 }); const loanId = await testOpenLoan({ collateral: ETH_TOKEN, collateralAmount, debt: token1, debtAmount, relayed: false, }); - const removeDebtParams = [wallet.address, loanId, token1.address, parseEther("0.002")]; + const removeDebtParams = [wallet.address, loanId, token1.address, web3.utils.toWei("0.002", "ether")]; await utils.assertRevert(loanManager.removeCollateral(...removeDebtParams, { from: owner }), "CM: redeemUnderlying failed"); }); }); describe("Increase/Decrease Debt", () => { it("should increase ETH debt to a token1/ETH loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.5", "ether") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: ETH_TOKEN, amount: parseEther("0.001"), add: true, relayed: false, + loanId, debtToken: ETH_TOKEN, amount: web3.utils.toWei("0.001", "ether"), add: true, relayed: false, }); }); it("should increase ETH debt to a token1/ETH loan (relayed tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.5", "ether") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: ETH_TOKEN, amount: parseEther("0.001"), add: true, relayed: true, + loanId, debtToken: ETH_TOKEN, amount: web3.utils.toWei("0.001", "ether"), add: true, relayed: true, }); }); it("should increase token1 debt to a ETH/token1 loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5", "ether"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token1, amount: parseEther("0.01"), add: true, relayed: false, + loanId, debtToken: token1, amount: web3.utils.toWei("0.01", "ether"), add: true, relayed: false, }); }); it("should increase token1 debt to a ETH/token1 loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5", "ether"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token1, amount: parseEther("0.01"), add: true, relayed: true, + loanId, debtToken: token1, amount: web3.utils.toWei("0.01", "ether"), add: true, relayed: true, }); }); it("should increase token2 debt to a ETH/token1 loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5", "ether"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token2, amount: parseEther("0.01"), add: true, relayed: false, + loanId, debtToken: token2, amount: web3.utils.toWei("0.01", "ether"), add: true, relayed: false, }); }); it("should increase token2 debt to a ETH/token1 loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5", "ether"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token2, amount: parseEther("0.01"), add: true, relayed: true, + loanId, debtToken: token2, amount: web3.utils.toWei("0.01", "ether"), add: true, relayed: true, }); }); it("should repay ETH debt to a token1/ETH loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.5", "ether") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: ETH_TOKEN, amount: parseEther("0.0005"), add: false, relayed: false, + loanId, debtToken: ETH_TOKEN, amount: web3.utils.toWei("0.0005", "ether"), add: false, relayed: false, }); }); it("should repay ETH debt to a token1/ETH loan (relay tx)", async () => { - await fundWallet({ ethAmount: 0, token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: 0, token1Amount: web3.utils.toWei("0.5", "ether") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: ETH_TOKEN, amount: parseEther("0.0005"), add: false, relayed: true, + loanId, debtToken: ETH_TOKEN, amount: web3.utils.toWei("0.0005"), add: false, relayed: true, }); }); it("should repay token1 debt to a ETH/token1 loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token1, amount: parseEther("0.005"), add: false, relayed: false, + loanId, debtToken: token1, amount: web3.utils.toWei("0.005", "ether"), add: false, relayed: false, }); }); it("should repay token1 debt to a ETH/token1 loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: 0 }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5", "ether"), token1Amount: 0 }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token1, amount: parseEther("0.005"), add: false, relayed: true, + loanId, debtToken: token1, amount: web3.utils.toWei("0.005", "ether"), add: false, relayed: true, }); }); it("should repay the full token1 debt to a ETH/token1 loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: parseEther("0.01") }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5", "ether"), token1Amount: web3.utils.toWei("0.01", "ether") }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.5"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.5", "ether"), debt: token1, debtAmount: web3.utils.toWei("0.01", "ether"), relayed: false, }); await testChangeDebt({ loanId, debtToken: token1, amount: ethers.constants.MaxUint256, add: false, relayed: false, @@ -616,67 +615,67 @@ contract("Loan Module", (accounts) => { } it("should close an ETH/token1 loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5"), token1Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.1"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.1"), debt: token1, debtAmount: web3.utils.toWei("0.01"), relayed: false, }); await testCloseLoan({ loanId, relayed: false }); }); it("should close an ETH/token1 loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5"), token1Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.1"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.1"), debt: token1, debtAmount: web3.utils.toWei("0.01"), relayed: false, }); await testCloseLoan({ loanId, relayed: true }); }); it("should close an token1/ETH loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.1"), token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("0.1"), token1Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testCloseLoan({ loanId, relayed: false }); }); it("should close an token1/ETH loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("0.1"), token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("0.1"), token1Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.5"), debt: ETH_TOKEN, debtAmount: parseEther("0.001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.5"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.001"), relayed: false, }); await testCloseLoan({ loanId, relayed: true }); }); it("should close a loan collateralized with ETH when there is a pre-existing loan collateralized with token1", async () => { - await fundWallet({ ethAmount: parseEther("0.5"), token1Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("0.5"), token1Amount: web3.utils.toWei("0.5") }); await testOpenLoan({ - collateral: token1, collateralAmount: parseEther("0.4"), debt: ETH_TOKEN, debtAmount: parseEther("0.0000001"), relayed: false, + collateral: token1, collateralAmount: web3.utils.toWei("0.4"), debt: ETH_TOKEN, debtAmount: web3.utils.toWei("0.0000001"), relayed: false, }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.4"), debt: token1, debtAmount: parseEther("0.0000001"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.4"), debt: token1, debtAmount: web3.utils.toWei("0.0000001"), relayed: false, }); // should not exit any market await testCloseLoan({ loanId, relayed: false, debtMarkets: 0 }); }); it("should close an ETH/token1+token2 loan (blockchain tx)", async () => { - await fundWallet({ ethAmount: parseEther("1"), token1Amount: parseEther("0.5"), token2Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("1"), token1Amount: web3.utils.toWei("0.5"), token2Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.2"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.2"), debt: token1, debtAmount: web3.utils.toWei("0.01"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token2, amount: parseEther("0.001"), add: true, relayed: false, + loanId, debtToken: token2, amount: web3.utils.toWei("0.001"), add: true, relayed: false, }); await testCloseLoan({ loanId, relayed: false, debtMarkets: 2 }); }); it("should close an ETH/token1+token2 loan (relayed tx)", async () => { - await fundWallet({ ethAmount: parseEther("1"), token1Amount: parseEther("0.5"), token2Amount: parseEther("0.5") }); + await fundWallet({ ethAmount: web3.utils.toWei("1"), token1Amount: web3.utils.toWei("0.5"), token2Amount: web3.utils.toWei("0.5") }); const loanId = await testOpenLoan({ - collateral: ETH_TOKEN, collateralAmount: parseEther("0.2"), debt: token1, debtAmount: parseEther("0.01"), relayed: false, + collateral: ETH_TOKEN, collateralAmount: web3.utils.toWei("0.2"), debt: token1, debtAmount: web3.utils.toWei("0.01"), relayed: false, }); await testChangeDebt({ - loanId, debtToken: token2, amount: parseEther("0.001"), add: true, relayed: false, + loanId, debtToken: token2, amount: web3.utils.toWei("0.001"), add: true, relayed: false, }); await testCloseLoan({ loanId, relayed: true, debtMarkets: 2 }); }); diff --git a/test/makerV2Manager_invest.js b/test/makerV2Manager_invest.js index 802ba6e47..d7833220a 100644 --- a/test/makerV2Manager_invest.js +++ b/test/makerV2Manager_invest.js @@ -87,8 +87,8 @@ contract("MakerV2Invest", (accounts) => { await wallet.init(owner, [versionManager.address]); await versionManager.upgradeWallet(wallet.address, await versionManager.lastVersion(), { from: owner }); - await sai["mint(address,uint256)"](wallet.address, DAI_SENT.mul(20)); - await dai["mint(address,uint256)"](wallet.address, DAI_SENT.mul(20)); + await sai["mint(address,uint256)"](wallet.address, DAI_SENT.times(20)); + await dai["mint(address,uint256)"](wallet.address, DAI_SENT.times(20)); }); async function exchangeWithPot({ toPot, relayed, all = false }) { diff --git a/test/makerV2Manager_loan.js b/test/makerV2Manager_loan.js index ca9ca0a75..f6863140b 100644 --- a/test/makerV2Manager_loan.js +++ b/test/makerV2Manager_loan.js @@ -146,7 +146,7 @@ contract("MakerV2Loan", (accounts) => { const { ilk } = await makerRegistry.collaterals(tokenAddress_); const { spot, dust } = await vat.ilks(ilk); const daiAmount = dust.div(RAY); - const collateralAmount = dust.div(spot).mul(2); + const collateralAmount = dust.div(spot).times(2); return { daiAmount, collateralAmount }; } @@ -262,7 +262,7 @@ contract("MakerV2Loan", (accounts) => { ? await getBalance(walletAddress) : await collateral.balanceOf(walletAddress); - const expectedCollateralChange = collateralAmount.mul(add ? -1 : 1).toString(); + const expectedCollateralChange = collateralAmount.times(add ? -1 : 1).toString(); assert.equal( afterCollateral.sub(beforeCollateral).toString(), expectedCollateralChange, @@ -461,7 +461,7 @@ contract("MakerV2Loan", (accounts) => { const { collateralAmount, daiAmount } = await getTestAmounts(ETH_TOKEN); const loanId = await testOpenLoan({ collateralAmount, daiAmount, relayed }); // give some ETH to the wallet to be used for repayment - await owner.send({ to: walletAddress, value: collateralAmount.mul(2) }); + await owner.send({ to: walletAddress, value: collateralAmount.times(2) }); await increaseTime(3); // wait 3 seconds const beforeDAI = await dai.balanceOf(wallet.address); const method = "closeLoan"; @@ -563,7 +563,7 @@ contract("MakerV2Loan", (accounts) => { const tx = await makerV2[method](...params, { gasLimit: 1000000, from: owner }); txReceipt = tx.receipt; } - assert.isTrue(await hasEvent(txReceipt, makerV2, "LoanAcquired"), "should have generated LoanAcquired event"); + hasEvent(txReceipt, "LoanAcquired"); // The loanId held by the MakerV2Manager will be different from the transferred vault id, in case the latter was merged into an existing vault const featureLoanId = await makerV2.loanIds(walletAddress, ilk); diff --git a/test/multisig.js b/test/multisig.js index c682f723b..1fbc51d7f 100644 --- a/test/multisig.js +++ b/test/multisig.js @@ -89,7 +89,7 @@ contract("MultiSigWallet", (accounts) => { async function getMultiSigParams(functioName, params) { const nonce = await multisig.nonce(); - const data = multisig.contract.methods[functioName]([...params]).encodeABI; + const data = multisig.contract.methods[functioName]([...params]).encodeABI(); const signedData = MultisigExecutor.signHash(multisig.address, multisig.address, 0, data, nonce.toNumber()); const signatures = await getSignatures(signedData, [owner1, owner2]); return { data, signatures }; diff --git a/test/transferManager.js b/test/transferManager.js index b9d4b6f25..b6bb12ad4 100644 --- a/test/transferManager.js +++ b/test/transferManager.js @@ -288,7 +288,7 @@ contract("TransferManager", (accounts) => { await previousTransferManager.addModule(existingWallet.address, versionManager.address, { from: owner }); const tx = await versionManager.upgradeWallet(existingWallet.address, await versionManager.lastVersion(), { from: owner }); const txReceipt = tx.receipt; - assert.isTrue(hasEvent(txReceipt, transferManager, "DailyLimitMigrated")); + utils.hasEvent(txReceipt, "DailyLimitMigrated"); // check result limit = await transferManager.getCurrentLimit(existingWallet.address); assert.equal(limit.toNumber(), 4000000, "limit should have been migrated"); @@ -336,7 +336,7 @@ contract("TransferManager", (accounts) => { it("should be able to disable the limit", async () => { const tx = await transferManager.disableLimit(wallet.address, { from: owner }); const txReceipt = tx.receipt; - assert.isTrue(hasEvent(txReceipt, transferManager, "DailyLimitDisabled")); + utils.hasEvent(txReceipt, "DailyLimitDisabled"); let limitDisabled = await transferManager.isLimitDisabled(wallet.address); assert.isFalse(limitDisabled); await increaseTime(SECURITY_PERIOD + 1); diff --git a/utils/defi-deployer.js b/utils/defi-deployer.js index f6164dfdd..c9ffaac53 100644 --- a/utils/defi-deployer.js +++ b/utils/defi-deployer.js @@ -46,7 +46,7 @@ module.exports = { await uniswapFactory.createExchange(token.address, { from: infrastructure }); const uniswapExchangeAddress = await uniswapFactory.getExchange(token.address); const tokenExchange = await UniswapExchange.at(uniswapExchangeAddress); - const tokenLiquidity = ethLiquidity.mul(WAD).div(ethPerToken[i]); + const tokenLiquidity = ethLiquidity.times(WAD).div(ethPerToken[i]); await token["mint(address,uint256)"](infrastructure, tokenLiquidity); await token.approve(tokenExchange.address, tokenLiquidity, { from: infrastructure }); const { timestamp } = await web3.eth.getBlock("latest"); @@ -147,7 +147,7 @@ module.exports = { // Allow daiJoin to mint DAI await dai.rely(daiJoin.address); // Give daiJoin some internal DAI in the vat - await vat.suck(daiJoin.address, daiJoin.address, RAD.mul(1000000)); + await vat.suck(daiJoin.address, daiJoin.address, RAD.times(1000000)); // Deploy and setup SCD to MCD Migration const migration = await ScdMcdMigration.new( diff --git a/utils/relay-manager.js b/utils/relay-manager.js index c51a0d113..87cfe4b01 100644 --- a/utils/relay-manager.js +++ b/utils/relay-manager.js @@ -59,6 +59,7 @@ class RelayManager { _refundAddress, { gasLimit: _gasLimitRelay, gasPrice: _gasPrice, from: relayerAccount }, ); + return tx.receipt; } } diff --git a/utils/utilities.js b/utils/utilities.js index 1ff532cbb..668d23e0f 100644 --- a/utils/utilities.js +++ b/utils/utilities.js @@ -101,7 +101,7 @@ module.exports = { }, async hasEvent(txReceipt, eventName) { - const event = txReceipt.logs.find((e) => e.event === eventName); + const event = txReceipt.logs.filter((e) => e.event === eventName); return expect(event, "Event does not exist in recept").to.exist; },