Skip to content

Commit 4fa6405

Browse files
committed
add test for agent/lockup
1 parent 7735190 commit 4fa6405

6 files changed

Lines changed: 195 additions & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ethers } from 'ethers'
2+
import { testProviders } from '../common/const'
3+
import { calculateCumulativeHoldersRewardAmount } from './calculateCumulativeHoldersRewardAmount'
4+
import { getLockupContract } from './common'
5+
6+
jest.mock('./common', () => {
7+
return {
8+
getLockupContract: jest.fn(),
9+
}
10+
})
11+
12+
describe('calculateCumulativeHoldersRewardAmount.ts', () => {
13+
const options = {
14+
provider: testProviders.ropsten,
15+
propertyAddress: '0x38c4bF6cD20d157EE45553b0fAD13B0c6750b439',
16+
}
17+
it('success', async () => {
18+
const expected = '100'
19+
;(getLockupContract as jest.Mock).mockReturnValue({
20+
calculateCumulativeHoldersRewardAmount: (property: string) => expected,
21+
})
22+
const result = await calculateCumulativeHoldersRewardAmount(options)
23+
expect(result).toEqual(expected)
24+
})
25+
it('return undefined if no valid network', async () => {
26+
const expected = undefined
27+
;(getLockupContract as jest.Mock).mockReturnValue(undefined)
28+
const result = await calculateCumulativeHoldersRewardAmount(options)
29+
expect(result).toEqual(expected)
30+
})
31+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { calculateRewardAmount } from './calculateRewardAmount'
2+
import { getLockupContract } from './common'
3+
import { testProviders } from '../common/const'
4+
5+
jest.mock('./common', () => {
6+
return {
7+
getLockupContract: jest.fn(),
8+
}
9+
})
10+
describe('calculateRewardAmount.ts', () => {
11+
const options = {
12+
provider: testProviders.ropsten,
13+
propertyAddress: '0x38c4bF6cD20d157EE45553b0fAD13B0c6750b439',
14+
}
15+
16+
it('success', async () => {
17+
const expected = ['abc', '123']
18+
;(getLockupContract as jest.Mock).mockReturnValue({
19+
calculateRewardAmount: (propertyAddress: string) => expected,
20+
})
21+
const result = await calculateRewardAmount(options)
22+
expect(result).toEqual(expected)
23+
})
24+
it('return undefined if no valid provider', async () => {
25+
const expected = undefined
26+
;(getLockupContract as jest.Mock).mockReturnValue({
27+
calculateRewardAmount: (propertyAddress: string) => undefined,
28+
})
29+
const result = await calculateRewardAmount(options)
30+
expect(result).toEqual(expected)
31+
})
32+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { calculateWithdrawableInterestAmountByPosition } from './calculateWithdrawableInterestAmountByPosition'
2+
import { getLockupContract } from './common'
3+
import { testProviders } from '../common/const'
4+
5+
jest.mock('./common', () => {
6+
return {
7+
getLockupContract: jest.fn(),
8+
}
9+
})
10+
11+
describe('calculateWithdrawableInterestAmountByPosition.ts', () => {
12+
const options = {
13+
provider: testProviders.ropsten,
14+
positionTokenId: '1',
15+
}
16+
17+
it('success', async () => {
18+
const expected = '123'
19+
;(getLockupContract as jest.Mock).mockReturnValue({
20+
calculateWithdrawableInterestAmountByPosition: (
21+
positionTokenId: string
22+
) => expected,
23+
})
24+
const result = await calculateWithdrawableInterestAmountByPosition(options)
25+
expect(result).toEqual(expected)
26+
})
27+
28+
it('return undefined if no valid network', async () => {
29+
const expected = undefined
30+
;(getLockupContract as jest.Mock).mockReturnValue(undefined)
31+
const result = await calculateWithdrawableInterestAmountByPosition(options)
32+
expect(result).toEqual(expected)
33+
})
34+
})

lib/agent/lockup/cap.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { getCap } from './cap'
2+
import { getLockupContract } from './common'
3+
import { testProviders } from '../common/const'
4+
5+
jest.mock('./common', () => {
6+
return {
7+
getLockupContract: jest.fn(),
8+
}
9+
})
10+
11+
describe('cap.ts', () => {
12+
const options = {
13+
provider: testProviders.ropsten,
14+
}
15+
16+
it('success', async () => {
17+
const expected = '123456'
18+
;(getLockupContract as jest.Mock).mockReturnValue({
19+
cap: () => expected,
20+
})
21+
const result = await getCap(options)
22+
expect(result).toEqual(expected)
23+
})
24+
25+
it('return undefined if no valid provider', async () => {
26+
const expected = undefined
27+
;(getLockupContract as jest.Mock).mockReturnValue(expected)
28+
const result = await getCap(options)
29+
expect(result).toEqual(expected)
30+
})
31+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { depositToPosition } from './depositToPosition'
2+
import { getLockupContract } from './common'
3+
import { testProviders } from '../common/const'
4+
5+
jest.mock('./common', () => {
6+
return {
7+
getLockupContract: jest.fn()
8+
}
9+
})
10+
11+
describe('depositToPosition.ts', () => {
12+
const options = {
13+
provider: testProviders.ropsten,
14+
positionTokenId: '1',
15+
amount: '100'
16+
}
17+
it('success', async () => {
18+
const expected = true
19+
20+
;(getLockupContract as jest.Mock).mockReturnValue({
21+
depositToPosition: (positionTokenId: string, amount: string) => expected
22+
})
23+
24+
const result = await depositToPosition(options)
25+
expect(result).toEqual(expected)
26+
})
27+
it('return undefined if no valid network', async () => {
28+
const expected = undefined
29+
;(getLockupContract as jest.Mock).mockReturnValue(undefined)
30+
const result = await depositToPosition(options)
31+
expect(result).toEqual(expected)
32+
})
33+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { testProviders } from '../common/const'
2+
import { getLockupContract } from './common'
3+
import { withdrawByPosition } from './withdrawByPosition'
4+
5+
jest.mock('./common', () => {
6+
return {
7+
getLockupContract: jest.fn(),
8+
}
9+
})
10+
11+
describe('withdrawByPosition.ts', () => {
12+
const options = {
13+
provider: testProviders.ropsten,
14+
positionTokenId: '1',
15+
amount: '100',
16+
}
17+
it('success', async () => {
18+
const expected = true
19+
;(getLockupContract as jest.Mock).mockReturnValue({
20+
withdrawByPosition: (positionTokenId: string, amount: string) => true,
21+
})
22+
const result = await withdrawByPosition(options)
23+
expect(result).toEqual(expected)
24+
})
25+
26+
it('return undefined if no valid provider', async () => {
27+
const expected = undefined
28+
;(getLockupContract as jest.Mock).mockReturnValue({
29+
withdrawByPosition: () => undefined,
30+
})
31+
const result = await withdrawByPosition(options)
32+
expect(result).toEqual(expected)
33+
})
34+
})

0 commit comments

Comments
 (0)