Skip to content

Commit 59725c5

Browse files
committed
test: add coverage for remaining branches in IssuanceAllocator
Added two tests to achieve 100% branch coverage: - Test for TargetAddressCannotBeZero error when trying to set allocation for address(0) while default is a real address - Test for getTotalAllocation() when default is a real address (not address(0)) Branch coverage: 97.96% → 100% All files now at 100% coverage (statements, branches, functions, lines) Total tests: 165 → 167
1 parent e0c3548 commit 59725c5

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

packages/issuance/contracts/allocate/IssuanceAllocator.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,9 @@ contract IssuanceAllocator is
566566
// (Would not be likely to be exploitable due to only governor being able to
567567
// make a call to set target allocation, but better to be paranoid.)
568568

569-
uint256 availablePPM = defaultTarget.allocatorMintingPPM + targetData.allocatorMintingPPM + targetData.selfMintingPPM;
569+
uint256 availablePPM = defaultTarget.allocatorMintingPPM +
570+
targetData.allocatorMintingPPM +
571+
targetData.selfMintingPPM;
570572
// solhint-disable-next-line gas-strict-inequalities
571573
require(allocatorMintingPPM + selfMintingPPM <= availablePPM, InsufficientAllocationAvailable());
572574

packages/issuance/test/tests/allocate/DefaultAllocation.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ describe('IssuanceAllocator - Default Allocation', () => {
344344
const allocation = await issuanceAllocator.getTargetAllocation(addresses.target1)
345345
expect(allocation.totalAllocationPPM).to.equal(300_000n)
346346
})
347+
348+
it('should revert when trying to set allocation for address(0) when default is not address(0)', async () => {
349+
// Change default to target1
350+
await issuanceAllocator.connect(accounts.governor).setDefaultAllocationAddress(addresses.target1)
351+
352+
// Try to set allocation for address(0) directly should fail
353+
await expectCustomError(
354+
issuanceAllocator
355+
.connect(accounts.governor)
356+
['setTargetAllocation(address,uint256)'](ethers.ZeroAddress, 300_000n),
357+
issuanceAllocator,
358+
'TargetAddressCannotBeZero',
359+
)
360+
})
347361
})
348362

349363
describe('Distribution with default allocation', () => {
@@ -426,7 +440,8 @@ describe('IssuanceAllocator - Default Allocation', () => {
426440

427441
const expectedTarget1 = (issuancePerBlock * 200_000n * 2n) / MILLION
428442
const expectedTarget2 = (issuancePerBlock * 300_000n) / MILLION
429-
const expectedTarget3 = issuancePerBlock * 2n + (issuancePerBlock * 800_000n) / MILLION + (issuancePerBlock * 500_000n) / MILLION
443+
const expectedTarget3 =
444+
issuancePerBlock * 2n + (issuancePerBlock * 800_000n) / MILLION + (issuancePerBlock * 500_000n) / MILLION
430445

431446
expect(target1Balance).to.equal(expectedTarget1)
432447
expect(target2Balance).to.equal(expectedTarget2)
@@ -519,5 +534,21 @@ describe('IssuanceAllocator - Default Allocation', () => {
519534
expect(data.allocatorMintingPPM).to.equal(600_000n)
520535
expect(data.selfMintingPPM).to.equal(0n)
521536
})
537+
538+
it('should report 100% total allocation when default is a real address', async () => {
539+
// Set target1 allocation first
540+
await issuanceAllocator
541+
.connect(accounts.governor)
542+
['setTargetAllocation(address,uint256)'](addresses.target1, 300_000n)
543+
544+
// Change default to target2 (a real address, not address(0))
545+
await issuanceAllocator.connect(accounts.governor).setDefaultAllocationAddress(addresses.target2)
546+
547+
// When default is a real address, it should report 100% total allocation
548+
const totalAllocation = await issuanceAllocator.getTotalAllocation()
549+
expect(totalAllocation.totalAllocationPPM).to.equal(MILLION)
550+
expect(totalAllocation.allocatorMintingPPM).to.equal(MILLION) // target1=30% + target2=70% = 100%
551+
expect(totalAllocation.selfMintingPPM).to.equal(0n)
552+
})
522553
})
523554
})

0 commit comments

Comments
 (0)