Skip to content

Commit

Permalink
chore: update naming, and expand redeemQueueMigration test
Browse files Browse the repository at this point in the history
  • Loading branch information
koderholic committed Sep 16, 2024
1 parent b9277f0 commit 2f3f41e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
16 changes: 8 additions & 8 deletions contracts/src/RedeemManager.1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ contract RedeemManagerV1 is Initializable, IRedeemManagerV1, IProtocolVersion {
}

function _redeemQueueMigrationV1_2(address[] memory _prevInitiators) internal {
RedeemQueueV1.RedeemRequest[] memory initialQueue = RedeemQueueV1.get();
uint256 currentQueueLen = initialQueue.length;
RedeemQueueV1.RedeemRequest[] memory oldQueue = RedeemQueueV1.get();
uint256 oldQueueLen = oldQueue.length;
RedeemQueueV2.RedeemRequest[] storage newQueue = RedeemQueueV2.get();

if (_prevInitiators.length != currentQueueLen) {
if (_prevInitiators.length != oldQueueLen) {
revert IncompatibleArrayLengths();
}
// Migrate from v1 to v2
for (uint256 i = 0; i < currentQueueLen;) {
for (uint256 i = 0; i < oldQueueLen;) {
newQueue[i] = RedeemQueueV2.RedeemRequest({
amount: initialQueue[i].amount,
maxRedeemableEth: initialQueue[i].maxRedeemableEth,
recipient: initialQueue[i].recipient,
height: initialQueue[i].height,
amount: oldQueue[i].amount,
maxRedeemableEth: oldQueue[i].maxRedeemableEth,
recipient: oldQueue[i].recipient,
height: oldQueue[i].height,
initiator: _prevInitiators[i] // Assign the provided initiators
});

Expand Down
2 changes: 1 addition & 1 deletion contracts/test/RedeemManager.1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ contract InitializeRedeemManagerV1_2Test is RedeeManagerV1TestBase {
vm.store(redeemManager, IMPLEMENTATION_SLOT, bytes32(uint256(uint160(address(redeemQueueImplV2)))));
RedeemManagerV1(redeemManager).initializeRedeemManagerV1_2(prevInitiators);

// Check all existing redeemRequests are intact after the migration (from initialQueue)
// Check all existing redeemRequests are intact after the migration (from oldQueue)
for (uint256 i = 0; i < 30; i++) {
RedeemQueueV2.RedeemRequest memory current =
RedeemManagerV1(redeemManager).getRedeemRequestDetails(uint32(i));
Expand Down
49 changes: 19 additions & 30 deletions contracts/test/fork/mainnet/4.redeemQueueMigrationV1_2_1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,23 @@ contract RedeemQueueMigrationV1_2 is Test {
}
}

function test_migrate_allRequestInOneCall() external shouldSkip {
// Setting up the Redeem Manager
function test_migrate_allRedeemRequestsInOneCall() external shouldSkip {
// Getting the RedeemManager proxy instance
TUPProxy redeemManagerProxy = TUPProxy(payable(REDEEM_MANAGER_MAINNET_ADDRESS));

// Getting RedeemManagerV1 instance before the upgrade
MockIRedeemManagerV1 RedeemManager = MockIRedeemManagerV1(REDEEM_MANAGER_MAINNET_ADDRESS);
// Getting all redeem request details, and count before the upgrade
uint256 oldCount = RedeemManager.getRedeemRequestCount();
RedeemQueueV1.RedeemRequest memory oldRequest0 = RedeemManager.getRedeemRequestDetails(0);
RedeemQueueV1.RedeemRequest memory oldRequest1 = RedeemManager.getRedeemRequestDetails(1);
RedeemQueueV1.RedeemRequest memory oldRequestN = RedeemManager.getRedeemRequestDetails(uint32(oldCount - 1));
RedeemQueueV1.RedeemRequest[33] memory oldRequests;
for (uint256 i = 0; i < 33; i++) {
oldRequests[i] = RedeemManager.getRedeemRequestDetails(uint32(i));
}

// Generating mock initiators
address[] memory mockInitiators = _generateRandomAddress(oldCount);

// Set up the fork at a new block for testing the upgrade
// Set up the fork at a new block for making the v1_2_1 upgrade, and testing
vm.createSelectFork(_rpcUrl, 20678000);
// Upgrade the RedeemManager
RedeemManagerV1 newImplementation = new RedeemManagerV1();
Expand All @@ -81,32 +85,17 @@ contract RedeemQueueMigrationV1_2 is Test {

// After upgrade: check that state before the upgrade, and state after upgrade are same.
RedeemManagerV1 RManager = RedeemManagerV1(REDEEM_MANAGER_MAINNET_ADDRESS);
uint256 newCount = RedeemManager.getRedeemRequestCount();
uint256 newCount = RManager.getRedeemRequestCount();
assertEq(newCount, oldCount);

{
RedeemQueueV2.RedeemRequest memory newRequest = RManager.getRedeemRequestDetails(0);
assertEq(newRequest.amount, oldRequest0.amount);
assertEq(newRequest.maxRedeemableEth, oldRequest0.maxRedeemableEth);
assertEq(newRequest.recipient, oldRequest0.recipient);
assertEq(newRequest.height, oldRequest0.height);
assertEq(newRequest.initiator, mockInitiators[0]);
}
{
RedeemQueueV2.RedeemRequest memory newRequest = RManager.getRedeemRequestDetails(1);
assertEq(newRequest.amount, oldRequest1.amount);
assertEq(newRequest.maxRedeemableEth, oldRequest1.maxRedeemableEth);
assertEq(newRequest.recipient, oldRequest1.recipient);
assertEq(newRequest.height, oldRequest1.height);
assertEq(newRequest.initiator, mockInitiators[1]);
}
{
RedeemQueueV2.RedeemRequest memory newRequest = RManager.getRedeemRequestDetails(uint32(newCount - 1));
assertEq(newRequest.amount, oldRequestN.amount);
assertEq(newRequest.maxRedeemableEth, oldRequestN.maxRedeemableEth);
assertEq(newRequest.recipient, oldRequestN.recipient);
assertEq(newRequest.height, oldRequestN.height);
assertEq(newRequest.initiator, mockInitiators[newCount - 1]);
for (uint32 i = 0; i < newCount; i++) {
RedeemQueueV2.RedeemRequest memory newRequest = RManager.getRedeemRequestDetails(i);

assertEq(newRequest.amount, oldRequests[i].amount);
assertEq(newRequest.maxRedeemableEth, oldRequests[i].maxRedeemableEth);
assertEq(newRequest.recipient, oldRequests[i].recipient);
assertEq(newRequest.height, oldRequests[i].height);
assertEq(newRequest.initiator, mockInitiators[i]);
}
}
}

0 comments on commit 2f3f41e

Please sign in to comment.