Skip to content

Commit

Permalink
Fix compound lending logic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Evert0x committed Dec 24, 2020
1 parent 03023e9 commit 00deafe
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 41 deletions.
70 changes: 35 additions & 35 deletions test/LendingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand All @@ -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));
});
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down
16 changes: 10 additions & 6 deletions test/lendingLogicCompound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ chai.use(solidity);

const mintAmount = parseEther("1000000");
// keccak("Compound");
const COMPOUND = "0x561ca898cce9f021c15a441ef41899706e923541cee724530075d1a1144761c7";
const PLACEHOLDER_PROTOCOL = "0x561ca898cce9f021c15a441ef41899706e923541cee724530075d1a1144761c7";

describe("LendingLogicCompound", function() {
Expand All @@ -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]);

Expand All @@ -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();
});

Expand All @@ -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");
});

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 00deafe

Please sign in to comment.