Skip to content

Commit cb209f6

Browse files
committed
🦨 Add test coverage to MDC package (#572)
1 parent 1ace8d7 commit cb209f6

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# tests coverage output
2+
coverage
3+
coverage.json

‎.solcover.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
skipFiles: [
3+
'./carbon',
4+
],
5+
modifierWhitelist: ['initializer'],
6+
onCompileComplete: async () => {
7+
const { spawn } = require('child_process')
8+
const child = spawn('pnpm', ['build:typechain'])
9+
await new Promise((res, rej) => {
10+
child.on('exit', res)
11+
child.on('error', rej)
12+
});
13+
},
14+
}

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"test:unit": "mocha 'test/**/*.test.ts'",
1919
"test": "pnpm test:unit",
2020
"test:ci": "pnpm run test",
21+
"coverage": "hardhat coverage --testfiles test/contracts/**/*.test.ts",
2122
"deploy:contracts": "bash ./scripts/guardedRun.sh"
2223
},
2324
"prettier": "prettier-config-archblock/contracts.json",

‎test/contracts/configure.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('MinimumDepositController.configure', () => {
1414
it('changes multiple values', async () => {
1515
const { depositController } = await loadFixture(minimumDepositControllerFixture)
1616
const status = PortfolioStatus.Live
17-
const depositAllowed = false
17+
const depositAllowed = !(await depositController.depositAllowed(status))
1818

1919
await depositController.configure(ceiling, depositFeeRate, minimumDeposit, lenderVerifierAddress, {
2020
status,
@@ -44,4 +44,24 @@ describe('MinimumDepositController.configure', () => {
4444
expect(await depositController.minimumDeposit()).to.eq(minimumDeposit)
4545
expect(await depositController.lenderVerifier()).to.eq(lenderVerifierAddress)
4646
})
47+
48+
it('can be called by anyone when not changing values', async () => {
49+
const { depositController, other } = await loadFixture(minimumDepositControllerFixture)
50+
51+
const status = PortfolioStatus.Live
52+
const ceiling = await depositController.ceiling()
53+
const depositFeeRate = await depositController.depositFeeRate()
54+
const minimumDeposit = await depositController.minimumDeposit()
55+
const lenderVerifierAddress = await depositController.lenderVerifier()
56+
const depositAllowed = await depositController.depositAllowed(status)
57+
58+
const controllerAsOther = depositController.connect(other)
59+
60+
expect(
61+
await controllerAsOther.configure(ceiling, depositFeeRate, minimumDeposit, lenderVerifierAddress, {
62+
status,
63+
value: depositAllowed,
64+
}),
65+
).not.to.be.reverted
66+
})
4767
})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { setupFixtureLoader } from 'test/setup'
2+
import { PortfolioStatus, structuredPortfolioFixture } from 'fixtures/structuredPortfolioFixture'
3+
import { parseUSDC } from 'utils'
4+
import { expect } from 'chai'
5+
import { MinimumDepositController__factory } from 'build/types'
6+
7+
describe('MinimumDepositController.maxDeposit', () => {
8+
const loadFixture = setupFixtureLoader()
9+
const minimumDeposit = parseUSDC(100)
10+
const ceiling = parseUSDC(5e9)
11+
12+
it('previews max deposit', async () => {
13+
const { equityTranche, wallet } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
14+
15+
expect(await equityTranche.maxDeposit(wallet.address)).to.eq(ceiling)
16+
})
17+
18+
it('previews current max deposit', async () => {
19+
const { equityTranche, wallet, depositToTranche } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
20+
await depositToTranche(equityTranche, minimumDeposit)
21+
22+
expect(await equityTranche.maxDeposit(wallet.address)).to.eq(ceiling.sub(minimumDeposit))
23+
})
24+
25+
it('returns zero if deposit is not allowed', async () => {
26+
const { equityTranche, wallet } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
27+
const depositController = MinimumDepositController__factory.connect(await equityTranche.depositController(), wallet)
28+
await depositController.setDepositAllowed(false, PortfolioStatus.CapitalFormation)
29+
30+
expect(await equityTranche.maxDeposit(wallet.address)).to.eq(0)
31+
})
32+
33+
it('returns zero if tranche is full', async () => {
34+
const { equityTranche, wallet, depositToTranche } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
35+
const depositController = MinimumDepositController__factory.connect(await equityTranche.depositController(), wallet)
36+
const amount = parseUSDC(150)
37+
await depositController.setCeiling(amount)
38+
await depositToTranche(equityTranche, amount)
39+
40+
expect(await equityTranche.maxDeposit(wallet.address)).to.eq(0)
41+
})
42+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { setupFixtureLoader } from 'test/setup'
2+
import { structuredPortfolioFixture } from 'fixtures/structuredPortfolioFixture'
3+
import { parseUSDC } from 'utils'
4+
import { expect } from 'chai'
5+
6+
describe('MinimumDepositController.previewMint', () => {
7+
const loadFixture = setupFixtureLoader()
8+
const minimumDeposit = parseUSDC(100)
9+
10+
it('previews the mint amount', async () => {
11+
const { equityTranche } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
12+
const amount = parseUSDC(100)
13+
14+
expect(await equityTranche.previewMint(amount)).to.eq(amount)
15+
})
16+
})

0 commit comments

Comments
 (0)