Skip to content

Commit

Permalink
test 721 pool creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Aug 6, 2023
1 parent aade448 commit c4cf6ea
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/erc-721-pool-factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import {
beforeAll,
afterAll
} from "matchstick-as/assembly/index"
import { Address } from "@graphprotocol/graph-ts"
import { handlePoolCreated } from "../src/erc-721-pool-factory"
import { createERC721PoolFactoryPoolCreatedEvent } from "./utils/erc-721-pool-factory-utils"
import { Address, BigInt, dataSource } from "@graphprotocol/graph-ts"

import { FIVE_PERCENT_BI, MAX_PRICE, ONE_BI, ZERO_BI } from "../src/utils/constants"
import { create721Pool } from "./utils/common"

// Tests structure (matchstick-as >=0.5.0)
// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0

describe("ERC721PoolFactory assertions", () => {
beforeAll(() => {
let pool_ = Address.fromString("0x0000000000000000000000000000000000000001")
let newERC721PoolFactoryPoolCreatedEvent = createERC721PoolFactoryPoolCreatedEvent(
pool_
)
handlePoolCreated(newERC721PoolFactoryPoolCreatedEvent)
const pool_ = Address.fromString("0x0000000000000000000000000000000000000001")
const expectedCollateralToken = Address.fromString("0x0000000000000000000000000000000000000002")
const expectedQuoteToken = Address.fromString("0x0000000000000000000000000000000000000003")
const expectedInitialInterestRate = FIVE_PERCENT_BI
const expectedInitialFeeRate = ZERO_BI

create721Pool(pool_, expectedCollateralToken, expectedQuoteToken, expectedInitialInterestRate, expectedInitialFeeRate)
})

afterAll(() => {
Expand Down
45 changes: 45 additions & 0 deletions tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Address, BigInt, Bytes, ethereum, dataSource, log } from "@graphprotoco
import { assert, createMockedFunction } from "matchstick-as"

import { handlePoolCreated } from "../../src/erc-20-pool-factory"
import { handlePoolCreated as handleERC721PoolCreated } from "../../src/erc-721-pool-factory"

import { createPoolCreatedEvent } from "./erc-20-pool-factory-utils"
import { createERC721PoolFactoryPoolCreatedEvent } from "./erc-721-pool-factory-utils"

import { BucketInfo } from "../../src/utils/pool/bucket"
import { wadToDecimal } from "../../src/utils/convert"
Expand Down Expand Up @@ -343,6 +346,7 @@ export function mockGetPoolKey(tokenId: BigInt, expectedPoolAddress: Address): v
/*** Pool Mock Functions ***/
/***************************/

// TODO: add mockGetRatesAndFees to this function
// create a pool entity and save it to the store
export function createPool(pool_: Address, collateral: Address, quote: Address, interestRate: BigInt, feeRate: BigInt): void {
// mock interest rate info contract call
Expand Down Expand Up @@ -371,6 +375,38 @@ export function createPool(pool_: Address, collateral: Address, quote: Address,
handlePoolCreated(newPoolCreatedEvent)
}

// create a 721 type pool entity and save it to the store
export function create721Pool(pool: Address, collateral: Address, quote: Address, interestRate: BigInt, feeRate: BigInt): void {
// mock rates and fees contract calls
mockGetRatesAndFees(pool, BigInt.fromString("980000000000000000"), BigInt.fromString("60000000000000000"))

// mock interest rate info contract call
createMockedFunction(pool, 'interestRateInfo', 'interestRateInfo():(uint256,uint256)')
.withArgs([])
.returns([
ethereum.Value.fromUnsignedBigInt(interestRate),
ethereum.Value.fromUnsignedBigInt(feeRate)
])

// mock get token address contract calls
createMockedFunction(pool, 'collateralAddress', 'collateralAddress():(address)')
.withArgs([])
.returns([ethereum.Value.fromAddress(collateral)])
createMockedFunction(pool, 'quoteTokenAddress', 'quoteTokenAddress():(address)')
.withArgs([])
.returns([ethereum.Value.fromAddress(quote)])

// mock get token info contract calls
mockGetERC721TokenInfo(collateral, 'collateral', 'C')
mockGetTokenInfo(quote, 'quote', 'Q', BigInt.fromI32(18), BigInt.fromI32(100))

// handlePoolCreated event
const newPoolCreatedEvent = createERC721PoolFactoryPoolCreatedEvent(pool)
// TODO: DYNAMICALLY SET THIS ADDRESS
newPoolCreatedEvent.address = Address.fromString("0x0000000000000000000000000000000000002020")
handleERC721PoolCreated(newPoolCreatedEvent)
}

export function mockGetBorrowerInfo(pool: Address, borrower: Address, expectedInfo: BorrowerInfo): void {
createMockedFunction(pool, 'borrowerInfo', 'borrowerInfo(address):(uint256,uint256,uint256)')
.withArgs([ethereum.Value.fromAddress(borrower)])
Expand Down Expand Up @@ -555,6 +591,15 @@ export function mockGetTokenInfo(token: Address, expectedName: string, expectedS
.returns([ethereum.Value.fromUnsignedBigInt(expectedTotalSupply)])
}

export function mockGetERC721TokenInfo(token: Address, expectedName: string, expectedSymbol: string): void {
createMockedFunction(token, 'name', 'name():(string)')
.withArgs([])
.returns([ethereum.Value.fromString(expectedName)])
createMockedFunction(token, 'symbol', 'symbol():(string)')
.withArgs([])
.returns([ethereum.Value.fromString(expectedSymbol)])
}

export class PoolMockParams {
// loans info mock params
poolSize: BigInt
Expand Down

0 comments on commit c4cf6ea

Please sign in to comment.