From c1442435f8cb4cb10b2ec9d699b2662f079c7aa3 Mon Sep 17 00:00:00 2001 From: syntrust Date: Tue, 24 Sep 2024 19:00:23 +0800 Subject: [PATCH] test --- contracts/test/StorageContractTest.t.sol | 29 ++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/contracts/test/StorageContractTest.t.sol b/contracts/test/StorageContractTest.t.sol index a8d4bc5..4763a2d 100644 --- a/contracts/test/StorageContractTest.t.sol +++ b/contracts/test/StorageContractTest.t.sol @@ -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}(); @@ -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); @@ -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;