Skip to content

Commit

Permalink
add failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-abrioux committed Mar 3, 2021
1 parent f64c0a2 commit cd01845
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/v2/computation-and-formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
formatUserSummaryData,
} from '../../v2/computations-and-formatting';
import BigNumber from 'bignumber.js';
import { getCompoundedBalance } from '../../helpers/pool-math';

const mockReserve: ReserveData = {
underlyingAsset: '0xff795577d9ac8bd7d90ee22b6c1703490b6512fd',
Expand Down Expand Up @@ -151,5 +152,27 @@ describe('computations and formattings', () => {

expect(new BigNumber(second.totalDebt).gte(first.totalDebt)).toBe(true);
});

it('should compute collateral balance from blockchain data', () => {
// data exported from user 0xa5a69107816c5e3dfa5561e6b621dfe6294f6e5b
// at block number: 11581421
// reserve: YFI
const scaledATokenBalance = '161316503206059870';
const liquidityIndex = '1001723339432542553527150680';
const currentLiquidityRate = '22461916953455574582370088';
const lastUpdateTimestamp = 1609673617;
// at a later time, but on the same block
// expected balance computed with hardhat
const currentTimestamp = 1609675535;
const expectedATokenBalance = '161594727054623229';
const underlyingBalance = getCompoundedBalance(
scaledATokenBalance,
liquidityIndex,
currentLiquidityRate,
lastUpdateTimestamp,
currentTimestamp
).toString();
expect(underlyingBalance).toBe(expectedATokenBalance);
});
});
});

0 comments on commit cd01845

Please sign in to comment.