def test_forkid(): forkid = ForkID(hash=b'\xe0)\xe9\x91', next=999) assert forkid.hash == b'\xe0)\xe9\x91' assert forkid.next == 999 # A hash with length diffrent than 4 is not allowed. with pytest.raises(ValueError): forkid = ForkID(hash=b'\x00\x00\x00\x02Q\xc0', next=0) with pytest.raises(ValueError): forkid = ForkID(hash=b'\x02Q\xc0', next=0)
def test_extract_forkid(): enr = ENR.from_repr( "enr:-Jq4QO5zEyIBU5lSa9iaen0A2xUB5_IVrCi1DbyASTTnLV5RJan6aGPr8kU0p0MYKU5YezZgdSUE" "-GOBEio6Ultyf1Aog2V0aMrJhGN2AZCDGfCggmlkgnY0gmlwhF4_wLuJc2VjcDI1NmsxoQOt7cA_B_Kg" "nQ5RmwyA6ji8M1Y0jfINItRGbOOwy7XgbIN0Y3CCdl-DdWRwgnZf") assert extract_forkid(enr) == ForkID(hash=to_bytes(hexstr='0x63760190'), next=1700000)
async def test_generate_eth_cap_enr_field(): base_db = AtomicDB() ChainDB(base_db).persist_header(ROPSTEN_GENESIS_HEADER) enr_field = await generate_eth_cap_enr_field(ROPSTEN_VM_CONFIGURATION, AsyncHeaderDB(base_db)) enr = ENRFactory(custom_kv_pairs={enr_field[0]: enr_field[1]}) assert extract_forkid(enr) == ForkID(hash=to_bytes(hexstr='0x30c7ddbc'), next=10)
class StatusPayloadFactory(factory.Factory): class Meta: model = StatusPayload version = ETHProtocol.version network_id = MAINNET_NETWORK_ID total_difficulty = 1 head_hash = factory.SubFactory(BlockHashFactory) genesis_hash = factory.SubFactory(BlockHashFactory) fork_id = ForkID(to_bytes(hexstr='0xfc64ec04'), BlockNumber(1150000)) # unsynced @classmethod def from_headerdb(cls, headerdb: HeaderDatabaseAPI, **kwargs: Any) -> StatusPayload: head = headerdb.get_canonical_head() head_score = headerdb.get_score(head.hash) genesis = headerdb.get_canonical_block_header_by_number( GENESIS_BLOCK_NUMBER) return cls(head_hash=head.hash, genesis_hash=genesis.hash, total_difficulty=head_score, fork_id=cls.fork_id, **kwargs)
) ROPSTEN_GENESIS_HASH = to_bytes( hexstr='0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d' ) def test_extract_fork_blocks(): fork_blocks = extract_fork_blocks(MAINNET_VM_CONFIGURATION) assert fork_blocks == (1150000, 1920000, 2463000, 2675000, 4370000, 7280000, 9069000, 9200000) @pytest.mark.parametrize( 'head,expected_forkid', [ (0, ForkID(hash=to_bytes(hexstr='0xfc64ec04'), next=1150000)), # Unsynced (1149999, ForkID(hash=to_bytes(hexstr='0xfc64ec04'), next=1150000)), # Last Frontier (1150000, ForkID(hash=to_bytes(hexstr='0x97c2c34c'), next=1920000)), # First Homestead (1919999, ForkID(hash=to_bytes(hexstr='0x97c2c34c'), next=1920000)), # Last Homestead (1920000, ForkID(hash=to_bytes(hexstr='0x91d1f948'), next=2463000)), # First DAO block (2462999, ForkID(hash=to_bytes(hexstr='0x91d1f948'), next=2463000)), # Last DAO block (2463000, ForkID(hash=to_bytes(hexstr='0x7a64da13'), next=2675000)), # First Tangerine (2674999, ForkID(hash=to_bytes(hexstr='0x7a64da13'), next=2675000)), # Last Tangerine (2675000, ForkID(hash=to_bytes(hexstr='0x3edd5b10'),