Test with Mine contract instead of MineTest

This commit is contained in:
Chenxing Li 2024-03-21 15:15:22 +08:00
parent 16dfc56437
commit 5f5050f37c
6 changed files with 22 additions and 19 deletions

@ -1 +1 @@
Subproject commit d466311abb6f629a6489450f2e684b2c6e7b1089 Subproject commit f816ade101f590a2a4c8818c878e0d8432c08efa

View File

@ -15,6 +15,9 @@ class MineTest(TestFramework):
"miner_id": MINER_ID, "miner_id": MINER_ID,
"miner_key": GENESIS_PRIV_KEY, "miner_key": GENESIS_PRIV_KEY,
} }
self.mine_config = {
"init_rate": 8000 / 60,
}
def submit_data(self, item, size): def submit_data(self, item, size):
submissions_before = self.contract.num_submissions() submissions_before = self.contract.num_submissions()
@ -34,9 +37,6 @@ class MineTest(TestFramework):
self.log.info("flow address: %s", self.contract.address()) self.log.info("flow address: %s", self.contract.address())
self.log.info("mine address: %s", self.mine_contract.address()) self.log.info("mine address: %s", self.mine_contract.address())
quality = int(2**256 / 40960)
self.mine_contract.set_quality(quality)
self.log.info("Submit the first data chunk") self.log.info("Submit the first data chunk")
self.submit_data(b"\x11", 2000) self.submit_data(b"\x11", 2000)

View File

@ -18,8 +18,11 @@ class MineTest(TestFramework):
"miner_id": MINER_ID, "miner_id": MINER_ID,
"miner_key": GENESIS_PRIV_KEY, "miner_key": GENESIS_PRIV_KEY,
} }
self.enable_market = True self.mine_config = {
self.mine_period = 150 "enable_market": True,
"mine_period": 150,
"init_rate": 800 / 60,
}
def submit_data(self, item, size, no_submit = False): def submit_data(self, item, size, no_submit = False):
submissions_before = self.contract.num_submissions() submissions_before = self.contract.num_submissions()
@ -41,9 +44,6 @@ class MineTest(TestFramework):
self.log.info("flow address: %s", self.contract.address()) self.log.info("flow address: %s", self.contract.address())
self.log.info("mine address: %s", self.mine_contract.address()) self.log.info("mine address: %s", self.mine_contract.address())
quality = int(2**256 / 4096)
self.mine_contract.set_quality(quality)
SECTORS_PER_PRICING = int(8 * ( 2 ** 30 ) / 256) SECTORS_PER_PRICING = int(8 * ( 2 ** 30 ) / 256)
self.log.info("Submit the actual data chunk (256 MB)") self.log.info("Submit the actual data chunk (256 MB)")

View File

