@@ -392,6 +392,132 @@ contract RecurringCollectorTest is Test, Bounder {
392
392
assertEq (collected, tokens);
393
393
}
394
394
395
+ function test_Upgrade_Revert_WhenUpgradeElapsed (
396
+ IRecurringCollector.RecurringCollectionAgreement memory rca ,
397
+ uint256 unboundedUpgradeSkip
398
+ ) public {
399
+ rca = _sensibleRCA (rca);
400
+ IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU (rca);
401
+
402
+ boundSkipCeil (unboundedUpgradeSkip, type (uint256 ).max);
403
+ rcau.upgradeDeadline = bound (rcau.upgradeDeadline, 0 , block .timestamp - 1 );
404
+ IRecurringCollector.SignedRCAU memory signedRCAU = IRecurringCollector.SignedRCAU ({
405
+ rcau: rcau,
406
+ signature: ""
407
+ });
408
+
409
+ bytes memory expectedErr = abi.encodeWithSelector (
410
+ IRecurringCollector.RecurringCollectorAgreementUpgradeElapsed.selector ,
411
+ rcau.upgradeDeadline
412
+ );
413
+ vm.expectRevert (expectedErr);
414
+ vm.prank (rca.dataService);
415
+ _recurringCollector.upgrade (signedRCAU);
416
+ }
417
+
418
+ function test_Upgrade_Revert_WhenNeverAccepted (IRecurringCollector.RecurringCollectionAgreement memory rca ) public {
419
+ rca = _sensibleRCA (rca);
420
+ IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU (rca);
421
+
422
+ rcau.upgradeDeadline = block .timestamp ;
423
+ IRecurringCollector.SignedRCAU memory signedRCAU = IRecurringCollector.SignedRCAU ({
424
+ rcau: rcau,
425
+ signature: ""
426
+ });
427
+
428
+ bytes memory expectedErr = abi.encodeWithSelector (
429
+ IRecurringCollector.RecurringCollectorAgreementNeverAccepted.selector ,
430
+ rcau.agreementId
431
+ );
432
+ vm.expectRevert (expectedErr);
433
+ vm.prank (rca.dataService);
434
+ _recurringCollector.upgrade (signedRCAU);
435
+ }
436
+
437
+ function test_Upgrade_Revert_WhenDataServiceNotAuthorized (
438
+ IRecurringCollector.RecurringCollectionAgreement memory rca ,
439
+ uint256 unboundedKey ,
440
+ uint256 unboundedUpgradeSkip ,
441
+ address notDataService
442
+ ) public {
443
+ vm.assume (rca.dataService != notDataService);
444
+ rca = _sensibleRCA (rca);
445
+ IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU (rca);
446
+ uint256 signerKey = boundKey (unboundedKey);
447
+ _authorizeAndAccept (rca, signerKey);
448
+
449
+ boundSkipCeil (unboundedUpgradeSkip, type (uint256 ).max);
450
+ rcau.upgradeDeadline = boundTimestampMin (rcau.upgradeDeadline, block .timestamp + 1 );
451
+ IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU (
452
+ rcau,
453
+ signerKey
454
+ );
455
+
456
+ bytes memory expectedErr = abi.encodeWithSelector (
457
+ IRecurringCollector.RecurringCollectorDataServiceNotAuthorized.selector ,
458
+ rcau.agreementId,
459
+ notDataService
460
+ );
461
+ vm.expectRevert (expectedErr);
462
+ vm.prank (notDataService);
463
+ _recurringCollector.upgrade (signedRCAU);
464
+ }
465
+
466
+ function test_Upgrade_Revert_WhenInvalidSigner (
467
+ IRecurringCollector.RecurringCollectionAgreement memory rca ,
468
+ uint256 unboundedKey ,
469
+ uint256 unboundedUpgradeSkip ,
470
+ uint256 unboundedInvalidSignerKey
471
+ ) public {
472
+ uint256 signerKey = boundKey (unboundedKey);
473
+ uint256 invalidSignerKey = boundKey (unboundedInvalidSignerKey);
474
+ vm.assume (signerKey != invalidSignerKey);
475
+
476
+ rca = _sensibleRCA (rca);
477
+ IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU (rca);
478
+ _authorizeAndAccept (rca, signerKey);
479
+
480
+ boundSkipCeil (unboundedUpgradeSkip, type (uint256 ).max);
481
+ rcau.upgradeDeadline = boundTimestampMin (rcau.upgradeDeadline, block .timestamp + 1 );
482
+
483
+ IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU (
484
+ rcau,
485
+ invalidSignerKey
486
+ );
487
+
488
+ vm.expectRevert (IRecurringCollector.RecurringCollectorInvalidSigner.selector );
489
+ vm.prank (rca.dataService);
490
+ _recurringCollector.upgrade (signedRCAU);
491
+ }
492
+
493
+ function test_Upgrade_OK (
494
+ IRecurringCollector.RecurringCollectionAgreement memory rca ,
495
+ uint256 unboundedKey ,
496
+ uint256 unboundedUpgradeSkip
497
+ ) public {
498
+ rca = _sensibleRCA (rca);
499
+ IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau = _sensibleRCAU (rca);
500
+ uint256 signerKey = boundKey (unboundedKey);
501
+ _authorizeAndAccept (rca, signerKey);
502
+
503
+ boundSkipCeil (unboundedUpgradeSkip, type (uint256 ).max);
504
+ rcau.upgradeDeadline = boundTimestampMin (rcau.upgradeDeadline, block .timestamp + 1 );
505
+ IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU (
506
+ rcau,
507
+ signerKey
508
+ );
509
+
510
+ vm.prank (rca.dataService);
511
+ _recurringCollector.upgrade (signedRCAU);
512
+
513
+ IRecurringCollector.AgreementData memory agreement = _recurringCollector.getAgreement (rca.agreementId);
514
+ assertEq (rcau.duration, agreement.duration);
515
+ assertEq (rcau.maxInitialTokens, agreement.maxInitialTokens);
516
+ assertEq (rcau.maxOngoingTokensPerSecond, agreement.maxOngoingTokensPerSecond);
517
+ assertEq (rcau.minSecondsPerCollection, agreement.minSecondsPerCollection);
518
+ assertEq (rcau.maxSecondsPerCollection, agreement.maxSecondsPerCollection);
519
+ }
520
+
395
521
/* solhint-enable graph/func-name-mixedcase */
396
522
397
523
function _authorizeAndAccept (
@@ -487,6 +613,22 @@ contract RecurringCollectorTest is Test, Bounder {
487
613
return _rca;
488
614
}
489
615
616
+ function _sensibleRCAU (
617
+ IRecurringCollector.RecurringCollectionAgreement memory _rca
618
+ ) private pure returns (IRecurringCollector.RecurringCollectionAgreementUpgrade memory ) {
619
+ IRecurringCollector.RecurringCollectionAgreementUpgrade memory rcau;
620
+ rcau.agreementId = _rca.agreementId;
621
+ rcau.minSecondsPerCollection = uint32 (bound (_rca.minSecondsPerCollection, 60 , 60 * 60 * 24 ));
622
+ rcau.maxSecondsPerCollection = uint32 (
623
+ bound (_rca.maxSecondsPerCollection, rcau.minSecondsPerCollection * 2 , 60 * 60 * 24 * 30 )
624
+ );
625
+ rcau.duration = bound (_rca.duration, rcau.maxSecondsPerCollection * 10 , type (uint256 ).max);
626
+ rcau.maxInitialTokens = bound (_rca.maxInitialTokens, 0 , 1e18 * 100_000_000 );
627
+ rcau.maxOngoingTokensPerSecond = bound (_rca.maxOngoingTokensPerSecond, 1 , 1e18 );
628
+
629
+ return rcau;
630
+ }
631
+
490
632
function _generateCollectParams (
491
633
IRecurringCollector.RecurringCollectionAgreement memory _rca ,
492
634
bytes32 _collectionId ,
0 commit comments