-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d69dff
commit 455bbb4
Showing
36 changed files
with
2,608 additions
and
852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/core/src/balances/__tests__/fetchVTokenBalances.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { makeFetchVTokenBalances } from '../fetchVTokenBalances'; | ||
|
||
let erc20BalancesResponse: any; | ||
let querySubgraph: jest.Mock; | ||
let fetchVTokenBalances: ReturnType<typeof makeFetchVTokenBalances>; | ||
let args: Parameters<typeof fetchVTokenBalances>[0]; | ||
let run: () => ReturnType<typeof fetchVTokenBalances>; | ||
|
||
beforeEach(() => { | ||
erc20BalancesResponse = { | ||
erc20Balances: [ | ||
{ | ||
id: '0x0000000', | ||
valueExact: '1000000000000000000', | ||
contract: { | ||
id: '0x0000000', | ||
asVaultAsset: { | ||
vaultId: '0', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
querySubgraph = jest.fn().mockResolvedValue(erc20BalancesResponse); | ||
fetchVTokenBalances = makeFetchVTokenBalances({ querySubgraph }); | ||
args = { | ||
userAddresses: ['0x0000000'], | ||
}; | ||
run = () => fetchVTokenBalances(args); | ||
}); | ||
|
||
it('returns a list of all vToken balances for a given address', async () => { | ||
const result = await run(); | ||
expect(result).toEqual([ | ||
{ | ||
type: 'vToken', | ||
id: '0x0000000', | ||
vaultId: '0', | ||
balance: BigInt('1000000000000000000'), | ||
}, | ||
]); | ||
}); | ||
|
||
it('returns a list of vToken balances for a vault address', async () => { | ||
args.vaultAddresses = ['0x0000000']; | ||
const result = await run(); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
type: 'vToken', | ||
id: '0x0000000', | ||
vaultId: '0', | ||
balance: BigInt('1000000000000000000'), | ||
}, | ||
]); | ||
}); | ||
|
||
it('returns a list of vToken balances for a vaultId', async () => { | ||
args.vaultIds = ['1']; | ||
const result = await run(); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
describe('when there are more than 1000 balances', () => { | ||
beforeEach(() => { | ||
const response = { | ||
erc20Balances: new Array(1000).fill( | ||
erc20BalancesResponse.erc20Balances[0] | ||
), | ||
}; | ||
querySubgraph.mockResolvedValueOnce(response); | ||
}); | ||
|
||
it('recusively fetches all balances', async () => { | ||
const result = await run(); | ||
|
||
expect(result.length).toEqual(1001); | ||
expect(querySubgraph).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/core/src/pools/__tests__/fetchPremiumPaids.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { makeFetchPremiumPaids } from '../fetchPremiumPaids'; | ||
|
||
let queryResponse: any; | ||
let querySubgraph: jest.Mock; | ||
let fetchPremiumPaids: ReturnType<typeof makeFetchPremiumPaids>; | ||
let args: Parameters<typeof fetchPremiumPaids>[0]; | ||
let run: () => ReturnType<typeof fetchPremiumPaids>; | ||
|
||
beforeEach(() => { | ||
queryResponse = { | ||
premiumPaids: [ | ||
{ | ||
amount: '100000000000000000000', | ||
date: '1629830400', | ||
id: '0x000000', | ||
to: { | ||
id: '0x0', | ||
}, | ||
vault: { | ||
id: '0x0', | ||
vaultId: '0', | ||
}, | ||
}, | ||
], | ||
}; | ||
querySubgraph = jest.fn().mockResolvedValue(queryResponse); | ||
fetchPremiumPaids = makeFetchPremiumPaids({ querySubgraph }); | ||
|
||
args = { | ||
network: 1, | ||
}; | ||
|
||
run = () => fetchPremiumPaids(args); | ||
}); | ||
|
||
it('fetches premium paids', async () => { | ||
const result = await run(); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
amount: BigInt('100000000000000000000'), | ||
date: 1629830400, | ||
to: '0x0', | ||
vaultAddress: '0x0', | ||
vaultId: '0', | ||
}, | ||
]); | ||
}); | ||
|
||
describe('when there are more than 1000 premium paids', () => { | ||
beforeEach(() => { | ||
querySubgraph.mockResolvedValueOnce({ | ||
premiumPaids: new Array(1000).fill(queryResponse.premiumPaids[0]), | ||
}); | ||
}); | ||
|
||
it('recusrively fetches all premium paids', async () => { | ||
const result = await run(); | ||
|
||
expect(result).toHaveLength(1001); | ||
}); | ||
}); |
Oops, something went wrong.