Skip to content

Commit ced07b3

Browse files
committed
Refactor UFragmentsPolicy tests to separate positive and negative growth functions
1 parent 8305b09 commit ced07b3

File tree

1 file changed

+161
-84
lines changed

1 file changed

+161
-84
lines changed

test/unit/UFragmentsPolicy.ts

Lines changed: 161 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,32 @@ describe('UFragmentsPolicy:CurveParameters', async function () {
396396
} = await waffle.loadFixture(mockedUpgradablePolicy))
397397
})
398398

399-
describe('when rebaseFunctionGrowth is more than 0', async function () {
399+
describe('when rebaseFunctionRebasePositiveGrowth is more than 0', async function () {
400400
it('should setRebaseFunctionGrowth', async function () {
401-
await uFragmentsPolicy.connect(deployer).setRebaseFunctionGrowth('42000000000000000000')
402-
expect(await uFragmentsPolicy.rebaseFunctionGrowth()).to.eq('42000000000000000000')
401+
await uFragmentsPolicy.connect(deployer).setRebaseFunctionPositiveGrowth('42000000000000000000')
402+
expect(await uFragmentsPolicy.rebaseFunctionPositiveGrowth()).to.eq('42000000000000000000')
403403
})
404404
})
405405

406-
describe('when rebaseFunctionGrowth is less than 0', async function () {
406+
describe('when rebaseFunctionRebasePositiveGrowth is less than 0', async function () {
407407
it('should fail', async function () {
408408
await expect(
409-
uFragmentsPolicy.connect(deployer).setRebaseFunctionGrowth(-1),
409+
uFragmentsPolicy.connect(deployer).setRebaseFunctionPositiveGrowth(-1),
410+
).to.be.reverted
411+
})
412+
})
413+
414+
describe('when rebaseFunctionRebaseNegativeGrowth is more than 0', async function () {
415+
it('should setRebaseFunctionGrowth', async function () {
416+
await uFragmentsPolicy.connect(deployer).setRebaseFunctionNegativeGrowth('42000000000000000000')
417+
expect(await uFragmentsPolicy.rebaseFunctionNegativeGrowth()).to.eq('42000000000000000000')
418+
})
419+
})
420+
421+
describe('when rebaseFunctionRebaseNegativeGrowth is less than 0', async function () {
422+
it('should fail', async function () {
423+
await expect(
424+
uFragmentsPolicy.connect(deployer).setRebaseFunctionNegativeGrowth(-1),
410425
).to.be.reverted
411426
})
412427
})
@@ -448,82 +463,6 @@ describe('UFragmentsPolicy:CurveParameters', async function () {
448463
})
449464
})
450465

451-
describe('UFragments:setRebaseFunctionGrowth:accessControl', function () {
452-
before('setup UFragmentsPolicy contract', async () => {
453-
;({
454-
deployer,
455-
user,
456-
orchestrator,
457-
mockUFragments,
458-
mockMarketOracle,
459-
mockCpiOracle,
460-
uFragmentsPolicy,
461-
} = await waffle.loadFixture(mockedUpgradablePolicy))
462-
})
463-
464-
it('should be callable by owner', async function () {
465-
await expect(uFragmentsPolicy.connect(deployer).setRebaseFunctionGrowth(1))
466-
.to.not.be.reverted
467-
})
468-
469-
it('should NOT be callable by non-owner', async function () {
470-
await expect(uFragmentsPolicy.connect(user).setRebaseFunctionGrowth(1)).to
471-
.be.reverted
472-
})
473-
})
474-
475-
describe('UFragments:setRebaseFunctionLowerPercentage:accessControl', function () {
476-
before('setup UFragmentsPolicy contract', async () => {
477-
;({
478-
deployer,
479-
user,
480-
orchestrator,
481-
mockUFragments,
482-
mockMarketOracle,
483-
mockCpiOracle,
484-
uFragmentsPolicy,
485-
} = await waffle.loadFixture(mockedUpgradablePolicy))
486-
})
487-
488-
it('should be callable by owner', async function () {
489-
await expect(
490-
uFragmentsPolicy.connect(deployer).setRebaseFunctionLowerPercentage(-1),
491-
).to.not.be.reverted
492-
})
493-
494-
it('should NOT be callable by non-owner', async function () {
495-
await expect(
496-
uFragmentsPolicy.connect(user).setRebaseFunctionLowerPercentage(-1),
497-
).to.be.reverted
498-
})
499-
})
500-
501-
describe('UFragments:setRebaseFunctionUpperPercentage:accessControl', function () {
502-
before('setup UFragmentsPolicy contract', async () => {
503-
;({
504-
deployer,
505-
user,
506-
orchestrator,
507-
mockUFragments,
508-
mockMarketOracle,
509-
mockCpiOracle,
510-
uFragmentsPolicy,
511-
} = await waffle.loadFixture(mockedUpgradablePolicy))
512-
})
513-
514-
it('should be callable by owner', async function () {
515-
await expect(
516-
uFragmentsPolicy.connect(deployer).setRebaseFunctionUpperPercentage(1),
517-
).to.not.be.reverted
518-
})
519-
520-
it('should NOT be callable by non-owner', async function () {
521-
await expect(
522-
uFragmentsPolicy.connect(user).setRebaseFunctionUpperPercentage(1),
523-
).to.be.reverted
524-
})
525-
})
526-
527466
describe('UFragmentsPolicy:setRebaseTimingParameters', async function () {
528467
before('setup UFragmentsPolicy contract', async function () {
529468
;({
@@ -1053,7 +992,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
1053992
await mockExternalData(INITIAL_RATE_2X, INITIAL_TARGET_RATE, 1000)
1054993
await uFragmentsPolicy
1055994
.connect(deployer)
1056-
.setRebaseFunctionGrowth('100' + '000000000000000000')
995+
.setRebaseFunctionPositiveGrowth('100' + '000000000000000000')
1057996
await increaseTime(60)
1058997
})
1059998

@@ -1073,7 +1012,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
10731012
await mockExternalData(0, INITIAL_TARGET_RATE, 1000)
10741013
await uFragmentsPolicy
10751014
.connect(deployer)
1076-
.setRebaseFunctionGrowth('75' + '000000000000000000')
1015+
.setRebaseFunctionNegativeGrowth('75' + '000000000000000000')
10771016
await increaseTime(60)
10781017
})
10791018

@@ -1088,12 +1027,54 @@ describe('UFragmentsPolicy:Rebase', async function () {
10881027
})
10891028
})
10901029

1030+
describe('when normalizedRate is greater than ONE (positive rebase)', function () {
1031+
beforeEach(async function () {
1032+
await mockExternalData(
1033+
INITIAL_RATE_30P_MORE,
1034+
INITIAL_TARGET_RATE,
1035+
1000,
1036+
)
1037+
await uFragmentsPolicy
1038+
.connect(deployer)
1039+
.setRebaseFunctionPositiveGrowth('50' + '000000000000000000') // Positive growth
1040+
await increaseTime(60)
1041+
})
1042+
1043+
it('should compute positive rebase percentage correctly', async function () {
1044+
const rebaseEvent = await parseRebaseEvent(
1045+
uFragmentsPolicy.connect(orchestrator).rebase(),
1046+
)
1047+
expect(rebaseEvent.requestedSupplyAdjustment).to.eq(0)
1048+
})
1049+
})
1050+
1051+
describe('when normalizedRate is less than ONE (negative rebase)', function () {
1052+
beforeEach(async function () {
1053+
await mockExternalData(
1054+
INITIAL_RATE_30P_LESS,
1055+
INITIAL_TARGET_RATE,
1056+
1000,
1057+
)
1058+
await uFragmentsPolicy
1059+
.connect(deployer)
1060+
.setRebaseFunctionNegativeGrowth('30' + '000000000000000000') // Negative growth
1061+
await increaseTime(60)
1062+
})
1063+
1064+
it('should compute negative rebase percentage correctly', async function () {
1065+
const rebaseEvent = await parseRebaseEvent(
1066+
uFragmentsPolicy.connect(orchestrator).rebase(),
1067+
)
1068+
expect(rebaseEvent.requestedSupplyAdjustment).to.eq(0)
1069+
})
1070+
})
1071+
10911072
describe('exponent less than -100', function () {
10921073
before(async function () {
10931074
await mockExternalData(0, INITIAL_TARGET_RATE, 1000)
10941075
await uFragmentsPolicy
10951076
.connect(deployer)
1096-
.setRebaseFunctionGrowth('150' + '000000000000000000')
1077+
.setRebaseFunctionNegativeGrowth('150' + '000000000000000000')
10971078
await increaseTime(60)
10981079
})
10991080

@@ -1328,3 +1309,99 @@ describe('UFragmentsPolicy:Rebase', async function () {
13281309
})
13291310
})
13301311
})
1312+
1313+
describe('UFragmentsPolicy:CurveParameters', async function () {
1314+
before('setup UFragmentsPolicy contract', async function () {
1315+
;({
1316+
deployer,
1317+
user,
1318+
orchestrator,
1319+
mockUFragments,
1320+
mockMarketOracle,
1321+
mockCpiOracle,
1322+
uFragmentsPolicy,
1323+
} = await waffle.loadFixture(mockedUpgradablePolicy))
1324+
})
1325+
1326+
describe('when rebaseFunctionPositiveGrowth is more than 0', async function () {
1327+
it('should setRebaseFunctionPositiveGrowth', async function () {
1328+
await uFragmentsPolicy.connect(deployer).setRebaseFunctionPositiveGrowth('42000000000000000000')
1329+
expect(await uFragmentsPolicy.rebaseFunctionPositiveGrowth()).to.eq('42000000000000000000')
1330+
})
1331+
})
1332+
1333+
describe('when rebaseFunctionNegativeGrowth is more than 0', async function () {
1334+
it('should setRebaseFunctionNegativeGrowth', async function () {
1335+
await uFragmentsPolicy.connect(deployer).setRebaseFunctionNegativeGrowth('42000000000000000000')
1336+
expect(await uFragmentsPolicy.rebaseFunctionNegativeGrowth()).to.eq('42000000000000000000')
1337+
})
1338+
})
1339+
1340+
describe('when rebaseFunctionPositiveGrowth is less than 0', async function () {
1341+
it('should fail', async function () {
1342+
await expect(
1343+
uFragmentsPolicy.connect(deployer).setRebaseFunctionPositiveGrowth(-1),
1344+
).to.be.reverted
1345+
})
1346+
})
1347+
1348+
describe('when rebaseFunctionNegativeGrowth is less than 0', async function () {
1349+
it('should fail', async function () {
1350+
await expect(
1351+
uFragmentsPolicy.connect(deployer).setRebaseFunctionNegativeGrowth(-1),
1352+
).to.be.reverted
1353+
})
1354+
})
1355+
})
1356+
1357+
describe('UFragments:setRebaseFunctionPositiveGrowth:accessControl', function () {
1358+
before('setup UFragmentsPolicy contract', async () => {
1359+
;({
1360+
deployer,
1361+
user,
1362+
orchestrator,
1363+
mockUFragments,
1364+
mockMarketOracle,
1365+
mockCpiOracle,
1366+
uFragmentsPolicy,
1367+
} = await waffle.loadFixture(mockedUpgradablePolicy))
1368+
})
1369+
1370+
it('should be callable by owner', async function () {
1371+
await expect(
1372+
uFragmentsPolicy.connect(deployer).setRebaseFunctionPositiveGrowth(1),
1373+
).to.not.be.reverted
1374+
})
1375+
1376+
it('should NOT be callable by non-owner', async function () {
1377+
await expect(
1378+
uFragmentsPolicy.connect(user).setRebaseFunctionPositiveGrowth(1),
1379+
).to.be.reverted
1380+
})
1381+
})
1382+
1383+
describe('UFragments:setRebaseFunctionNegativeGrowth:accessControl', function () {
1384+
before('setup UFragmentsPolicy contract', async () => {
1385+
;({
1386+
deployer,
1387+
user,
1388+
orchestrator,
1389+
mockUFragments,
1390+
mockMarketOracle,
1391+
mockCpiOracle,
1392+
uFragmentsPolicy,
1393+
} = await waffle.loadFixture(mockedUpgradablePolicy))
1394+
})
1395+
1396+
it('should be callable by owner', async function () {
1397+
await expect(
1398+
uFragmentsPolicy.connect(deployer).setRebaseFunctionNegativeGrowth(1),
1399+
).to.not.be.reverted
1400+
})
1401+
1402+
it('should NOT be callable by non-owner', async function () {
1403+
await expect(
1404+
uFragmentsPolicy.connect(user).setRebaseFunctionNegativeGrowth(1),
1405+
).to.be.reverted
1406+
})
1407+
})

0 commit comments

Comments
 (0)