Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrust committed Sep 24, 2024
1 parent b1e2dfc commit 9bfb294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
20 changes: 7 additions & 13 deletions contracts/StorageContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,14 @@ abstract contract StorageContract is DecentralizedKV, ReentrancyGuardTransient {
reward = _paymentIn(STORAGE_COST * (kvEntryCount % (1 << SHARD_ENTRY_BITS)), info.lastMineTime, _minedTs);
// Additional prepaid for the last shard
if (prepaidLastMineTime < _minedTs) {
uint256 prepaidAmountCap =
STORAGE_COST * ((1 << SHARD_ENTRY_BITS) - kvEntryCount % (1 << SHARD_ENTRY_BITS));
if (prepaidAmountCap > prepaidAmount) {
if (prepaidLastMineTime < _minedTs) {
fullReward = _paymentIn(STORAGE_COST << SHARD_ENTRY_BITS, info.lastMineTime, _minedTs);
prepaidAmountIn = _paymentIn(prepaidAmount, prepaidLastMineTime, _minedTs);
if (prepaidAmountIn > fullReward - reward) {
prepaidAmountIn = fullReward - reward;
}
}
- _paymentIn(prepaidAmount, prepaidLastMineTime, _minedTs);
prepaidAmountCap = prepaidAmount;
uint256 fullReward = _paymentIn(STORAGE_COST << SHARD_ENTRY_BITS, info.lastMineTime, _minedTs);
uint256 prepaidAmountIn = _paymentIn(prepaidAmount, prepaidLastMineTime, _minedTs);
uint256 rewardCap = fullReward - reward;
if (prepaidAmountIn > rewardCap) {
prepaidAmountSaved = prepaidAmountIn - rewardCap;
prepaidAmountIn = rewardCap;
}
reward += _paymentIn(prepaidAmountCap, prepaidLastMineTime, _minedTs);
reward += prepaidAmountIn;
updatePrepaidTime = true;
}
}
Expand Down
20 changes: 9 additions & 11 deletions contracts/test/StorageContractTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,23 @@ contract StorageContractTest is Test {
uint256 valueToSent = 50000000;
uint256 withdrawAmount = 8000000;
uint256 mineTs = 10000;
uint40 kvEntryCount = 1;
uint256 shardEntry = 1 << (SHARD_SIZE_BITS - MAX_KV_SIZE);

address miner = vm.addr(2);
storageContract.sendValue{value: valueToSent}();
storageContract.setKvEntryCount(kvEntryCount);
uint256 reward = storageContract.paymentIn(STORAGE_COST * kvEntryCount, 0, mineTs);

// a little half
storageContract.setKvEntryCount(1);
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;
uint256 prepaidAmountCap = STORAGE_COST * (shardEntry - kvEntryCount);
uint256 prepaidAmountSaved = storageContract.paymentIn(prepaidAmountCap, 0, mineTs) - prepaidReward;

storageContract.rewardMiner(0, vm.addr(2), mineTs, 1);
uint256 totalPrepaid = valueToSent + treasureReward + prepaidAmountSaved;
assertEq(storageContract.accPrepaidAmount(), totalPrepaid);
assertEq(miner.balance, minerReward);
assertEq(storageContract.accPrepaidAmount(), valueToSent + treasureReward);

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

0 comments on commit 9bfb294

Please sign in to comment.