mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-20 08:05:33 +03:00
Use make_test_constants_with_genesis
.
This commit is contained in:
parent
e4f3050667
commit
f8d06946cd
@ -23,7 +23,7 @@ def service_kwargs_for_wallet(root_path):
|
||||
wallet_constants = consensus_constants
|
||||
if config["testing"] is True:
|
||||
config["database_path"] = "test_db_wallet.db"
|
||||
wallet_constants = wallet_constants.replace(test_constants)
|
||||
wallet_constants = wallet_constants.replace(**test_constants)
|
||||
|
||||
api = WalletNode(config, keychain, root_path, consensus_constants=wallet_constants)
|
||||
|
||||
|
@ -24,7 +24,7 @@ def service_kwargs_for_full_node(root_path):
|
||||
config["database_path"] = config["simulator_database_path"]
|
||||
|
||||
api = FullNodeSimulator(
|
||||
config, root_path=root_path, override_constants=test_constants
|
||||
config, root_path=root_path, consensus_constants=test_constants
|
||||
)
|
||||
|
||||
introducer = config["introducer_peer"]
|
||||
|
@ -14,10 +14,10 @@ from chiabip158 import PyBIP158
|
||||
from chiapos import DiskPlotter, DiskProver
|
||||
from src import __version__
|
||||
from src.consensus.coinbase import create_puzzlehash_for_pk
|
||||
from src.consensus.constants import ConsensusConstants
|
||||
from src.cmds.init import create_default_chia_config, initialize_ssl
|
||||
from src.types.BLSSignature import BLSPublicKey
|
||||
from src.consensus import block_rewards, pot_iterations
|
||||
from src.consensus.constants import constants
|
||||
from src.consensus.pot_iterations import calculate_min_iters_from_iterations
|
||||
from src.consensus.coinbase import create_coinbase_coin_and_signature
|
||||
from src.types.challenge import Challenge
|
||||
@ -183,7 +183,7 @@ class BlockTools:
|
||||
|
||||
def get_consecutive_blocks(
|
||||
self,
|
||||
input_constants: Dict,
|
||||
test_constants: ConsensusConstants,
|
||||
num_blocks: int,
|
||||
block_list: List[FullBlock] = [],
|
||||
seconds_per_block=None,
|
||||
@ -194,9 +194,6 @@ class BlockTools:
|
||||
) -> List[FullBlock]:
|
||||
if transaction_data_at_height is None:
|
||||
transaction_data_at_height = {}
|
||||
test_constants: Dict[str, Any] = constants.copy()
|
||||
for key, value in input_constants.items():
|
||||
test_constants[key] = value
|
||||
if seconds_per_block is None:
|
||||
seconds_per_block = test_constants["BLOCK_TIME_TARGET"]
|
||||
|
||||
@ -355,7 +352,7 @@ class BlockTools:
|
||||
|
||||
def create_genesis_block(
|
||||
self,
|
||||
input_constants: Dict,
|
||||
test_constants: ConsensusConstants,
|
||||
challenge_hash=bytes([0] * 32),
|
||||
seed: bytes = b"",
|
||||
reward_puzzlehash: Optional[bytes32] = None,
|
||||
@ -363,10 +360,6 @@ class BlockTools:
|
||||
"""
|
||||
Creates the genesis block with the specified details.
|
||||
"""
|
||||
test_constants: Dict[str, Any] = constants.copy()
|
||||
for key, value in input_constants.items():
|
||||
test_constants[key] = value
|
||||
|
||||
return self._create_block(
|
||||
test_constants,
|
||||
challenge_hash,
|
||||
@ -384,7 +377,7 @@ class BlockTools:
|
||||
|
||||
def create_next_block(
|
||||
self,
|
||||
input_constants: Dict,
|
||||
test_constants: ConsensusConstants,
|
||||
prev_block: FullBlock,
|
||||
timestamp: uint64,
|
||||
update_difficulty: bool,
|
||||
@ -399,9 +392,6 @@ class BlockTools:
|
||||
"""
|
||||
Creates the next block with the specified details.
|
||||
"""
|
||||
test_constants: Dict[str, Any] = constants.copy()
|
||||
for key, value in input_constants.items():
|
||||
test_constants[key] = value
|
||||
assert prev_block.proof_of_time is not None
|
||||
if update_difficulty:
|
||||
challenge = Challenge(
|
||||
@ -442,7 +432,7 @@ class BlockTools:
|
||||
|
||||
def _create_block(
|
||||
self,
|
||||
test_constants: Dict,
|
||||
test_constants: ConsensusConstants,
|
||||
challenge_hash: bytes32,
|
||||
height: uint32,
|
||||
prev_header_hash: bytes32,
|
||||
@ -651,12 +641,13 @@ class BlockTools:
|
||||
# Run by doing python -m tests.block_tools
|
||||
if __name__ == "__main__":
|
||||
from src.util.default_root import DEFAULT_ROOT_PATH
|
||||
from src.consensus.constants import constants as consensus_constants
|
||||
|
||||
bt = BlockTools(root_path=DEFAULT_ROOT_PATH, real_plots=True)
|
||||
print(
|
||||
bytes(
|
||||
bt.create_genesis_block(
|
||||
{},
|
||||
consensus_constants,
|
||||
bytes([2] * 32),
|
||||
b"0",
|
||||
bytes.fromhex(
|
||||
|
@ -72,7 +72,7 @@ class TestBlockStore:
|
||||
assert (await db.get_tips()) == [blocks[-2].header, blocks[-1].header]
|
||||
|
||||
coin_store: CoinStore = await CoinStore.create(connection_3)
|
||||
hacked_constants = consensus_constants.replace(**test_constants)
|
||||
hacked_constants = consensus_constants.replace(**test_constants.copy())
|
||||
b: Blockchain = await Blockchain.create(coin_store, db_3, hacked_constants)
|
||||
|
||||
assert b.lca_block == genesis.header
|
||||
|
@ -12,7 +12,7 @@ from src.types.full_block import FullBlock
|
||||
from src.types.header import Header, HeaderData
|
||||
from src.types.proof_of_space import ProofOfSpace
|
||||
from src.util.ints import uint8, uint64
|
||||
from src.consensus.constants import constants as consensus_constants
|
||||
from src.consensus.constants import ConsensusConstants
|
||||
from tests.block_tools import BlockTools
|
||||
from src.util.errors import Err
|
||||
from src.consensus.coinbase import create_coinbase_coin_and_signature
|
||||
@ -21,11 +21,11 @@ from src.full_node.block_store import BlockStore
|
||||
from src.full_node.coin_store import CoinStore
|
||||
from src.consensus.find_fork_point import find_fork_point_in_chain
|
||||
from tests.block_tools import BlockTools
|
||||
from tests.make_test_constants import make_test_constants_with_genesis
|
||||
|
||||
bt = BlockTools()
|
||||
test_constants: Dict[str, Any] = consensus_constants.copy()
|
||||
test_constants.update(
|
||||
{
|
||||
|
||||
test_constants: ConsensusConstants = make_test_constants_with_genesis({
|
||||
"DIFFICULTY_STARTING": 1,
|
||||
"DISCRIMINANT_SIZE_BITS": 8,
|
||||
"BLOCK_TIME_TARGET": 10,
|
||||
@ -33,11 +33,8 @@ test_constants.update(
|
||||
"DIFFICULTY_WARP_FACTOR": 3,
|
||||
"DIFFICULTY_DELAY": 2, # EPOCH / WARP_FACTOR
|
||||
"MIN_ITERS_STARTING": 50 * 1,
|
||||
}
|
||||
)
|
||||
test_constants["GENESIS_BLOCK"] = bytes(
|
||||
bt.create_genesis_block(test_constants, bytes([0] * 32), b"0")
|
||||
)
|
||||
})
|
||||
test_constants_dict: Dict[str, Any] = test_constants.copy()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
@ -10,12 +10,11 @@ from src.full_node.coin_store import CoinStore
|
||||
from src.full_node.block_store import BlockStore
|
||||
from tests.block_tools import BlockTools
|
||||
from src.consensus.constants import constants as consensus_constants
|
||||
from tests.setup_nodes import test_constants as override_constants
|
||||
from tests.setup_nodes import test_constants
|
||||
from tests.block_tools import BlockTools
|
||||
|
||||
bt = BlockTools()
|
||||
|
||||
test_constants = consensus_constants.replace(**override_constants)
|
||||
test_constants_dict = test_constants.copy()
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
|
16
tests/make_test_constants.py
Normal file
16
tests/make_test_constants.py
Normal file
@ -0,0 +1,16 @@
|
||||
from typing import Dict
|
||||
|
||||
from src.consensus.constants import constants
|
||||
from .block_tools import BlockTools
|
||||
|
||||
|
||||
def make_test_constants_with_genesis(test_constants_overrides: Dict):
|
||||
|
||||
test_constants = constants.replace(**test_constants_overrides)
|
||||
|
||||
bt = BlockTools()
|
||||
|
||||
new_genesis_block = bt.create_genesis_block(test_constants, bytes([0] * 32), b"0")
|
||||
|
||||
final_test_constants = test_constants.replace(GENESIS_BLOCK=bytes(new_genesis_block))
|
||||
return final_test_constants
|
@ -3,7 +3,7 @@ import signal
|
||||
|
||||
from secrets import token_bytes
|
||||
from typing import Any, Dict, Tuple, List, Optional
|
||||
from src.consensus.constants import constants as consensus_constants
|
||||
from src.consensus.constants import constants as consensus_constants, ConsensusConstants
|
||||
from src.full_node.full_node import FullNode
|
||||
from src.server.connection import NodeType
|
||||
from src.server.server import ChiaServer, start_server
|
||||
@ -22,6 +22,7 @@ from src.server.start_service import create_periodic_introducer_poll_task
|
||||
from src.util.ints import uint16, uint32
|
||||
from src.server.start_service import Service
|
||||
from src.rpc.harvester_rpc_api import HarvesterRpcApi
|
||||
from tests.make_test_constants import make_test_constants_with_genesis
|
||||
from tests.time_out_assert import time_out_assert
|
||||
|
||||
|
||||
@ -31,7 +32,7 @@ root_path = bt.root_path
|
||||
global_config = load_config(bt.root_path, "config.yaml")
|
||||
self_hostname = global_config["self_hostname"]
|
||||
|
||||
test_constants: Dict[str, Any] = {
|
||||
test_constants = make_test_constants_with_genesis({
|
||||
"DIFFICULTY_STARTING": 1,
|
||||
"DISCRIMINANT_SIZE_BITS": 8,
|
||||
"BLOCK_TIME_TARGET": 10,
|
||||
@ -43,10 +44,7 @@ test_constants: Dict[str, Any] = {
|
||||
"MEMPOOL_BLOCK_BUFFER": 10,
|
||||
"MIN_ITERS_STARTING": 50 * 1,
|
||||
"CLVM_COST_RATIO_CONSTANT": 108,
|
||||
}
|
||||
test_constants["GENESIS_BLOCK"] = bytes(
|
||||
bt.create_genesis_block(test_constants, bytes([0] * 32), b"0")
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
async def _teardown_nodes(node_aiters: List) -> None:
|
||||
@ -259,8 +257,7 @@ async def setup_harvester(port, farmer_port, dic={}):
|
||||
async def setup_farmer(port, full_node_port: Optional[uint16] = None, dic={}):
|
||||
config = load_config(bt.root_path, "config.yaml", "farmer")
|
||||
config_pool = load_config(root_path, "config.yaml", "pool")
|
||||
test_constants_copy = consensus_constants.replace(**test_constants)
|
||||
test_constants_copy = test_constants_copy.replace(**dic)
|
||||
test_constants_copy = test_constants.replace(**dic)
|
||||
config["xch_target_puzzle_hash"] = bt.fee_target.hex()
|
||||
config["pool_public_keys"] = [
|
||||
bytes(epk.get_public_key()).hex() for epk in bt.keychain.get_all_public_keys()
|
||||
@ -356,8 +353,7 @@ async def setup_vdf_clients(port):
|
||||
|
||||
async def setup_timelord(port, full_node_port, sanitizer, dic={}):
|
||||
config = load_config(bt.root_path, "config.yaml", "timelord")
|
||||
test_constants_copy = consensus_constants.replace(**test_constants)
|
||||
test_constants_copy = test_constants_copy.replace(**dic)
|
||||
test_constants_copy = test_constants.replace(**dic)
|
||||
config["sanitizer_mode"] = sanitizer
|
||||
if sanitizer:
|
||||
config["vdf_server"]["port"] = 7999
|
||||
|
@ -7,15 +7,12 @@ from tests.block_tools import BlockTools
|
||||
from src.consensus.constants import constants as consensus_constants
|
||||
from src.util.ints import uint32
|
||||
from src.types.full_block import FullBlock
|
||||
from tests.make_test_constants import make_test_constants_with_genesis
|
||||
from tests.time_out_assert import time_out_assert, time_out_assert_custom_interval
|
||||
|
||||
bt = BlockTools()
|
||||
test_constants: Dict[str, Any] = consensus_constants.copy()
|
||||
test_constants.update({"DIFFICULTY_STARTING": 500, "MIN_ITERS_STARTING": 500})
|
||||
|
||||
test_constants["GENESIS_BLOCK"] = bytes(
|
||||
bt.create_genesis_block(test_constants, bytes([0] * 32), b"0")
|
||||
)
|
||||
test_constants = make_test_constants_with_genesis({"DIFFICULTY_STARTING": 500, "MIN_ITERS_STARTING": 500})
|
||||
|
||||
|
||||
def node_height_at_least(node, h):
|
||||
@ -33,7 +30,7 @@ def event_loop():
|
||||
class TestSimulation:
|
||||
@pytest.fixture(scope="function")
|
||||
async def simulation(self):
|
||||
async for _ in setup_full_system(test_constants):
|
||||
async for _ in setup_full_system(test_constants.copy()):
|
||||
yield _
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
Loading…
Reference in New Issue
Block a user