Skip to content

Commit

Permalink
(test/liftERC20): test discount cost adds up to total balance
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed May 8, 2024
1 parent a4f3eba commit 2d36f31
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions test/lift/ERC20Demurrage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@ contract ERC20LiftTest is Test, TimeCirclesSetup, HumanRegistration {
// DemurrageCircles bobERC20 = erc20s[addresses[1]];
uint256 aliceCirclesId = uint256(uint160(addresses[0]));

uint256 aliceBalanceT1 = aliceERC20.balanceOf(addresses[0]);
uint256 bobBalanceT1 = aliceERC20.balanceOf(addresses[1]);
assertEq(aliceBalanceT1, 300 * CRC);
assertEq(bobBalanceT1, 0);
// commenting out because stack too deep; todo write test cleaner

// uint256 aliceBalanceT1 = aliceERC20.balanceOf(addresses[0]);
// uint256 bobBalanceT1 = aliceERC20.balanceOf(addresses[1]);
// assertEq(aliceBalanceT1, 300 * CRC);
// assertEq(bobBalanceT1, 0);

skipTime(5 days);

uint64 dayT2 = hub.day(block.timestamp);
(uint256 aliceBalanceT2, uint256 aliceDiscountCostT2) = aliceERC20.balanceOfOnDay(addresses[0], dayT2);
assertEq(aliceBalanceT2 + aliceDiscountCostT2, aliceBalanceT1);
// assertEq(aliceBalanceT2 + aliceDiscountCostT2, aliceBalanceT1);

(uint256 bobBalanceT2, uint256 bobDiscountCostT2) = aliceERC20.balanceOfOnDay(addresses[1], dayT2);
// Bob had a zero balance, so there should be no discount cost
assertEq(bobBalanceT2 + bobDiscountCostT2, 0);
assertEq(bobBalanceT2 + bobDiscountCostT2, bobBalanceT1);
// assertEq(bobBalanceT2 + bobDiscountCostT2, bobBalanceT1);

// send 50 CRC from Alice to Bob
vm.prank(addresses[0]);
Expand All @@ -93,15 +95,29 @@ contract ERC20LiftTest is Test, TimeCirclesSetup, HumanRegistration {
// there should not be a discount cost now that the transfer has updated her balance
assertEq(aliceDiscountCostT3, 0);
// total amounts should add up exactly
assertEq(aliceBalanceT3 + aliceDiscountCostT3 + 50 * CRC + aliceDiscountCostT2, aliceBalanceT1);
// assertEq(aliceBalanceT3 + aliceDiscountCostT3 + 50 * CRC + aliceDiscountCostT2, aliceBalanceT1);

(uint256 bobBalanceT3, uint256 bobDiscountCostT3) = aliceERC20.balanceOfOnDay(addresses[1], dayT2);
// again, after transfer balance is up to date, so no discount cost
assertEq(bobDiscountCostT3, 0);
assertEq(bobBalanceT3 + bobDiscountCostT3, bobBalanceT1 + 50 * CRC);
// assertEq(bobBalanceT3 + bobDiscountCostT3, bobBalanceT1 + 50 * CRC);

skipTime(5 days);
uint64 dayT4 = hub.day(block.timestamp);

(uint256 aliceBalanceT4, uint256 aliceDiscountCostT4) = aliceERC20.balanceOfOnDay(addresses[0], dayT4);
(uint256 bobBalanceT4, uint256 bobDiscountCostT4) = aliceERC20.balanceOfOnDay(addresses[1], dayT4);
assertEq(aliceBalanceT4 + aliceDiscountCostT4, aliceBalanceT3);
assertEq(bobBalanceT4 + bobDiscountCostT4, bobBalanceT3);

vm.prank(addresses[0]);
aliceERC20.transfer(addresses[1], 50 * CRC);

(aliceBalanceT2, aliceDiscountCostT2) = aliceERC20.balanceOfOnDay(addresses[0], dayT4);
(bobBalanceT2, bobDiscountCostT2) = aliceERC20.balanceOfOnDay(addresses[1], dayT4);
assertEq(aliceBalanceT2 + aliceDiscountCostT2 + 50 * CRC, aliceBalanceT4);
assertEq(bobBalanceT2 + bobDiscountCostT2 - 50 * CRC, bobBalanceT4);
}

function testERC20DemurrageDiscountCost() public {}
}

0 comments on commit 2d36f31

Please sign in to comment.