Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrust committed Sep 24, 2024
1 parent 9bfb294 commit c144243
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions contracts/test/StorageContractTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ contract StorageContractTest is Test {
uint256 valueToSent = 50000000;
uint256 withdrawAmount = 8000000;
uint256 mineTs = 10000;
uint256 shardEntry = 1 << (SHARD_SIZE_BITS - MAX_KV_SIZE);
address miner = vm.addr(2);
storageContract.sendValue{value: valueToSent}();

Expand All @@ -74,9 +73,10 @@ contract StorageContractTest is Test {
uint256 reward = storageContract.paymentIn(STORAGE_COST, 0, mineTs);
uint256 prepaidReward = storageContract.paymentIn(PREPAID_AMOUNT, 0, mineTs);
reward += prepaidReward;
storageContract.rewardMiner(0, miner, mineTs, 1);
uint256 treasureReward = (reward * storageContract.treasuryShare()) / 10000;
uint256 minerReward = reward - treasureReward;

storageContract.rewardMiner(0, miner, mineTs, 1);
assertEq(miner.balance, minerReward);
assertEq(storageContract.accPrepaidAmount(), valueToSent + treasureReward);

Expand All @@ -86,6 +86,31 @@ contract StorageContractTest is Test {
assertEq(address(storageContract).balance, valueToSent - minerReward - withdrawAmount);
}

function testWithdrawRewardMinerSaved() public {
uint256 valueToSent = 50000000;
uint256 withdrawAmount = 8000000;
uint256 mineTs = 10000;
address miner = vm.addr(2);
storageContract.sendValue{value: valueToSent}();

// more than half
storageContract.setKvEntryCount(3);
uint256 rewardFull = storageContract.paymentIn(STORAGE_COST << (SHARD_SIZE_BITS - MAX_KV_SIZE), 0, mineTs);
(, uint256 saved,, uint256 reward) = storageContract.miningRewards(0, mineTs);
assertEq(rewardFull, reward);
uint256 treasureReward = (reward * storageContract.treasuryShare()) / 10000;
uint256 minerReward = reward - treasureReward;

storageContract.rewardMiner(0, miner, mineTs, 1);
assertEq(miner.balance, minerReward);
assertEq(storageContract.accPrepaidAmount(), valueToSent + treasureReward + saved);

storageContract.withdraw(withdrawAmount);
assertEq(storageContract.accPrepaidAmount(), valueToSent + treasureReward + saved - withdrawAmount);
assertEq(storageContract.treasury().balance, withdrawAmount);
assertEq(address(storageContract).balance, valueToSent - minerReward - withdrawAmount);
}

function testRewardMiner() public {
address miner = vm.addr(2);
uint256 mineTs = 10000;
Expand Down

0 comments on commit c144243

Please sign in to comment.