Exemple #1
0
    def checksum_address_from_filepath(cls, filepath: Path) -> str:
        pattern = re.compile(
            r'''
                             (^\w+)-
                             (0x{1}           # Then, 0x the start of the string, exactly once
                             [0-9a-fA-F]{40}) # Followed by exactly 40 hex chars
                             ''', re.VERBOSE)

        filename = filepath.name
        match = pattern.match(filename)

        if match:
            character_name, checksum_address = match.groups()
        else:
            # Extract from default by "peeking" inside the configuration file.
            default_name = cls.generate_filename()
            if filename == default_name:
                checksum_address = cls.peek(filepath=filepath,
                                            field='checksum_address')
            else:
                raise ValueError(
                    f"Cannot extract checksum from filepath '{filepath}'")

        if not is_checksum_address(checksum_address):
            raise RuntimeError(
                f"Invalid checksum address detected in configuration file at '{filepath}'."
            )
        return checksum_address
Exemple #2
0
async def test_module_web3_eth(provider):
    web3 = Web3(provider)
    version = await web3.eth.protocolVersion
    assert isinstance(version, str) and len(version) < 5
    coinbase = await web3.eth.coinbase
    assert is_checksum_address(coinbase)
    mining = await web3.eth.mining
    assert isinstance(mining, bool) and mining
    assert isinstance(await web3.eth.blockNumber, int)
    coinbase_balance = await web3.eth.getBalance(coinbase)
    assert isinstance(coinbase_balance, int) and coinbase_balance > 0
    data = await web3.eth.getStorageAt(coinbase, '0x0', 'latest')
    assert isinstance(data, bytes) and data == b'\x00' * 32
    assert isinstance(await web3.eth.getTransactionCount(coinbase), int)
Exemple #3
0
    def checksum_address_from_filepath(cls, filepath: str) -> str:

        pattern = re.compile(
            r'''
                             (^\w+)-
                             (0x{1}         # Then, 0x the start of the string, exactly once
                             [0-9a-fA-F]{40}) # Followed by exactly 40 hex chars
                             ''', re.VERBOSE)

        filename = os.path.basename(filepath)
        match = pattern.match(filename)

        if match:
            character_name, checksum_address = match.groups()

        else:
            # Extract from default by "peeking" inside the configuration file.
            default_name = cls.generate_filename()
            if filename == default_name:
                checksum_address = cls.peek(filepath=filepath,
                                            field='checksum_address')

                ###########
                # TODO: Cleanup and deprecate worker_address in config files, leaving only checksum_address
                from nucypher.config.characters import UrsulaConfiguration
                if isinstance(cls, UrsulaConfiguration):
                    federated = bool(
                        cls.peek(filepath=filepath, field='federated_only'))
                    if not federated:
                        checksum_address = cls.peek(filepath=cls.filepath,
                                                    field='worker_address')
                ###########

            else:
                raise ValueError(
                    f"Cannot extract checksum from filepath '{filepath}'")

        if not is_checksum_address(checksum_address):
            raise RuntimeError(
                f"Invalid checksum address detected in configuration file at '{filepath}'."
            )
        return checksum_address
Exemple #4
0
def test_is_checksum_address(value, expected):
    assert is_checksum_address(value) is expected