Skip to content

Commit

Permalink
🦨 Add test coverage to MDC package (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
truefibot committed Jan 27, 2023
1 parent 1ace8d7 commit cb209f6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# tests coverage output
coverage
coverage.json
14 changes: 14 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
skipFiles: [
'./carbon',
],
modifierWhitelist: ['initializer'],
onCompileComplete: async () => {
const { spawn } = require('child_process')
const child = spawn('pnpm', ['build:typechain'])
await new Promise((res, rej) => {
child.on('exit', res)
child.on('error', rej)
});
},
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test:unit": "mocha 'test/**/*.test.ts'",
"test": "pnpm test:unit",
"test:ci": "pnpm run test",
"coverage": "hardhat coverage --testfiles test/contracts/**/*.test.ts",
"deploy:contracts": "bash ./scripts/guardedRun.sh"
},
"prettier": "prettier-config-archblock/contracts.json",
Expand Down
22 changes: 21 additions & 1 deletion test/contracts/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('MinimumDepositController.configure', () => {
it('changes multiple values', async () => {
const { depositController } = await loadFixture(minimumDepositControllerFixture)
const status = PortfolioStatus.Live
const depositAllowed = false
const depositAllowed = !(await depositController.depositAllowed(status))

await depositController.configure(ceiling, depositFeeRate, minimumDeposit, lenderVerifierAddress, {
status,
Expand Down Expand Up @@ -44,4 +44,24 @@ describe('MinimumDepositController.configure', () => {
expect(await depositController.minimumDeposit()).to.eq(minimumDeposit)
expect(await depositController.lenderVerifier()).to.eq(lenderVerifierAddress)
})

it('can be called by anyone when not changing values', async () => {
const { depositController, other } = await loadFixture(minimumDepositControllerFixture)

const status = PortfolioStatus.Live
const ceiling = await depositController.ceiling()
const depositFeeRate = await depositController.depositFeeRate()
const minimumDeposit = await depositController.minimumDeposit()
const lenderVerifierAddress = await depositController.lenderVerifier()
const depositAllowed = await depositController.depositAllowed(status)

const controllerAsOther = depositController.connect(other)

expect(
await controllerAsOther.configure(ceiling, depositFeeRate, minimumDeposit, lenderVerifierAddress, {
status,
value: depositAllowed,
}),
).not.to.be.reverted
})
})
42 changes: 42 additions & 0 deletions test/contracts/maxDeposit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { setupFixtureLoader } from 'test/setup'
import { PortfolioStatus, structuredPortfolioFixture } from 'fixtures/structuredPortfolioFixture'
import { parseUSDC } from 'utils'
import { expect } from 'chai'
import { MinimumDepositController__factory } from 'build/types'

describe('MinimumDepositController.maxDeposit', () => {
const loadFixture = setupFixtureLoader()
const minimumDeposit = parseUSDC(100)
const ceiling = parseUSDC(5e9)

it('previews max deposit', async () => {
const { equityTranche, wallet } = await loadFixture(structuredPortfolioFixture(minimumDeposit))

expect(await equityTranche.maxDeposit(wallet.address)).to.eq(ceiling)
})

it('previews current max deposit', async () => {
const { equityTranche, wallet, depositToTranche } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
await depositToTranche(equityTranche, minimumDeposit)

expect(await equityTranche.maxDeposit(wallet.address)).to.eq(ceiling.sub(minimumDeposit))
})

it('returns zero if deposit is not allowed', async () => {
const { equityTranche, wallet } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
const depositController = MinimumDepositController__factory.connect(await equityTranche.depositController(), wallet)
await depositController.setDepositAllowed(false, PortfolioStatus.CapitalFormation)

expect(await equityTranche.maxDeposit(wallet.address)).to.eq(0)
})

it('returns zero if tranche is full', async () => {
const { equityTranche, wallet, depositToTranche } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
const depositController = MinimumDepositController__factory.connect(await equityTranche.depositController(), wallet)
const amount = parseUSDC(150)
await depositController.setCeiling(amount)
await depositToTranche(equityTranche, amount)

expect(await equityTranche.maxDeposit(wallet.address)).to.eq(0)
})
})
16 changes: 16 additions & 0 deletions test/contracts/previewMint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { setupFixtureLoader } from 'test/setup'
import { structuredPortfolioFixture } from 'fixtures/structuredPortfolioFixture'
import { parseUSDC } from 'utils'
import { expect } from 'chai'

describe('MinimumDepositController.previewMint', () => {
const loadFixture = setupFixtureLoader()
const minimumDeposit = parseUSDC(100)

it('previews the mint amount', async () => {
const { equityTranche } = await loadFixture(structuredPortfolioFixture(minimumDeposit))
const amount = parseUSDC(100)

expect(await equityTranche.previewMint(amount)).to.eq(amount)
})
})

0 comments on commit cb209f6

Please sign in to comment.