From ce356d767e1bfcfccf27ab4fb5150b08c3d76379 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Fri, 29 Nov 2024 10:09:01 -0300 Subject: [PATCH] test: update unit tests --- .../isolated-pools/tests/Pool/index.test.ts | 4 ++ .../tests/RewardsDistributor/index.test.ts | 21 +++++- .../isolated-pools/tests/VToken/index.test.ts | 17 +++-- .../isolated-pools/tests/VToken/mocks.ts | 69 ++++--------------- 4 files changed, 48 insertions(+), 63 deletions(-) diff --git a/subgraphs/isolated-pools/tests/Pool/index.test.ts b/subgraphs/isolated-pools/tests/Pool/index.test.ts index 4a0fa503..f1351987 100644 --- a/subgraphs/isolated-pools/tests/Pool/index.test.ts +++ b/subgraphs/isolated-pools/tests/Pool/index.test.ts @@ -60,6 +60,9 @@ const newAddress = Address.fromString('0x0000000000000000000000000000000000000e0 const accountAddress = Address.fromString('0x0000000000000000000000000000000000000d0d'); const interestRateModelAddress = Address.fromString('0x594942C0e62eC577889777424CD367545C796A74'); +const accessControlManagerAddress = Address.fromString( + '0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA', +); const rewardsDistributorAddress = Address.fromString('0x082F27894f3E3CbC2790899AEe82D6f149521AFa'); @@ -80,6 +83,7 @@ beforeAll(() => { BigInt.fromI32(18), balanceOfAccount, interestRateModelAddress, + accessControlManagerAddress, underlyingPrice, ); diff --git a/subgraphs/isolated-pools/tests/RewardsDistributor/index.test.ts b/subgraphs/isolated-pools/tests/RewardsDistributor/index.test.ts index 9cbf596c..b3fa07d7 100644 --- a/subgraphs/isolated-pools/tests/RewardsDistributor/index.test.ts +++ b/subgraphs/isolated-pools/tests/RewardsDistributor/index.test.ts @@ -18,7 +18,7 @@ import { } from '../../src/mappings/rewardsDistributor'; import { getRewardSpeedId } from '../../src/utilities/ids'; import { createNewRewardsDistributor } from '../Pool/events'; -import { createMarketMock } from '../VToken/mocks'; +import { createVBep20AndUnderlyingMock } from '../VToken/mocks'; import { createRewardTokenBorrowSpeedUpdatedEvent, createRewardTokenSupplySpeedUpdatedEvent, @@ -26,9 +26,15 @@ import { import { createRewardsDistributorMock } from './mocks'; const vTokenAddress = Address.fromString('0x0000000000000000000000000000000000000a0a'); +const underlyingAddress = Address.fromString('0x0000000000000000000000000000000000000111'); const comptrollerAddress = Address.fromString('0x0000000000000000000000000000000000000c0c'); const rewardsDistributorAddress = Address.fromString('0x082F27894f3E3CbC2790899AEe82D6f149521AFa'); const tokenAddress = Address.fromString('0x0000000000000000000000000000000000000b0b'); +const interestRateModelAddress = Address.fromString('0x594942C0e62eC577889777424CD367545C796A74'); +const accessControlManagerAddress = Address.fromString( + '0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA', +); +const underlyingPrice = BigInt.fromString('15000000000000000'); const cleanup = (): void => { clearStore(); @@ -48,7 +54,18 @@ beforeEach(() => { ); handleNewRewardsDistributor(newRewardsDistributorEvent); - createMarketMock(vTokenAddress); + createVBep20AndUnderlyingMock( + vTokenAddress, + underlyingAddress, + comptrollerAddress, + 'AAA Coin', + 'AAA', + BigInt.fromI32(18), + BigInt.fromI32(100), + interestRateModelAddress, + accessControlManagerAddress, + underlyingPrice, + ); }); afterEach(() => { diff --git a/subgraphs/isolated-pools/tests/VToken/index.test.ts b/subgraphs/isolated-pools/tests/VToken/index.test.ts index 9741d0be..8d3a6203 100644 --- a/subgraphs/isolated-pools/tests/VToken/index.test.ts +++ b/subgraphs/isolated-pools/tests/VToken/index.test.ts @@ -57,7 +57,7 @@ import { createTransferEvent, } from './events'; import { PoolInfo, createAccountVTokenBalanceOfMock, createPoolRegistryMock } from './mocks'; -import { createMarketMock, createPriceOracleMock, createVBep20AndUnderlyingMock } from './mocks'; +import { createPriceOracleMock, createVBep20AndUnderlyingMock } from './mocks'; const underlying1Address = Address.fromString('0x0000000000000000000000000000000000000111'); const underlying2Address = Address.fromString('0x0000000000000000000000000000000000000222'); @@ -69,6 +69,9 @@ const bTokenAddress = Address.fromString('0x000000000000000000000000000000000000 const rootAddress = Address.fromString('0x0000000000000000000000000000000000000072'); const interestRateModelAddress = Address.fromString('0x594942C0e62eC577889777424CD367545C796A74'); +const accessControlManagerAddress = Address.fromString( + '0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA', +); const underlyingPrice = BigInt.fromString('15000000000000000'); @@ -86,6 +89,7 @@ beforeAll(() => { BigInt.fromI32(18), BigInt.fromI32(100), interestRateModelAddress, + accessControlManagerAddress, underlyingPrice, ); @@ -98,11 +102,10 @@ beforeAll(() => { BigInt.fromI32(18), BigInt.fromI32(100), interestRateModelAddress, + accessControlManagerAddress, underlyingPrice, ); - createMarketMock(aTokenAddress); - createPriceOracleMock([[ethereum.Value.fromAddress(aTokenAddress), ethereum.Value.fromI32(99)]]); createPoolRegistryMock([new PoolInfo('Gamer Pool', rootAddress, comptrollerAddress)]); @@ -553,11 +556,11 @@ describe('VToken', () => { }; assertMarketDocument('accrualBlockNumber', '999'); - assertMarketDocument('totalSupplyVTokenMantissa', '36504567163409'); // value from mock + assertMarketDocument('totalSupplyVTokenMantissa', '0'); // value from mock assertMarketDocument('exchangeRateMantissa', '365045823500000000000000'); - assertMarketDocument('borrowIndex', '300000000000000000000'); + assertMarketDocument('borrowIndex', '1'); assertMarketDocument('reservesMantissa', '5128924555022289393'); - assertMarketDocument('totalBorrowsMantissa', '2641234234636158123'); + assertMarketDocument('totalBorrowsMantissa', '62197468301'); assertMarketDocument('cashMantissa', '1418171344423412457'); assertMarketDocument('borrowRateMantissa', '12678493'); assertMarketDocument('supplyRateMantissa', '12678493'); @@ -829,7 +832,7 @@ describe('VToken', () => { test('registers increase and decrease in the market supplier count', () => { const market = getMarket(aTokenAddress)!; - const marketId = market.id.toHexString(); + const marketId = aTokenAddress.toHexString(); assert.assertNotNull(market); if (!market) { return; diff --git a/subgraphs/isolated-pools/tests/VToken/mocks.ts b/subgraphs/isolated-pools/tests/VToken/mocks.ts index d897a35d..72ab4b71 100644 --- a/subgraphs/isolated-pools/tests/VToken/mocks.ts +++ b/subgraphs/isolated-pools/tests/VToken/mocks.ts @@ -87,6 +87,7 @@ export const createVBep20AndUnderlyingMock = ( decimals: BigInt, reserveFactorMantissa: BigInt, interestRateModelAddress: Address, + accessControlManagerAddress: Address, underlyingPrice: BigInt, ): void => { // vBep20 @@ -122,6 +123,12 @@ export const createVBep20AndUnderlyingMock = ( ethereum.Value.fromAddress(comptrollerAddress), ]); + createMockedFunction( + contractAddress, + 'accessControlManager', + 'accessControlManager():(address)', + ).returns([ethereum.Value.fromAddress(accessControlManagerAddress)]); + // Underlying createMockedFunction(underlyingAddress, 'decimals', 'decimals():(uint8)').returns([ ethereum.Value.fromUnsignedBigInt(decimals), @@ -147,17 +154,17 @@ export const createVBep20AndUnderlyingMock = ( contractAddress, 'borrowRatePerBlock', 'borrowRatePerBlock():(uint256)', - ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('12678493'))]); createMockedFunction(contractAddress, 'getCash', 'getCash():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1418171344423412457')), ]); createMockedFunction( contractAddress, 'exchangeRateStored', 'exchangeRateStored():(uint256)', - ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('365045823500000000000000'))]); createMockedFunction(contractAddress, 'badDebt', 'badDebt():(uint256)').returns([ ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0')), @@ -168,28 +175,28 @@ export const createVBep20AndUnderlyingMock = ( ]); createMockedFunction(contractAddress, 'totalBorrows', 'totalBorrows():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('36504567163409')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('100000000000000000')), ]); createMockedFunction(contractAddress, 'totalReserves', 'totalReserves():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('5128924555022289393')), ]); createMockedFunction( contractAddress, 'accrualBlockNumber', 'accrualBlockNumber():(uint256)', - ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('999'))]); createMockedFunction(contractAddress, 'borrowIndex', 'borrowIndex():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0')), + ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000')), ]); createMockedFunction( contractAddress, 'supplyRatePerBlock', 'supplyRatePerBlock():(uint256)', - ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('0'))]); + ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('12678493'))]); createMockedFunction(comptrollerAddress, 'supplyCaps', 'supplyCaps(address):(uint256)') .withArgs([ethereum.Value.fromAddress(contractAddress)]) @@ -208,52 +215,6 @@ export const createVBep20AndUnderlyingMock = ( ]); }; -export const createMarketMock = (marketAddress: Address): void => { - createMockedFunction( - marketAddress, - 'accrualBlockNumber', - 'accrualBlockNumber():(uint256)', - ).returns([ethereum.Value.fromI32(999)]); - - createMockedFunction(marketAddress, 'totalSupply', 'totalSupply():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('36504567163409')), - ]); - - createMockedFunction( - marketAddress, - 'exchangeRateStored', - 'exchangeRateStored():(uint256)', - ).returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromString('365045823500000000000000'))]); - - createMockedFunction(marketAddress, 'borrowIndex', 'borrowIndex():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('300000000000000000000')), - ]); - - createMockedFunction(marketAddress, 'totalReserves', 'totalReserves():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('5128924555022289393')), - ]); - - createMockedFunction(marketAddress, 'totalBorrows', 'totalBorrows():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('2641234234636158123')), - ]); - - createMockedFunction(marketAddress, 'getCash', 'getCash():(uint256)').returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromString('1418171344423412457')), - ]); - - createMockedFunction( - marketAddress, - 'borrowRatePerBlock', - 'borrowRatePerBlock():(uint256)', - ).returns([ethereum.Value.fromI32(12678493)]); - - createMockedFunction( - marketAddress, - 'supplyRatePerBlock', - 'supplyRatePerBlock():(uint256)', - ).returns([ethereum.Value.fromI32(12678493)]); -}; - // type Tokens = [address, price][] export const createPriceOracleMock = (tokens: Array>): void => { tokens.forEach((token): void => {