From c4cf6eac2fad20ffa6b4a095fb6dc59f6eafc63e Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 6 Aug 2023 16:41:49 -0400 Subject: [PATCH] test 721 pool creation --- tests/erc-721-pool-factory.test.ts | 19 +++++++------ tests/utils/common.ts | 45 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/tests/erc-721-pool-factory.test.ts b/tests/erc-721-pool-factory.test.ts index c623765..55e4cea 100644 --- a/tests/erc-721-pool-factory.test.ts +++ b/tests/erc-721-pool-factory.test.ts @@ -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(() => { diff --git a/tests/utils/common.ts b/tests/utils/common.ts index fcfb0e1..0b8b20b 100644 --- a/tests/utils/common.ts +++ b/tests/utils/common.ts @@ -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" @@ -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 @@ -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)]) @@ -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