mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-11-10 10:05:17 +00:00
Add tests.
This commit is contained in:
parent
69be4e1412
commit
be95796f84
@ -103,6 +103,10 @@ impl Pruner {
|
||||
.maybe_forward_first_rewardable(new_first_rewardable)
|
||||
.await?
|
||||
{
|
||||
info!(
|
||||
?new_first_rewardable,
|
||||
"first rewardable chunk moves forward, start pruning"
|
||||
);
|
||||
self.prune_in_batch(no_reward_list).await?;
|
||||
self.put_first_rewardable_chunk_index(new_first_rewardable)
|
||||
.await?;
|
||||
|
@ -2,8 +2,10 @@
|
||||
import time
|
||||
|
||||
from test_framework.test_framework import TestFramework
|
||||
from config.node_config import GENESIS_PRIV_KEY
|
||||
from mine_with_market_test import PRICE_PER_SECTOR
|
||||
from utility.submission import create_submission, submit_data
|
||||
from utility.utils import wait_until, assert_equal
|
||||
from utility.utils import wait_until, assert_equal, estimate_st_performance
|
||||
|
||||
|
||||
class PrunerTest(TestFramework):
|
||||
@ -13,16 +15,25 @@ class PrunerTest(TestFramework):
|
||||
self.num_nodes = 1
|
||||
self.zgs_node_configs[0] = {
|
||||
"db_max_num_chunks": 16 * 1024,
|
||||
"miner_key": GENESIS_PRIV_KEY,
|
||||
"prune_check_time_s": 1,
|
||||
"prune_batch_wait_time_ms": 10,
|
||||
}
|
||||
self.enable_market = True
|
||||
self.mine_period = int(45 / self.block_time)
|
||||
self.lifetime_seconds = 60
|
||||
self.launch_wait_seconds = 15
|
||||
self.log.info("Contract Info: Est. block time %.2f, Mine period %d", self.block_time, self.mine_period)
|
||||
|
||||
def run_test(self):
|
||||
difficulty = int(2**256 / 5 / estimate_st_performance())
|
||||
self.mine_contract.set_quality(difficulty)
|
||||
|
||||
client = self.nodes[0]
|
||||
|
||||
chunk_data = b"\x02" * 16 * 256 * 1024
|
||||
submissions, data_root = create_submission(chunk_data)
|
||||
self.contract.submit(submissions)
|
||||
self.contract.submit(submissions, tx_prarams = {"value": int(len(chunk_data) / 256 * PRICE_PER_SECTOR * 1.1)})
|
||||
wait_until(lambda: self.contract.num_submissions() == 1)
|
||||
wait_until(lambda: client.zgs_get_file_info(data_root) is not None)
|
||||
|
||||
@ -42,6 +53,15 @@ class PrunerTest(TestFramework):
|
||||
else:
|
||||
assert_equal(seg, None)
|
||||
|
||||
wait_until(lambda: self.reward_contract.first_rewardable_chunk() != 0)
|
||||
first_rewardable = self.reward_contract.first_rewardable_chunk()
|
||||
for i in range(shard_id, len(segment), num_shard):
|
||||
seg = client.zgs_download_segment(data_root, i * 1024, (i + 1) * 1024)
|
||||
if i < first_rewardable:
|
||||
assert_equal(seg, None)
|
||||
else:
|
||||
assert_equal(len(seg), 349528)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
PrunerTest().main()
|
||||
|
@ -253,7 +253,7 @@ class BlockchainNode(TestNode):
|
||||
def wait_for_transaction_receipt(self, w3, tx_hash, timeout=120, parent_hash=None):
|
||||
return w3.eth.wait_for_transaction_receipt(tx_hash, timeout)
|
||||
|
||||
def setup_contract(self, enable_market, mine_period):
|
||||
def setup_contract(self, enable_market, mine_period, lifetime_seconds):
|
||||
w3 = Web3(HTTPProvider(self.rpc_url))
|
||||
|
||||
account1 = w3.eth.account.from_key(GENESIS_PRIV_KEY)
|
||||
@ -314,9 +314,7 @@ class BlockchainNode(TestNode):
|
||||
|
||||
return flow_contract, flow_initialize_hash, mine_contract, dummy_reward_contract
|
||||
|
||||
def deploy_with_market():
|
||||
LIFETIME_MONTH = 1
|
||||
|
||||
def deploy_with_market(lifetime_seconds):
|
||||
self.log.debug("Start deploy contracts")
|
||||
|
||||
mine_contract, _ = deploy_contract("PoraMineTest", [0])
|
||||
@ -325,7 +323,7 @@ class BlockchainNode(TestNode):
|
||||
market_contract, _ = deploy_contract("FixedPrice", [])
|
||||
self.log.debug("Market deployed")
|
||||
|
||||
reward_contract, _ =deploy_contract("OnePoolReward", [LIFETIME_MONTH])
|
||||
reward_contract, _ = deploy_contract("ChunkLinearReward", [lifetime_seconds])
|
||||
self.log.debug("Reward deployed")
|
||||
|
||||
flow_contract, _ = deploy_contract("FixedPriceFlow", [mine_period, 0])
|
||||
@ -336,7 +334,9 @@ class BlockchainNode(TestNode):
|
||||
mine_contract.functions.setTargetSubmissions(2).transact(TX_PARAMS)
|
||||
self.log.debug("Mine Initialized")
|
||||
|
||||
market_contract.functions.initialize(LIFETIME_MONTH, flow_contract.address, reward_contract.address).transact(TX_PARAMS)
|
||||
market_contract.functions.initialize(int(lifetime_seconds * 256 * 10 * 10 ** 18 /
|
||||
2 ** 30 / 12 / 31 / 86400),
|
||||
flow_contract.address, reward_contract.address).transact(TX_PARAMS)
|
||||
self.log.debug("Market Initialized")
|
||||
|
||||
reward_contract.functions.initialize(market_contract.address, mine_contract.address).transact(TX_PARAMS)
|
||||
@ -351,7 +351,7 @@ class BlockchainNode(TestNode):
|
||||
return flow_contract, flow_initialize_hash, mine_contract, reward_contract
|
||||
|
||||
if enable_market:
|
||||
return deploy_with_market()
|
||||
return deploy_with_market(lifetime_seconds)
|
||||
else:
|
||||
return deploy_no_market()
|
||||
|
||||
|
@ -51,6 +51,7 @@ class TestFramework:
|
||||
self.block_time = blockchain_node_type.block_time()
|
||||
self.enable_market = False
|
||||
self.mine_period = 100
|
||||
self.lifetime_seconds = 3600
|
||||
self.launch_wait_seconds = 1
|
||||
|
||||
# Set default binary path
|
||||
@ -171,7 +172,7 @@ class TestFramework:
|
||||
wait_until(lambda: node.eth_blockNumber() is not None)
|
||||
wait_until(lambda: int(node.eth_blockNumber(), 16) > 0)
|
||||
|
||||
contract, tx_hash, mine_contract, reward_contract = self.blockchain_nodes[0].setup_contract(self.enable_market, self.mine_period)
|
||||
contract, tx_hash, mine_contract, reward_contract = self.blockchain_nodes[0].setup_contract(self.enable_market, self.mine_period, self.lifetime_seconds)
|
||||
self.contract = FlowContractProxy(contract, self.blockchain_nodes)
|
||||
self.mine_contract = MineContractProxy(mine_contract, self.blockchain_nodes)
|
||||
self.reward_contract = IRewardContractProxy(reward_contract, self.blockchain_nodes)
|
||||
@ -197,6 +198,7 @@ class TestFramework:
|
||||
updated_config,
|
||||
self.contract.address(),
|
||||
self.mine_contract.address(),
|
||||
self.reward_contract.address(),
|
||||
self.log,
|
||||
)
|
||||
self.nodes.append(node)
|
||||
|
@ -22,6 +22,7 @@ class ZgsNode(TestNode):
|
||||
updated_config,
|
||||
log_contract_address,
|
||||
mine_contract_address,
|
||||
reward_contract_address,
|
||||
log,
|
||||
rpc_timeout=10,
|
||||
libp2p_nodes=None,
|
||||
@ -43,6 +44,7 @@ class ZgsNode(TestNode):
|
||||
"network_libp2p_nodes": libp2p_nodes,
|
||||
"log_contract_address": log_contract_address,
|
||||
"mine_contract_address": mine_contract_address,
|
||||
"reward_contract_address": reward_contract_address,
|
||||
"blockchain_rpc_endpoint": f"http://127.0.0.1:{blockchain_rpc_port(0)}",
|
||||
}
|
||||
# Set configs for this specific node.
|
||||
|
Loading…
Reference in New Issue
Block a user