From 00deafe6a1f217d58dbb241c5da5694178dc5f31 Mon Sep 17 00:00:00 2001 From: Evert Kors Date: Tue, 22 Dec 2020 21:13:12 +0100 Subject: [PATCH] Fix compound lending logic tests --- test/LendingManager.ts | 70 ++++++++++++++++++------------------ test/lendingLogicCompound.ts | 16 +++++---- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/test/LendingManager.ts b/test/LendingManager.ts index 68e529e..3ec07fd 100644 --- a/test/LendingManager.ts +++ b/test/LendingManager.ts @@ -15,7 +15,7 @@ import DiamondArtifact from "../artifacts/Diamond.json"; import TimeTraveler from "../utils/TimeTraveler"; import { parseEther, formatBytes32String } from "ethers/lib/utils"; -import { +import { MockAToken, MockCToken, MockToken, @@ -141,7 +141,7 @@ describe("LendingManager", function() { } await pieFactory.setDefaultController(account); - + const diamondImplementation = await(deployContract(signers[0], DiamondArtifact)) as Diamond; diamondImplementation.initialize([], constants.AddressZero); pieFactory.setDiamondImplementation(diamondImplementation.address); @@ -197,46 +197,46 @@ describe("LendingManager", function() { describe("Aave", async() => { it("Lending less than max should work", async() => { const lendAmount = mintAmount.div(2); - + await lendingManager.lend(token.address, lendAmount, AAVE); - + const tokens = await pie.getTokens(); - + expect(tokens.length).to.eq(2); expect(tokens[0]).to.eq(token.address); expect(tokens[1]).to.eq(aToken.address); - + const tokenBalance = await token.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(tokenBalance).to.eq(lendAmount); expect(aTokenBalance).to.eq(lendAmount); }); it("Lending the max should work", async() => { await lendingManager.lend(token.address, mintAmount, AAVE); - + const tokens = await pie.getTokens(); - + expect(tokens.length).to.eq(1); expect(tokens[0]).to.eq(aToken.address); - + const tokenBalance = await token.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(tokenBalance).to.eq(0); expect(aTokenBalance).to.eq(mintAmount); }); it("Lending more than the max should lend the max", async() => { await lendingManager.lend(token.address, mintAmount.add(parseEther("2")), AAVE); - + const tokens = await pie.getTokens(); - + expect(tokens.length).to.eq(1); expect(tokens[0]).to.eq(aToken.address); - + const tokenBalance = await token.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(tokenBalance).to.eq(0); expect(aTokenBalance).to.eq(mintAmount); }); @@ -245,44 +245,44 @@ describe("LendingManager", function() { it("Lending less than the max should work", async() => { const lendAmount = mintAmount.div(2); await lendingManager.lend(token.address, lendAmount, COMPOUND); - + const tokens = await pie.getTokens(); - + expect(tokens.length).to.eq(2); expect(tokens[0]).to.eq(token.address); expect(tokens[1]).to.eq(cToken.address); - + const tokenBalance = await token.balanceOf(pie.address); const cTokenBalance = await cToken.balanceOf(pie.address); - + expect(tokenBalance).to.eq(lendAmount); expect(cTokenBalance).to.eq(lendAmount.mul(5)); }); it("Lending the max should work", async() => { await lendingManager.lend(token.address, mintAmount, COMPOUND); - + const tokens = await pie.getTokens(); - + expect(tokens.length).to.eq(1); expect(tokens[0]).to.eq(cToken.address); - + const tokenBalance = await token.balanceOf(pie.address); const cTokenBalance = await cToken.balanceOf(pie.address); - + expect(tokenBalance).to.eq(0); expect(cTokenBalance).to.eq(mintAmount.mul(5)); }); it("Lending more than the max should lend the max", async() => { await lendingManager.lend(token.address, mintAmount.add(parseEther("2")), COMPOUND); - + const tokens = await pie.getTokens(); - + expect(tokens.length).to.eq(1); expect(tokens[0]).to.eq(cToken.address); - + const tokenBalance = await token.balanceOf(pie.address); const cTokenBalance = await cToken.balanceOf(pie.address); - + expect(tokenBalance).to.eq(0); expect(cTokenBalance).to.eq(mintAmount.mul(5)); }); @@ -298,7 +298,7 @@ describe("LendingManager", function() { it("Unlending less than the max should work", async() => { const unlendAmount = mintAmount.div(2); await lendingManager.unlend(aToken.address, unlendAmount); - + const tokens = await pie.getTokens(); expect(tokens.length).to.eq(2); @@ -351,7 +351,7 @@ describe("LendingManager", function() { it("Unlending less than the max should work", async() => { const unlendAmount = mintAmount.div(2).mul(5); await lendingManager.unlend(cToken.address, unlendAmount); - + const tokens = await pie.getTokens(); expect(tokens.length).to.eq(2); @@ -419,7 +419,7 @@ describe("LendingManager", function() { const cTokenBalance = await cToken.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(cTokenBalance).to.eq(bounceAmount); expect(aTokenBalance).to.eq(mintAmount.div(2)); }); @@ -434,7 +434,7 @@ describe("LendingManager", function() { const cTokenBalance = await cToken.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(cTokenBalance).to.eq(0); expect(aTokenBalance).to.eq(mintAmount); }); @@ -449,7 +449,7 @@ describe("LendingManager", function() { const cTokenBalance = await cToken.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(cTokenBalance).to.eq(0); expect(aTokenBalance).to.eq(mintAmount); }); @@ -473,7 +473,7 @@ describe("LendingManager", function() { const cTokenBalance = await cToken.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(cTokenBalance).to.eq(cTokenAmount); expect(aTokenBalance).to.eq(bounceAmount); }); @@ -489,7 +489,7 @@ describe("LendingManager", function() { const cTokenBalance = await cToken.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(cTokenBalance).to.eq(cTokenAmount); expect(aTokenBalance).to.eq(0); }); @@ -505,7 +505,7 @@ describe("LendingManager", function() { const cTokenBalance = await cToken.balanceOf(pie.address); const aTokenBalance = await aToken.balanceOf(pie.address); - + expect(cTokenBalance).to.eq(cTokenAmount); expect(aTokenBalance).to.eq(0); }); diff --git a/test/lendingLogicCompound.ts b/test/lendingLogicCompound.ts index 0b86200..4139edf 100644 --- a/test/lendingLogicCompound.ts +++ b/test/lendingLogicCompound.ts @@ -22,6 +22,7 @@ chai.use(solidity); const mintAmount = parseEther("1000000"); // keccak("Compound"); +const COMPOUND = "0x561ca898cce9f021c15a441ef41899706e923541cee724530075d1a1144761c7"; const PLACEHOLDER_PROTOCOL = "0x561ca898cce9f021c15a441ef41899706e923541cee724530075d1a1144761c7"; describe("LendingLogicCompound", function() { @@ -39,7 +40,7 @@ describe("LendingLogicCompound", function() { signers = await ethers.getSigners(); account = await signers[0].getAddress(); timeTraveler = new TimeTraveler(ethereum); - + const tokenFactory = new MockTokenFactory(signers[0]); const cTokenFactory = new MockCTokenFactory(signers[0]); @@ -49,12 +50,12 @@ describe("LendingLogicCompound", function() { await token.mint(mintAmount, account); lendingRegistry = await (new LendingRegistryFactory(signers[0])).deploy(); - lendingLogic = await deployContract(signers[0], LendingLogicCompoundArtifact, [lendingRegistry.address, PLACEHOLDER_PROTOCOL]) as LendingLogicCompound; - + lendingLogic = await deployContract(signers[0], LendingLogicCompoundArtifact, [lendingRegistry.address, COMPOUND]) as LendingLogicCompound; + await lendingRegistry.setProtocolToLogic(PLACEHOLDER_PROTOCOL, lendingLogic.address); await lendingRegistry.setWrappedToProtocol(cToken.address, PLACEHOLDER_PROTOCOL); await lendingRegistry.setUnderlyingToProtocolWrapped(token.address, PLACEHOLDER_PROTOCOL, cToken.address); - + await timeTraveler.snapshot(); }); @@ -63,7 +64,10 @@ describe("LendingLogicCompound", function() { }); it("Deploying with the lending registry to the zero address should fail", async() => { - const promise = deployContract(signers[0], LendingLogicCompoundArtifact, [constants.AddressZero, PLACEHOLDER_PROTOCOL]); + const promise = deployContract(signers[0], LendingLogicCompoundArtifact, [ + constants.AddressZero, + COMPOUND + ]); await expect(promise).to.be.revertedWith("INVALID_LENDING_REGISTRY"); }); @@ -105,7 +109,7 @@ describe("LendingLogicCompound", function() { expect(calls.targets.length).to.eq(1); expect(calls.data.length).to.eq(1); - + await signers[0].sendTransaction({ to: calls.targets[0], data: calls.data[0]