@@ -567,22 +567,23 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
567
567
} ) ;
568
568
569
569
contract ( 'UFragmentsPolicy:Rebase' , async function ( accounts ) {
570
- let rbTime , rbWindow , minRebaseTimeIntervalSec , now , prevRebaseTime , nextRebaseTime ,
571
- timeToWait ;
570
+ let rbTime , rbWindow , minRebaseTimeIntervalSec , now , prevRebaseTime , nextRebaseWindowOpenTime ,
571
+ timeToWait , lastRebaseTimestamp ;
572
572
573
573
beforeEach ( 'setup UFragmentsPolicy contract' , async function ( ) {
574
574
await setupContracts ( ) ;
575
+ await uFragmentsPolicy . setRebaseTimingParameters ( 86400 , 72000 , 900 ) ;
575
576
rbTime = await uFragmentsPolicy . rebaseWindowOffsetSec . call ( ) ;
576
577
rbWindow = await uFragmentsPolicy . rebaseWindowLengthSec . call ( ) ;
577
578
minRebaseTimeIntervalSec = await uFragmentsPolicy . minRebaseTimeIntervalSec . call ( ) ;
578
579
now = new BigNumber ( await chain . currentTime ( ) ) ;
579
580
prevRebaseTime = now . minus ( now . mod ( minRebaseTimeIntervalSec ) ) . plus ( rbTime ) ;
580
- nextRebaseTime = prevRebaseTime . plus ( minRebaseTimeIntervalSec ) ;
581
+ nextRebaseWindowOpenTime = prevRebaseTime . plus ( minRebaseTimeIntervalSec ) ;
581
582
} ) ;
582
583
583
584
describe ( 'when its 5s after the rebase window closes' , function ( ) {
584
585
it ( 'should fail' , async function ( ) {
585
- timeToWait = nextRebaseTime . minus ( now ) . plus ( rbWindow ) . plus ( 5 ) ;
586
+ timeToWait = nextRebaseWindowOpenTime . minus ( now ) . plus ( rbWindow ) . plus ( 5 ) ;
586
587
await chain . waitForSomeTime ( timeToWait . toNumber ( ) ) ;
587
588
await mockExternalData ( INITIAL_RATE , INITIAL_CPI , 1000 ) ;
588
589
expect ( await uFragmentsPolicy . inRebaseWindow . call ( ) ) . to . be . false ;
@@ -594,7 +595,7 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
594
595
595
596
describe ( 'when its 5s before the rebase window opens' , function ( ) {
596
597
it ( 'should fail' , async function ( ) {
597
- timeToWait = nextRebaseTime . minus ( now ) . minus ( 5 ) ;
598
+ timeToWait = nextRebaseWindowOpenTime . minus ( now ) . minus ( 5 ) ;
598
599
await chain . waitForSomeTime ( timeToWait . toNumber ( ) ) ;
599
600
await mockExternalData ( INITIAL_RATE , INITIAL_CPI , 1000 ) ;
600
601
expect ( await uFragmentsPolicy . inRebaseWindow . call ( ) ) . to . be . false ;
@@ -606,25 +607,29 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
606
607
607
608
describe ( 'when its 5s after the rebase window opens' , function ( ) {
608
609
it ( 'should NOT fail' , async function ( ) {
609
- timeToWait = nextRebaseTime . minus ( now ) . plus ( 5 ) ;
610
+ timeToWait = nextRebaseWindowOpenTime . minus ( now ) . plus ( 5 ) ;
610
611
await chain . waitForSomeTime ( timeToWait . toNumber ( ) ) ;
611
612
await mockExternalData ( INITIAL_RATE , INITIAL_CPI , 1000 ) ;
612
613
expect ( await uFragmentsPolicy . inRebaseWindow . call ( ) ) . to . be . true ;
613
614
expect (
614
615
await chain . isEthException ( uFragmentsPolicy . rebase ( ) )
615
616
) . to . be . false ;
617
+ lastRebaseTimestamp = await uFragmentsPolicy . lastRebaseTimestampSec . call ( ) ;
618
+ expect ( lastRebaseTimestamp . eq ( nextRebaseWindowOpenTime ) ) . to . be . true ;
616
619
} ) ;
617
620
} ) ;
618
621
619
622
describe ( 'when its 5s before the rebase window closes' , function ( ) {
620
623
it ( 'should NOT fail' , async function ( ) {
621
- timeToWait = nextRebaseTime . minus ( now ) . plus ( rbWindow ) . minus ( 5 ) ;
624
+ timeToWait = nextRebaseWindowOpenTime . minus ( now ) . plus ( rbWindow ) . minus ( 5 ) ;
622
625
await chain . waitForSomeTime ( timeToWait . toNumber ( ) ) ;
623
626
await mockExternalData ( INITIAL_RATE , INITIAL_CPI , 1000 ) ;
624
627
expect ( await uFragmentsPolicy . inRebaseWindow . call ( ) ) . to . be . true ;
625
628
expect (
626
629
await chain . isEthException ( uFragmentsPolicy . rebase ( ) )
627
630
) . to . be . false ;
631
+ lastRebaseTimestamp = await uFragmentsPolicy . lastRebaseTimestampSec . call ( ) ;
632
+ expect ( lastRebaseTimestamp . eq ( nextRebaseWindowOpenTime ) ) . to . be . true ;
628
633
} ) ;
629
634
} ) ;
630
635
} ) ;
0 commit comments