Skip to content

Commit

Permalink
Flashloan test (#74)
Browse files Browse the repository at this point in the history
* fit typo; make addressToBytes consistent in lpb management

* add flashloan tests

---------

Co-authored-by: Mike <[email protected]>
  • Loading branch information
MikeHathaway and Mike authored Oct 17, 2023
1 parent 5a5c222 commit 5b610e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/erc-20-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
logStore,
} from "matchstick-as/assembly/index"
import { Address, BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { handleAddCollateral, handleAddQuoteToken, handleBucketBankruptcy, handleBucketTake, handleBucketTakeLPAwarded, handleDrawDebt, handleKick, handleMoveQuoteToken, handleRepayDebt, handleReserveAuctionKick, handleReserveAuctionTake, handleTake, handleUpdateInterestRate } from "../src/mappings/erc-20-pool"
import { createAddCollateralEvent, createAddQuoteTokenEvent, createBucketBankruptcyEvent, createBucketTakeEvent, createBucketTakeLPAwardedEvent, createDrawDebtEvent, createKickEvent, createMoveQuoteTokenEvent, createRepayDebtEvent, createReserveAuctionKickEvent, createReserveAuctionTakeEvent, createTakeEvent, createUpdateInterestRateEvent } from "./utils/erc-20-pool-utils"
import { handleAddCollateral, handleAddQuoteToken, handleBucketBankruptcy, handleBucketTake, handleBucketTakeLPAwarded, handleDrawDebt, handleFlashloan, handleKick, handleMoveQuoteToken, handleRepayDebt, handleReserveAuctionKick, handleReserveAuctionTake, handleTake, handleUpdateInterestRate } from "../src/mappings/erc-20-pool"
import { createAddCollateralEvent, createAddQuoteTokenEvent, createBucketBankruptcyEvent, createBucketTakeEvent, createBucketTakeLPAwardedEvent, createDrawDebtEvent, createFlashLoanEvent, createKickEvent, createMoveQuoteTokenEvent, createRepayDebtEvent, createReserveAuctionKickEvent, createReserveAuctionTakeEvent, createTakeEvent, createUpdateInterestRateEvent } from "./utils/erc-20-pool-utils"
import {
assertBucketUpdate,
assertLendUpdate,
Expand Down Expand Up @@ -1638,4 +1638,18 @@ describe("ERC20Pool assertions", () => {
)
})

test("FlashLoan", () => {
// mock parameters
const poolAddress = Address.fromString("0x0000000000000000000000000000000000000001")
const reciever = Address.fromString("0x0000000000000000000000000000000000000002")
const token = Address.fromString("0x0000000000000000000000000000000000000012")
const amount = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18

const flashLoanEvent = createFlashLoanEvent(poolAddress, reciever, token, amount)
handleFlashloan(flashLoanEvent)

assert.entityCount("Flashloan", 1)

})

})
26 changes: 26 additions & 0 deletions tests/utils/erc-20-pool-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BucketTake,
BucketTakeLPAwarded,
DrawDebt,
Flashloan,
Kick,
KickReserveAuction,
MoveQuoteToken,
Expand Down Expand Up @@ -256,6 +257,31 @@ export function createDrawDebtEvent(
return drawDebtEvent
}

export function createFlashLoanEvent(
pool: Address,
reciever: Address,
token: Address,
amount: BigInt
): Flashloan {
let flashLoanEvent = changetype<Flashloan>(newMockEvent())

flashLoanEvent.parameters = new Array()

flashLoanEvent.parameters.push(
new ethereum.EventParam("reciever", ethereum.Value.fromAddress(reciever))
)
flashLoanEvent.parameters.push(
new ethereum.EventParam("token", ethereum.Value.fromAddress(token))
)
flashLoanEvent.parameters.push(
new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigInt(amount))
)

flashLoanEvent.address = pool

return flashLoanEvent
}

export function createKickEvent(
pool: Address,
kicker: Address,
Expand Down

0 comments on commit 5b610e7

Please sign in to comment.