Skip to content

Commit

Permalink
chore(Vault): test withdrawUntrackedERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
0xb337r007 committed Mar 11, 2024
1 parent b75bae2 commit 4f30241
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ AddEntryTest:test_RevertWhen_InvalidAddress() (gas: 25133)
AddEntryTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 14827)
CommunityERC20Test:test_Deployment() (gas: 35198)
CommunityTokenDeployerTest:test_Deployment() (gas: 14805)
CommunityVaulWithdrawUntrackedERC721Test:testRevertWithdrawalIfTokenIsTracked() (gas: 37990)
CommunityVaulWithdrawUntrackedERC721Test:testSuccessfulDepositERC721() (gas: 73349)
CommunityVaulWithdrawUntrackedERC721Test:test_Deployment() (gas: 10783)
CommunityVaultBaseERC20Test:test_Deployment() (gas: 10641)
CommunityVaultBaseERC721Test:test_Deployment() (gas: 10641)
CommunityVaultBaseTransferERC721Test:test_Deployment() (gas: 10641)
CommunityVaultDepositERC721Test:testSuccessfulDepositERC721() (gas: 184942)
CommunityVaultDepositERC721Test:test_Deployment() (gas: 10783)
CommunityVaultTest:test_Deployment() (gas: 10641)
CommunityVaultWithdrawUntrackedERC20Test:testRevertWithdrawalIfAmountIsMoreThanTheUntracked() (gas: 30810)
CommunityVaultWithdrawUntrackedERC20Test:testSuccessfulWithdrawal() (gas: 64806)
CommunityVaultWithdrawUntrackedERC20Test:test_Deployment() (gas: 10761)
CommunityVaultWithdrawUntrackedERC721Test:testRevertWithdrawalIfTokenIsTracked() (gas: 37990)
CommunityVaultWithdrawUntrackedERC721Test:testSuccessfulWithdrUntrackedERC721() (gas: 73328)
CommunityVaultWithdrawUntrackedERC721Test:test_Deployment() (gas: 10783)
CreateTest:test_Create() (gas: 2374801)
CreateTest:test_Create() (gas: 2661968)
CreateTest:test_RevertWhen_InvalidOwnerTokenAddress() (gas: 15523)
Expand Down
40 changes: 37 additions & 3 deletions test/CommunityVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ contract TransferERC20ByNonAdminTest is CommunityVaultBaseERC20Test {
}

contract TransferERC20ByAdminTest is CommunityVaultBaseERC20Test {
uint256 depositAmount = 10e18;
uint256 private depositAmount = 10e18;

function setUp() public virtual override {
CommunityVaultBaseERC20Test.setUp();
Expand Down Expand Up @@ -164,6 +164,40 @@ contract DepositERC20Test is CommunityVaultBaseERC20Test {
}
}

contract CommunityVaultWithdrawUntrackedERC20Test is CommunityVaultBaseERC20Test {
function setUp() public virtual override {
CommunityVaultBaseERC20Test.setUp();
assertEq(erc20Token.balanceOf(accounts[0]), 10e18);

vm.startPrank(accounts[0]);

// deposit 2 tokens
erc20Token.approve(address(vault), 2e18);
vault.depositERC20(address(erc20Token), 2e18);

// trasfer 8 tokens
erc20Token.transfer(address(vault), 8e18);
vm.stopPrank();
}

function testRevertWithdrawalIfAmountIsMoreThanTheUntracked() public {
vm.prank(deployer);
vm.expectRevert(CommunityVault.CommunityVault_AmountExceedsUntrackedBalanceERC20.selector);
vault.withdrawUntrackedERC20(address(erc20Token), 9e18, accounts[0]);
}

function testSuccessfulWithdrawal() public {
assertEq(erc20Token.balanceOf(accounts[0]), 0e18);
assertEq(erc20Token.balanceOf(address(vault)), 10e18);

vm.prank(deployer);
vault.withdrawUntrackedERC20(address(erc20Token), 8e18, accounts[0]);

assertEq(erc20Token.balanceOf(accounts[0]), 8e18);
assertEq(erc20Token.balanceOf(address(vault)), 2e18);
}
}

contract CommunityVaultBaseERC721Test is CommunityVaultTest {
function setUp() public virtual override {
CommunityVaultTest.setUp();
Expand Down Expand Up @@ -304,7 +338,7 @@ contract CommunityVaultDepositERC721Test is CommunityVaultBaseERC721Test {
}
}

contract CommunityVaulWithdrawUntrackedERC721Test is CommunityVaultBaseERC721Test {
contract CommunityVaultWithdrawUntrackedERC721Test is CommunityVaultBaseERC721Test {
function setUp() public virtual override {
CommunityVaultBaseERC721Test.setUp();
vm.startPrank(accounts[0]);
Expand Down Expand Up @@ -332,7 +366,7 @@ contract CommunityVaulWithdrawUntrackedERC721Test is CommunityVaultBaseERC721Tes
vault.withdrawUntrackedERC721(address(erc721Token), ids, accounts[0]);
}

function testSuccessfulDepositERC721() public {
function testSuccessfulWithdrUntrackedERC721() public {
uint256[] memory ids = new uint256[](2);
ids[0] = 0;
ids[1] = 1;
Expand Down

0 comments on commit 4f30241

Please sign in to comment.