@ -248,9 +248,13 @@ class BlockchainNode(TestNode):
def wait_for_transaction_receipt(self, w3, tx_hash, timeout=120, parent_hash=None): def wait_for_transaction_receipt(self, w3, tx_hash, timeout=120, parent_hash=None):
return w3.eth.wait_for_transaction_receipt(tx_hash, timeout) return w3.eth.wait_for_transaction_receipt(tx_hash, timeout)
def setup_contract(self, enable_market, mine_period): def setup_contract(self, mine_config):
w3 = Web3(HTTPProvider(self.rpc_url)) w3 = Web3(HTTPProvider(self.rpc_url))
enable_market = mine_config.get("enable_market", False)
mine_period = mine_config.get("mine_period", 100)
init_rate = int(mine_config.get("init_rate", 1024))
account1 = w3.eth.account.from_key(GENESIS_PRIV_KEY) account1 = w3.eth.account.from_key(GENESIS_PRIV_KEY)
account2 = w3.eth.account.from_key(GENESIS_PRIV_KEY1) account2 = w3.eth.account.from_key(GENESIS_PRIV_KEY1)
w3.middleware_onion.add( w3.middleware_onion.add(
@ -298,11 +302,11 @@ class BlockchainNode(TestNode):
flow_contract, flow_contract_hash = deploy_contract("Flow", [book.address, mine_period, 0]) flow_contract, flow_contract_hash = deploy_contract("Flow", [book.address, mine_period, 0])
self.log.debug("Flow deployed") self.log.debug("Flow deployed")
mine_contract, _ = deploy_contract("PoraMineTest", [book.address, 3]) mine_contract, _ = deploy_contract("PoraMine", [book.address, 1, 1, 7])
self.log.debug("Mine deployed") self.log.debug("Mine deployed")
self.log.info("All contracts deployed") self.log.info("All contracts deployed")
tx_hash = mine_contract.functions.setMiner(decode_hex(MINER_ID)).transact(TX_PARAMS) tx_hash = mine_contract.functions.registMiner(decode_hex(MINER_ID)).transact(TX_PARAMS)
self.wait_for_transaction_receipt(w3, tx_hash) self.wait_for_transaction_receipt(w3, tx_hash)
dummy_reward_contract = w3.eth.contract( dummy_reward_contract = w3.eth.contract(
@ -324,14 +328,14 @@ class BlockchainNode(TestNode):
book, _ = deploy_contract("AddressBook", [flowAddress, marketAddress, rewardAddress, mineAddress]); book, _ = deploy_contract("AddressBook", [flowAddress, marketAddress, rewardAddress, mineAddress]);
self.log.debug("AddressBook deployed") self.log.debug("AddressBook deployed")
mine_contract, _ = deploy_contract("PoraMineTest", [book.address, 3]) mine_contract, _ = deploy_contract("PoraMine", [book.address, init_rate, 20, 3])
deploy_contract("FixedPrice", [book.address, LIFETIME_MONTH]) deploy_contract("FixedPrice", [book.address, LIFETIME_MONTH])
reward_contract, _ =deploy_contract("OnePoolReward", [book.address, LIFETIME_MONTH]) reward_contract, _ =deploy_contract("OnePoolReward", [book.address, LIFETIME_MONTH])
flow_contract, flow_contract_hash = deploy_contract("FixedPriceFlow", [book.address, mine_period, 0]) flow_contract, flow_contract_hash = deploy_contract("FixedPriceFlow", [book.address, mine_period, 0])
self.log.info("All contracts deployed") self.log.info("All contracts deployed")
tx_hash = mine_contract.functions.setMiner(decode_hex(MINER_ID)).transact(TX_PARAMS) tx_hash = mine_contract.functions.registMiner(decode_hex(MINER_ID)).transact(TX_PARAMS)
self.wait_for_transaction_receipt(w3, tx_hash) self.wait_for_transaction_receipt(w3, tx_hash)
return flow_contract, flow_contract_hash, mine_contract, reward_contract return flow_contract, flow_contract_hash, mine_contract, reward_contract

View File

@ -87,8 +87,8 @@ class MineContractProxy(ContractProxy):
def last_mined_epoch(self, node_idx=0): def last_mined_epoch(self, node_idx=0):
return self._call("lastMinedEpoch", node_idx) return self._call("lastMinedEpoch", node_idx)
def set_quality(self, quality, node_idx=0): # def set_quality(self, quality, node_idx=0):
return self._send("setQuality", node_idx, _targetQuality=quality) # return self._send("setQuality", node_idx, _targetQuality=quality)

View File

@ -46,8 +46,7 @@ class TestFramework:
self.blockchain_node_configs = {} self.blockchain_node_configs = {}
self.zgs_node_configs = {} self.zgs_node_configs = {}
self.blockchain_node_type = blockchain_node_type self.blockchain_node_type = blockchain_node_type
self.enable_market = False self.mine_config = {}
self.mine_period = 100
binary_ext = ".exe" if is_windows_platform() else "" binary_ext = ".exe" if is_windows_platform() else ""
tests_dir = os.path.dirname(__file_path__) tests_dir = os.path.dirname(__file_path__)
@ -140,7 +139,7 @@ class TestFramework:
connect_sample_nodes(self.blockchain_nodes, self.log) connect_sample_nodes(self.blockchain_nodes, self.log)
sync_blocks(self.blockchain_nodes) sync_blocks(self.blockchain_nodes)
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.mine_config)
self.contract = FlowContractProxy(contract, self.blockchain_nodes) self.contract = FlowContractProxy(contract, self.blockchain_nodes)
self.mine_contract = MineContractProxy(mine_contract, self.blockchain_nodes) self.mine_contract = MineContractProxy(mine_contract, self.blockchain_nodes)
self.reward_contract = IRewardContractProxy(reward_contract, self.blockchain_nodes) self.reward_contract = IRewardContractProxy(reward_contract, self.blockchain_nodes)