diff --git a/buidler.config.ts b/buidler.config.ts index 54fff118..e4afcf09 100644 --- a/buidler.config.ts +++ b/buidler.config.ts @@ -10,13 +10,14 @@ usePlugin("buidler-typechain"); usePlugin("solidity-coverage"); usePlugin("@nomiclabs/buidler-waffle"); usePlugin("@nomiclabs/buidler-etherscan"); +usePlugin("@nomiclabs/buidler-ganache"); ["misc", "deployments", "migrations"].forEach((folder) => { const tasksPath = path.join(__dirname, "tasks", folder); fs.readdirSync(tasksPath).forEach((task) => require(`${tasksPath}/${task}`)); }); -const DEFAULT_BLOCK_GAS_LIMIT = 9500000; +const DEFAULT_BLOCK_GAS_LIMIT = 10000000; const DEFAULT_GAS_PRICE = 10; const HARDFORK = "istanbul"; const INFURA_KEY = ""; @@ -84,6 +85,10 @@ const config: BuidlerConfig = { }) ), }, + ganache: { + blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT, + url: "http://localhost:8545", + }, }, }; diff --git a/docker-compose.yml b/docker-compose.yml index d165c010..41a521e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,4 +7,15 @@ services: working_dir: /src command: npm run run-env volumes: - - ./:/src \ No newline at end of file + - ./:/src + + ganache: + image: trufflesuite/ganache-cli:next + ports: + - "8545:8545" + command: [ + "ganache-cli", + "--gasLimit", "10000000", + "--mnemonic", "frame post antenna before valid claw crunch clap travel buyer inch act", + "--hardfork", "istanbul" + ] \ No newline at end of file diff --git a/helpers/contracts-helpers.ts b/helpers/contracts-helpers.ts index ab24b717..487f5c6e 100644 --- a/helpers/contracts-helpers.ts +++ b/helpers/contracts-helpers.ts @@ -155,9 +155,7 @@ export const deployLendingPoolCore = async () => { linkedBytecode ); - const lendingPoolCore = await LendingPoolCoreFactory.deploy({ - gasLimit: 9500000, - }); + const lendingPoolCore = await LendingPoolCoreFactory.deploy(); return (await lendingPoolCore.deployed()) as LendingPoolCore; }; diff --git a/package-lock.json b/package-lock.json index 2238f6ea..750ea6a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -198,6 +198,18 @@ "request-promise": "^4.2.4" } }, + "@nomiclabs/buidler-ganache": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-ganache/-/buidler-ganache-1.3.3.tgz", + "integrity": "sha512-5dReZ3qqkA8Y46qeuw4gM3hzyzTB8DPvc5xTz7TKSkCHE5iwe4mMBLjyJ0ZwVaxmQvr4zxkNC9LsQ8JVC/j6IA==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "ganache-core": "^2.7.0", + "ts-essentials": "^2.0.7", + "ts-interface-checker": "^0.1.9" + } + }, "@nomiclabs/buidler-waffle": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-waffle/-/buidler-waffle-1.3.4.tgz", @@ -22832,6 +22844,12 @@ } } }, + "ts-interface-checker": { + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.11.tgz", + "integrity": "sha512-Jx6cFBiuCQrRl3CgoIOamIE/toZ8jQJbIlsLGpkBiUpCEUyFcyZ2pvjP8kSXIcz8V5v/murgm/5EfIQapUmh6A==", + "dev": true + }, "ts-node": { "version": "8.10.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.2.tgz", diff --git a/package.json b/package.json index 90223aee..79b90786 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@nomiclabs/buidler": "1.3.5", "@nomiclabs/buidler-ethers": "1.3.3", "@nomiclabs/buidler-etherscan": "1.3.3", + "@nomiclabs/buidler-ganache": "^1.3.3", "@nomiclabs/buidler-waffle": "1.3.4", "@openzeppelin/contracts": "3.0.1", "@typechain/ethers-v4": "1.0.0", diff --git a/test-wallets.js b/test-wallets.js index b054b743..38b0e1c5 100644 --- a/test-wallets.js +++ b/test-wallets.js @@ -5,17 +5,32 @@ module.exports = { { secretKey: "0xc5e8f61d1ab959b397eecc0a37a6517b8e67a0e7cf1f4bce5591f3ed80199122", - balance: toWad(1_000_000), + balance: toWad("1000000"), }, { secretKey: "0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb", - balance: toWad(1_000_000), + balance: toWad("1000000"), }, { secretKey: "0x23c601ae397441f3ef6f1075dcb0031ff17fb079837beadaf3c84d96c6f3e569", - balance: toWad(1_000_000), + balance: toWad("1000000"), + }, + { + secretKey: + "0xee9d129c1997549ee09c0757af5939b2483d80ad649a0eda68e8b0357ad11131", + balance: toWad("1000000"), + }, + { + secretKey: + "0x87630b2d1de0fbd5044eb6891b3d9d98c34c8d310c852f98550ba774480e47cc", + balance: toWad("1000000"), + }, + { + secretKey: + "0x275cc4a2bfd4f612625204a20a2280ab53a6da2d14860c47a9f5affe58ad86d4", + balance: toWad("1000000"), }, ], }; diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index 1968c180..e85a03e7 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -30,10 +30,11 @@ import { getLendingPool, insertContractAddressInDb, deployAaveProtocolTestHelpers, + getEthersSigners, } from "../helpers/contracts-helpers"; import {LendingPoolAddressesProvider} from "../types/LendingPoolAddressesProvider"; import {evmSnapshot} from "../helpers/misc-utils"; -import {Wallet, ContractTransaction, ethers} from "ethers"; +import {Wallet, ContractTransaction, ethers, Signer} from "ethers"; import { TokenContractId, eContractid, @@ -65,7 +66,7 @@ import {LendingRateOracle} from "../types/LendingRateOracle"; import {LendingPoolCore} from "../types/LendingPoolCore"; import {LendingPoolConfigurator} from "../types/LendingPoolConfigurator"; -const deployAllMockTokens = async (deployer: Wallet) => { +const deployAllMockTokens = async (deployer: Signer) => { const tokens: {[symbol: string]: MockContract | MintableErc20} = {}; for (const tokenSymbol of Object.keys(TokenContractId)) { @@ -347,9 +348,9 @@ const enableReservesAsCollateral = async ( const waitForTx = async (tx: ContractTransaction) => await tx.wait(); -const buildTestEnv = async (deployer: Wallet, secondaryWallet: Wallet) => { +const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { console.time("setup"); - const lendingPoolManager = deployer.address; + const lendingPoolManager = await deployer.getAddress(); const mockTokens = await deployAllMockTokens(deployer); @@ -579,7 +580,7 @@ const buildTestEnv = async (deployer: Wallet, secondaryWallet: Wallet) => { ); const {receivers, percentages} = getFeeDistributionParamsCommon( - deployer.address + lendingPoolManager ); await deployMockOneSplit(tokensAddressesWithoutUsd.LEND); @@ -599,7 +600,7 @@ const buildTestEnv = async (deployer: Wallet, secondaryWallet: Wallet) => { await waitForTx( await tokenDistributorProxy.initialize( tokenDistributorImpl.address, - secondaryWallet.address, + await secondaryWallet.getAddress(), implementationParams ) ); @@ -627,8 +628,7 @@ const buildTestEnv = async (deployer: Wallet, secondaryWallet: Wallet) => { before(async () => { await rawBRE.run("set-bre"); - const deployer = new ethers.Wallet(accounts[0].secretKey); - const secondaryWallet = new ethers.Wallet(accounts[1].secretKey); + const [deployer, secondaryWallet] = await getEthersSigners(); await buildTestEnv(deployer, secondaryWallet); console.log("\n***************"); console.log("Setup and snapshot finished"); diff --git a/test/atoken-transfer.spec.ts b/test/atoken-transfer.spec.ts index 70897bd8..a1c34cc8 100644 --- a/test/atoken-transfer.spec.ts +++ b/test/atoken-transfer.spec.ts @@ -1,8 +1,9 @@ -import {MockProvider} from "ethereum-waffle"; -import {evmRevert, BRE} from "../helpers/misc-utils"; +import {evmRevert} from "../helpers/misc-utils"; import { TEST_SNAPSHOT_ID, APPROVAL_AMOUNT_LENDING_POOL_CORE, + MOCK_ETH_ADDRESS, + oneEther, } from "../helpers/constants"; import {AToken} from "../types/AToken"; import {MintableErc20} from "../types/MintableErc20"; @@ -18,20 +19,16 @@ import { getLendingPool, } from "../helpers/contracts-helpers"; import {expect} from "chai"; -import {ethers, Wallet, Signer} from "ethers"; -// @ts-ignore -import {accounts} from "../test-wallets.js"; +import {Signer} from "ethers"; +import {BigNumber as EthersBigNumber} from "ethers/utils"; describe("AToken: Transfer", () => { - let wallets: Signer[]; let deployer: Signer; let users: Signer[]; let _aDai: AToken; let _dai: MintableErc20; let _lendingPool: LendingPool; let _lendingPoolCore: LendingPoolCore; - const NOT_LENDING_POOL_MSG = - "The caller of this function must be a lending pool"; before(async () => { await evmRevert(TEST_SNAPSHOT_ID); @@ -70,13 +67,11 @@ describe("AToken: Transfer", () => { .connect(users[0]) .mint(await convertToCurrencyDecimals(_dai.address, "1000")); - console.log(_lendingPoolCore.address); - - console.time("approve"); + console.time("approve()"); await _dai .connect(users[0]) .approve(_lendingPoolCore.address, APPROVAL_AMOUNT_LENDING_POOL_CORE); - console.timeEnd("approve"); + console.timeEnd("approve()"); //user 1 deposits 1000 DAI const amountDAItoDeposit = await convertToCurrencyDecimals( @@ -84,11 +79,11 @@ describe("AToken: Transfer", () => { "1000" ); - console.time("getaddress"); + console.time("deposit()"); await _lendingPool .connect(users[0]) .deposit(_dai.address, amountDAItoDeposit, "0"); - console.timeEnd("getaddress"); + console.timeEnd("deposit()"); await _aDai .connect(users[0]) @@ -107,51 +102,89 @@ describe("AToken: Transfer", () => { ); }); - // it('User 1 redirects interest to user 2, transfers 500 DAI back to user 0', async () => { + it("User 1 redirects interest to user 2, transfers 500 DAI back to user 0", async () => { + console.time("redirectInterest"); + await _aDai + .connect(users[1]) + .redirectInterestStream(await users[2].getAddress()); + console.timeEnd("redirectInterest"); - // await _aDai.redirectInterestStream(await users[2].getAddress()); + const aDAIRedirected = await convertToCurrencyDecimals( + _dai.address, + "1000" + ); - // const aDAIRedirected = await convertToCurrencyDecimals(_DAI.address, '1000'); + const aDAItoTransfer = await convertToCurrencyDecimals(_dai.address, "500"); - // const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500'); + const user2RedirectedBalanceBefore = await _aDai.getRedirectedBalance( + await users[2].getAddress() + ); + expect(user2RedirectedBalanceBefore.toString()).to.be.equal( + aDAIRedirected, + "Invalid redirected balance for user 2 before transfer" + ); - // const user2RedirectedBalanceBefore = await _aDAI.getRedirectedBalance(users[2]) - // expect(user2RedirectedBalanceBefore.toString()).to.be.equal(aDAIRedirected, "Invalid redirected balance for user 2 before transfer") + await _aDai + .connect(users[1]) + .transfer(await users[0].getAddress(), aDAItoTransfer); - // await _aDAI.transfer(users[0], aDAItoTransfer, {from: users[1]}) + const user2RedirectedBalanceAfter = await _aDai.getRedirectedBalance( + await users[2].getAddress() + ); + const user1RedirectionAddress = await _aDai.getInterestRedirectionAddress( + await users[1].getAddress() + ); - // const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2]) - // const user1RedirectionAddress = await _aDAI.getInterestRedirectionAddress(users[1]) + expect(user2RedirectedBalanceAfter.toString()).to.be.equal( + aDAItoTransfer, + "Invalid redirected balance for user 2 after transfer" + ); + expect(user1RedirectionAddress.toString()).to.be.equal( + await users[2].getAddress(), + "Invalid redirection address for user 1" + ); + }); - // expect(user2RedirectedBalanceAfter.toString()).to.be.equal(aDAItoTransfer, "Invalid redirected balance for user 2 after transfer") - // expect(user1RedirectionAddress.toString()).to.be.equal(users[2], "Invalid redirection address for user 1") + it("User 0 transfers back to user 1", async () => { + const aDAItoTransfer = await convertToCurrencyDecimals(_dai.address, "500"); - // }); + await _aDai + .connect(users[0]) + .transfer(await users[1].getAddress(), aDAItoTransfer); - // it('User 0 transfers back to user 1', async () => { + const user2RedirectedBalanceAfter = await _aDai.getRedirectedBalance( + await users[2].getAddress() + ); - // const aDAItoTransfer = await convertToCurrencyDecimals(_DAI.address, '500'); + const user1BalanceAfter = await _aDai.balanceOf( + await users[1].getAddress() + ); - // await _aDAI.transfer(users[1], aDAItoTransfer, {from: users[0]}) + expect(user2RedirectedBalanceAfter.toString()).to.be.equal( + user1BalanceAfter.toString(), + "Invalid redirected balance for user 2 after transfer" + ); + }); - // const user2RedirectedBalanceAfter = await _aDAI.getRedirectedBalance(users[2]) - - // const user1BalanceAfter = await _aDAI.balanceOf(users[1]) - - // expect(user2RedirectedBalanceAfter.toString()).to.be.equal(user1BalanceAfter.toString(), "Invalid redirected balance for user 2 after transfer") - - // }); - - // it('User 0 deposits 1 ETH and user tries to borrow, but the aTokens received as a transfer are not available as collateral (revert expected)', async () => { - - // await _lendingPoolInstance.deposit(ETHEREUM_ADDRESS, oneEther, '0', { - // from: users[0], - // value: oneEther.toFixed(0) - // }); - - // await expectRevert(_lendingPoolInstance.borrow(ETHEREUM_ADDRESS, await convertToCurrencyDecimals(ETHEREUM_ADDRESS,"0.1"), RateMode.Stable, "0", {from: users[1]}), "The collateral balance is 0") - - // }); + it("User 0 deposits 1 ETH and user tries to borrow, but the aTokens received as a transfer are not available as collateral (revert expected)", async () => { + // console.time("deposit()"); + // await _lendingPool + // .connect(users[0]) + // .deposit(MOCK_ETH_ADDRESS, oneEther.toFixed(), "0", { + // value: new EthersBigNumber(oneEther.toFixed()), + // }); + // console.timeEnd("deposit()"); + // await expectRevert( + // _lendingPoolInstance.borrow( + // ETHEREUM_ADDRESS, + // await convertToCurrencyDecimals(ETHEREUM_ADDRESS, "0.1"), + // RateMode.Stable, + // "0", + // {from: users[1]} + // ), + // "The collateral balance is 0" + // ); + }); // it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => { diff --git a/tsconfig.json b/tsconfig.json index 2aec18a6..497e8a12 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,8 @@ "node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts", "node_modules/buidler-typechain/src/type-extensions.d.ts", "node_modules/@nomiclabs/buidler-waffle/src/type-extensions.d.ts", - "node_modules/@nomiclabs/buidler-etherscan/src/type-extensions.d.ts" + "node_modules/@nomiclabs/buidler-etherscan/src/type-extensions.d.ts", + "node_modules/@nomiclabs/buidler-ganache/src/type-extensions.d.ts" ] } \ No newline at end of file