Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test removing all deposits #1104

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ contract SiloGettersFacet is ReentrancyGuard {
return LibBytes.packAddressAndStem(token, stem);
}

/**
* @notice outputs the token and stem given a depositId.
*/
function getAddressAndStem(
uint256 depositId
) external pure returns (address token, int96 stem) {
return LibBytes.unpackAddressAndStem(depositId);
}

/**
* @notice returns the bean denominated value ("bdv") of a token amount.
*/
Expand Down
2 changes: 2 additions & 0 deletions protocol/contracts/interfaces/IMockFBeanstalk.sol
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ interface IMockFBeanstalk {

function getActiveFertilizer() external view returns (uint256);

function getAddressAndStem(uint256 depositId) external pure returns (address token, int96 stem);

function getAllBalance(address account, address token) external view returns (Balance memory b);

function getAllBalances(
Expand Down
61 changes: 60 additions & 1 deletion protocol/test/foundry/Migration/ReseedState.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ contract ReseedStateTest is TestHelper {
function setUp() public {
// parse accounts and populate the accounts.txt file
// the number of accounts to parse, for testing purposes
uint256 numAccounts = 10;
// the total number of accounts is 3665
uint256 numAccounts = 10000;
accountNumber = parseAccounts(numAccounts);
console.log("Number of accounts: ", accountNumber);
l2Beanstalk = IMockFBeanstalk(L2_BEANSTALK);
Expand Down Expand Up @@ -302,6 +303,7 @@ contract ReseedStateTest is TestHelper {
function test_AccountPlots() public {
// test the L2 Beanstalk
string memory account;
uint256 totalPlotsAmount;
// for every account
for (uint256 i = 0; i < accountNumber; i++) {
account = vm.readLine(ACCOUNTS_PATH);
Expand Down Expand Up @@ -331,13 +333,26 @@ contract ReseedStateTest is TestHelper {
// compare the plot amount and index
assertEq(accountPlotAmountJsonDecoded, plots[j].pods);
assertEq(plotindexesJsonDecoded[j], plots[j].index);
totalPlotsAmount += plots[j].pods;
}
}
console.log("total plots amount:", totalPlotsAmount);
}

//////////////////// Account Deposits ////////////////////

function test_AccountDeposits() public {
vm.pauseGasMetering();

uint256 totalStalkBefore = l2Beanstalk.totalStalk();
assertGt(totalStalkBefore, 0);

uint256 totalRootsBefore = l2Beanstalk.totalRoots();
assertGt(totalRootsBefore, 0);

// verify ratio is 1:1 on reseed
assertEq(totalStalkBefore * 1e12, totalRootsBefore);

address[] memory tokens = l2Beanstalk.getWhitelistedTokens();

// for every account
Expand Down Expand Up @@ -375,9 +390,53 @@ contract ReseedStateTest is TestHelper {
accountDepositsStorage[j].tokenDeposits[k].bdv,
accountDepositsJson[j].tokenDeposits[k].bdv
);

(address token, int96 stem) = l2Beanstalk.getAddressAndStem(
accountDepositsStorage[j].depositIds[k]
);

// withdraw deposit
vm.prank(account);
l2Beanstalk.withdrawDeposit(
accountDepositsStorage[j].token,
stem,
accountDepositsStorage[j].tokenDeposits[k].amount,
0
);
}
}
}

uint256 totalStalk = l2Beanstalk.totalStalk();
assertEq(totalStalk, 0);

uint256 totalRoots = l2Beanstalk.totalRoots();
assertEq(totalRoots, 0);

uint256 totalRainRoots = l2Beanstalk.totalRainRoots();
assertEq(totalRainRoots, 0);

uint256 getTotalBdv = l2Beanstalk.getTotalBdv();
assertEq(getTotalBdv, 0);

uint256[] memory depositedAmounts = l2Beanstalk.getTotalSiloDeposited();
for (uint256 i = 0; i < depositedAmounts.length; i++) {
assertEq(depositedAmounts[i], 0);
}

uint256[] memory depositedBdvs = l2Beanstalk.getTotalSiloDepositedBdv();
for (uint256 i = 0; i < depositedBdvs.length; i++) {
assertEq(depositedBdvs[i], 0);
}

// loop through whitelisted tokens
for (uint256 i = 0; i < tokens.length; i++) {
address token = whitelistedTokens[i];
uint256 totalDeposited = l2Beanstalk.getTotalDeposited(token);
assertEq(totalDeposited, 0);
uint256 totalDepositedBdv = l2Beanstalk.getTotalDepositedBdv(token);
assertEq(totalDepositedBdv, 0);
}
}

//////////////////// Fertilizer ////////////////////
Expand Down
Loading