diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4cb2ba1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# tests coverage output +coverage +coverage.json diff --git a/.solcover.js b/.solcover.js new file mode 100644 index 0000000..6394f15 --- /dev/null +++ b/.solcover.js @@ -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) + }); + }, +} diff --git a/package.json b/package.json index 8363d6c..e9745ba 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/contracts/configure.test.ts b/test/contracts/configure.test.ts index e313ff5..a076046 100644 --- a/test/contracts/configure.test.ts +++ b/test/contracts/configure.test.ts @@ -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, @@ -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 + }) }) diff --git a/test/contracts/maxDeposit.test.ts b/test/contracts/maxDeposit.test.ts new file mode 100644 index 0000000..05e5728 --- /dev/null +++ b/test/contracts/maxDeposit.test.ts @@ -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) + }) +}) diff --git a/test/contracts/previewMint.test.ts b/test/contracts/previewMint.test.ts new file mode 100644 index 0000000..903415c --- /dev/null +++ b/test/contracts/previewMint.test.ts @@ -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) + }) +})