Skip to content

Commit

Permalink
test: update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Nov 29, 2024
1 parent e536b3b commit ce356d7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 63 deletions.
4 changes: 4 additions & 0 deletions subgraphs/isolated-pools/tests/Pool/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -80,6 +83,7 @@ beforeAll(() => {
BigInt.fromI32(18),
balanceOfAccount,
interestRateModelAddress,
accessControlManagerAddress,
underlyingPrice,
);

Expand Down
21 changes: 19 additions & 2 deletions subgraphs/isolated-pools/tests/RewardsDistributor/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ 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,
} from './events';
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();
Expand All @@ -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(() => {
Expand Down
17 changes: 10 additions & 7 deletions subgraphs/isolated-pools/tests/VToken/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');

Expand All @@ -86,6 +89,7 @@ beforeAll(() => {
BigInt.fromI32(18),
BigInt.fromI32(100),
interestRateModelAddress,
accessControlManagerAddress,
underlyingPrice,
);

Expand All @@ -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)]);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
69 changes: 15 additions & 54 deletions subgraphs/isolated-pools/tests/VToken/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const createVBep20AndUnderlyingMock = (
decimals: BigInt,
reserveFactorMantissa: BigInt,
interestRateModelAddress: Address,
accessControlManagerAddress: Address,
underlyingPrice: BigInt,
): void => {
// vBep20
Expand Down Expand Up @@ -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),
Expand All @@ -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')),
Expand All @@ -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)])
Expand All @@ -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<Array<ethereum.Value>>): void => {
tokens.forEach((token): void => {
Expand Down

0 comments on commit ce356d7

Please sign in to comment.