def generate_safe_contract_address(address: Address, salt: int,
                                   call_data: bytes) -> Address:
    return force_bytes_to_address(
        keccak(b'\xff' + address + int_to_bytes32(salt) + keccak(call_data)))
def test_int_to_bytes32_invalid(value):
    with pytest.raises(ValueError):
        int_to_bytes32(value)
Example #3
0
        'validator_registry_update_epoch,'
        'epochs_since_last_registry_change_is_power_of_two,'
        'current_calculation_epoch,'
        'latest_randao_mixes,'
        'expected_current_calculation_epoch,'
    ),
    [
        (
            40, 4, 2, 2,
            2**10, 4, 19,
            False,
            10,
            2,
            True,  # (state.current_epoch - state.validator_registry_update_epoch) is power of two
            0,
            [int_to_bytes32(i) for i in range(2**10)],
            5,  # expected current_calculation_epoch is state.next_epoch
        ),
        (
            40, 4, 2, 2,
            2**10, 4, 19,
            False,
            10,
            1,
            False,  # (state.current_epoch - state.validator_registry_update_epoch) != power of two
            0,
            [int_to_bytes32(i) for i in range(2**10)],
            0,  # expected_current_calculation_epoch is current_calculation_epoch because it will not be updated  # noqa: E501
        ),
    ]
)
def test_int_to_bytes32_valid(value, expected):
    assert int_to_bytes32(value) == expected
Example #5
0
     'num_shards_in_committees,'
     'validator_registry_update_slot,'
     'current_epoch_calculation_slot,'
     'latest_randao_mixes,'
     'expected_current_epoch_calculation_slot,'
     'expected_current_epoch_randao_mix,'
 ),
 [
     (
         40, 4, 2, 2,
         2**10, 4, 20,
         False,
         10,
         16,  # (state.slot - state.validator_registry_update_slot) EPOCH_LENGTH is power of two
         0,
         [int_to_bytes32(i) for i in range(2**10)],
         20,  # expected current_epoch_calculation_slot is state.slot
         int_to_bytes32((20 - 4) % 2**10),  # latest_randao_mixes[(result_state.current_epoch_calculation_slot - SEED_LOOKAHEAD) % LATEST_RANDAO_MIXES_LENGTH]  # noqa: E501
     ),
     (
         40, 4, 2, 2,
         2**10, 4, 20,
         False,
         10,
         8,  # (state.slot - state.validator_registry_update_slot) EPOCH_LENGTH != power of two
         0,
         [int_to_bytes32(i) for i in range(2**10)],
         0,  # expected current_epoch_calculation_slot is state.slot
         int_to_bytes32(0),
     ),
 ]