-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.19; | ||
|
||
import "./TestStorageContract.sol"; | ||
import "../StorageContract.sol"; | ||
import "forge-std/Test.sol"; | ||
import "forge-std/Vm.sol"; | ||
|
||
contract StorageContractTest is Test { | ||
uint256 constant STORAGE_COST = 1000; | ||
uint256 constant SHARD_SIZE_BITS = 19; | ||
uint256 constant MAX_KV_SIZE = 17; | ||
uint256 constant PREPAID_AMOUNT = 2 * STORAGE_COST; | ||
TestStorageContract storageContract; | ||
|
||
function setUp() public { | ||
storageContract = new TestStorageContract( | ||
StorageContract.Config(MAX_KV_SIZE, SHARD_SIZE_BITS, 2, 0, 0, 0), 0, STORAGE_COST, 0 | ||
); | ||
storageContract.initialize(0, PREPAID_AMOUNT, 0, address(0x1), address(0x1)); | ||
} | ||
|
||
function testMiningReward() public { | ||
// no key-value stored on EthStorage, only use prepaid amount as the reward | ||
(,, uint256 reward) = storageContract.miningRewards(0, 1); | ||
assertEq(reward, storageContract.paymentIn(PREPAID_AMOUNT, 0, 1)); | ||
|
||
// 1 key-value stored on EthStorage | ||
storageContract.setKvEntryCount(1); | ||
(,, reward) = storageContract.miningRewards(0, 1); | ||
assertEq(reward, storageContract.paymentIn(PREPAID_AMOUNT + STORAGE_COST * 1, 0, 1)); | ||
|
||
// 2 key-value stored on EthStorage | ||
storageContract.setKvEntryCount(2); | ||
(,, reward) = storageContract.miningRewards(0, 1); | ||
assertEq(reward, storageContract.paymentIn(PREPAID_AMOUNT + STORAGE_COST * 2, 0, 1)); | ||
|
||
// 3 key-value stored on EthStorage, but the reward is capped with 4 * STORAGE_COST | ||
storageContract.setKvEntryCount(3); | ||
(,, reward) = storageContract.miningRewards(0, 1); | ||
assertEq(reward, storageContract.paymentIn(PREPAID_AMOUNT + STORAGE_COST * 2, 0, 1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX License Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../StorageContract.sol"; | ||
|
||
contract TestStorageContract is StorageContract { | ||
constructor(Config memory _config, uint256 _startTime, uint256 _storageCost, uint256 _dcfFactor) | ||
StorageContract(_config, _startTime, _storageCost, _dcfFactor) | ||
{} | ||
|
||
function initialize( | ||
uint256 _minimumDiff, | ||
uint256 _prepaidAmount, | ||
uint256 _nonceLimit, | ||
address _treasury, | ||
address _owner | ||
) public payable initializer { | ||
__init_storage(_minimumDiff, _prepaidAmount, _nonceLimit, _treasury, _owner); | ||
} | ||
|
||
function verifySamples( | ||
uint256 _startShardId, | ||
bytes32 _hash0, | ||
address _miner, | ||
bytes32[] memory _encodedSamples, | ||
uint256[] memory _masks, | ||
bytes[] calldata _inclusiveProofs, | ||
bytes[] calldata _decodeProof | ||
) public pure override returns (bytes32) { | ||
return bytes32(0); | ||
} | ||
|
||
function setKvEntryCount(uint40 _kvEntryCount) public { | ||
kvEntryCount = _kvEntryCount; | ||
} | ||
|
||
function paymentIn(uint256 _x, uint256 _fromTs, uint256 _toTs) public view returns (uint256) { | ||
return _paymentIn(_x, _fromTs, _toTs); | ||
} | ||
|
||
function miningRewards(uint256 _shardId, uint256 _minedTs) public view returns (bool, uint256, uint256) { | ||
return _miningReward(_shardId, _minedTs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters