Skip to content

Commit

Permalink
fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Dec 11, 2023
1 parent 5a37741 commit 646da38
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/utils/pool/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { PoolInfoUtils } from "../../../generated/templates/ERC20Pool/PoolInfoUt

import { wadToDecimal } from "../convert"
import { ONE_BI, ZERO_ADDRESS, ZERO_BD, ZERO_BI, poolInfoUtilsAddressTable } from "../constants"
import { thresholdPrice } from './loan';

export function getLiquidationAuctionId(poolId: Bytes, loanId: Bytes, kickBlock: BigInt): Bytes {
return poolId.concat(Bytes.fromUTF8('|' + loanId.toString() + '|' + kickBlock.toString()))
Expand Down
13 changes: 8 additions & 5 deletions tests/erc-20-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,9 @@ describe("ERC20Pool assertions", () => {
const expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
collateralPledged,
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// mock drawDebt event
Expand Down Expand Up @@ -601,8 +602,8 @@ describe("ERC20Pool assertions", () => {
const thresholdPrice = quoteRepaid.div(collateralPulled)

// TODO: fix mismatch between using pre-repay and post-repay update returns
const expectedBorrowerInfo = new BorrowerInfo(quoteRepaid, collateralPulled, BigInt.fromString("501250000000000000"))
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo, thresholdPrice)
const expectedBorrowerInfo = new BorrowerInfo(quoteRepaid, collateralPulled, BigInt.fromString("501250000000000000"), thresholdPrice)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

const newRepayDebtEvent = createRepayDebtEvent(
poolAddress,
Expand Down Expand Up @@ -867,8 +868,9 @@ describe("ERC20Pool assertions", () => {
let expectedBorrowerInfo = new BorrowerInfo(
wdiv(debt, inflator),
collateral,
wdiv(neutralPrice, inflator)),
wdiv(neutralPrice, inflator),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// mock kick event
Expand Down Expand Up @@ -915,8 +917,9 @@ describe("ERC20Pool assertions", () => {
expectedBorrowerInfo = new BorrowerInfo(
wdiv(debt, inflator),
collateral.minus(amountToTake),
wdiv(neutralPrice, inflator)),
wdiv(neutralPrice, inflator),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// mock take event
Expand Down
26 changes: 16 additions & 10 deletions tests/erc-721-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ describe("Describe entity assertions", () => {
const expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
amountPledged,
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

const newDrawDebtEvent = createDrawDebtNFTEvent(
Expand Down Expand Up @@ -415,8 +416,9 @@ describe("Describe entity assertions", () => {
let expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
amountPledged,
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

const newDrawDebtEvent = createDrawDebtNFTEvent(
Expand Down Expand Up @@ -762,7 +764,7 @@ describe("Describe entity assertions", () => {
const tokenIdsPledged = [BigInt.fromI32(234), BigInt.fromI32(345), BigInt.fromI32(456), BigInt.fromI32(567), BigInt.fromI32(789)]
const amountPledged = BigInt.fromString("5000000000000000000") // 5 * 1e18
const lup = BigInt.fromString("9529276179422528643") // 9.529276179422528643 * 1e18
const thresholdPrice = amountBorrowed.div(amountPledged)
let thresholdPrice = amountBorrowed.div(amountPledged)

// mock required contract calls
const expectedPoolDebtInfo = new DebtInfo(amountBorrowed, ZERO_BI, ZERO_BI, ZERO_BI)
Expand All @@ -772,8 +774,9 @@ describe("Describe entity assertions", () => {
let expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
amountPledged,
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// create and handle DrawDebt event
Expand Down Expand Up @@ -823,7 +826,7 @@ describe("Describe entity assertions", () => {
const kickTime = BigInt.fromI32(123)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const thresholdPrice = debt.div(amountPledged)
thresholdPrice = debt.div(amountPledged)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
const prev = Address.fromString("0x0000000000000000000000000000000000000000")
Expand Down Expand Up @@ -882,8 +885,9 @@ describe("Describe entity assertions", () => {
expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
amountPledged.minus(collateralToTake),
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// create and handle Take event
Expand Down Expand Up @@ -1163,7 +1167,7 @@ describe("Describe entity assertions", () => {
const amountBorrowed = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18
const tokenIdsPledged = [BigInt.fromI32(234), BigInt.fromI32(345), BigInt.fromI32(456), BigInt.fromI32(567), BigInt.fromI32(789)]
const amountPledged = BigInt.fromString("5000000000000000000") // 5 * 1e18
const thresholdPrice = amountBorrowed.div(amountPledged)
let thresholdPrice = amountBorrowed.div(amountPledged)

// mock required contract calls
const expectedPoolDebtInfo = new DebtInfo(amountBorrowed, ZERO_BI, ZERO_BI, ZERO_BI)
Expand All @@ -1173,8 +1177,9 @@ describe("Describe entity assertions", () => {
let expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
amountPledged,
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// create and handle DrawDebt event
Expand Down Expand Up @@ -1224,7 +1229,7 @@ describe("Describe entity assertions", () => {
const kickTime = BigInt.fromI32(123)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const thresholdPrice = debt.div(amountPledged)
thresholdPrice = debt.div(amountPledged)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
const prev = Address.fromString("0x0000000000000000000000000000000000000000")
Expand Down Expand Up @@ -1314,8 +1319,9 @@ describe("Describe entity assertions", () => {
expectedBorrowerInfo = new BorrowerInfo(
wdiv(amountBorrowed, inflator),
amountPledged.minus(collateralToTake),
BigInt.fromString("8766934085068726351")),
BigInt.fromString("8766934085068726351"),
thresholdPrice
)
mockGetBorrowerInfo(poolAddress, borrower, expectedBorrowerInfo)

// mock bucket take event
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/mock-contract-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function mockGetPositionInfo(tokenId: BigInt, bucketIndex: BigInt, expect
/***************************/

export function mockGetBorrowerInfo(pool: Address, borrower: Address, expectedInfo: BorrowerInfo): void {
createMockedFunction(pool, 'borrowerInfo', 'borrowerInfo(address):(uint256,uint256,uint256)')
createMockedFunction(pool, 'borrowerInfo', 'borrowerInfo(address):(uint256,uint256,uint256,uint256)')
.withArgs([ethereum.Value.fromAddress(borrower)])
.returns([
ethereum.Value.fromUnsignedBigInt(expectedInfo.t0debt),
Expand Down

0 comments on commit 646da38

Please sign in to comment.