Exemple #1
0
 def connect(self, compile_now: bool = True, ignore_solidity_check: bool = False) -> bool:
     super().connect()
     if compile_now:
         # Execute the compilation if we're recompiling
         # Otherwise read compiled contract data from the registry.
         check = not ignore_solidity_check
         compiled_contracts = multiversion_compile(source_bundles=self.SOURCES, compiler_version_check=check)
         self._raw_contract_cache = compiled_contracts
     return self.is_connected
Exemple #2
0
def test_multi_source_compilation(testerchain):
    bundles = [
        SourceBundle(base_path=SOLIDITY_SOURCE_ROOT),
        SourceBundle(base_path=SOLIDITY_SOURCE_ROOT,
                     other_paths=(TEST_SOLIDITY_SOURCE_ROOT, ))
    ]
    interfaces = multiversion_compile(source_bundles=bundles)
    raw_cache = testerchain._raw_contract_cache.copy()
    assert interfaces == raw_cache
Exemple #3
0
def test_multi_versions():
    base_dir = TEST_MULTIVERSION_CONTRACTS
    v1_dir, v2_dir = base_dir / "v1", base_dir / "v2"
    bundles = [SourceBundle(base_path=v1_dir), SourceBundle(base_path=v2_dir)]
    interfaces = multiversion_compile(source_bundles=bundles)
    assert "VersionTest" in interfaces
    contract_data = interfaces["VersionTest"]
    assert len(contract_data) == 2
    assert "v1.2.3" in contract_data
    assert "v1.1.4" in contract_data
    assert contract_data["v1.2.3"]["devdoc"]['details'] != contract_data[
        "v1.1.4"]["devdoc"]['details']
Exemple #4
0
def generate_doc() -> None:
    """Compile solidity contracts, extract json docs and generate rst files from them"""

    GlobalLoggerSettings.start_console_logging()

    base_dir = Path(__file__).parent.parent.parent.resolve()
    solidity_source_root = base_dir / 'nucypher' / 'blockchain' / 'eth' / 'sol' / 'source'

    bundle = SourceBundle(base_path=solidity_source_root)
    contracts = multiversion_compile(source_bundles=[bundle])

    # Prepare folders
    base_path = base_dir / 'docs' / 'source' / 'contracts_api'
    base_path.mkdir(exist_ok=True)
    for dir in CONTRACTS.keys():
        category_path = base_path / dir
        category_path.mkdir(exist_ok=True)

    contract_names = {
        contract
        for contracts in CONTRACTS.values() for contract in contracts
    }
    patch()
    for contract, data in contracts.items():
        if contract not in contract_names:
            continue

        # Merge, update and generate resulting rst
        no_version = next(iter(data.values()))
        docs = merge_and_update(no_version["userdoc"], dict())
        docs = merge_and_update(no_version["devdoc"], docs)
        rst = schema2rst(docs, "kind,version,title", contract)

        # Find proper category and write file
        category_path = base_path
        for category, contracts in CONTRACTS.items():
            if contract in contracts:
                category_path /= category
        with open(category_path / f"{contract}.rst", 'w') as file:
            file.write(rst)
def test_multiversion_contract():

    # Prepare compiler
    base_dir = TEST_MULTIVERSION_CONTRACTS
    v1_dir, v2_dir = base_dir / 'v1', base_dir / 'v2'
    bundles = [
        SourceBundle(base_path=SOLIDITY_SOURCE_ROOT, other_paths=(v1_dir, )),
        SourceBundle(base_path=SOLIDITY_SOURCE_ROOT, other_paths=(v2_dir, ))
    ]
    compiled_contracts = multiversion_compile(source_bundles=bundles)

    # Prepare chain
    BlockchainDeployerInterface.GAS_STRATEGIES = {
        **BlockchainDeployerInterface.GAS_STRATEGIES, 'free':
        free_gas_price_strategy
    }

    blockchain_interface = BlockchainDeployerInterface(
        provider_uri='tester://pyevm/2', gas_strategy='free')
    blockchain_interface.connect(compile_now=False)
    blockchain_interface._raw_contract_cache = compiled_contracts

    origin = blockchain_interface.client.accounts[0]
    blockchain_interface.transacting_power = TransactingPower(
        password=INSECURE_DEVELOPMENT_PASSWORD,
        signer=Web3Signer(blockchain_interface.client),
        account=origin)
    blockchain_interface.transacting_power.activate()

    # Searching both contract through raw data
    contract_name = "VersionTest"
    requested_version = "v1.2.3"
    version, _data = blockchain_interface.find_raw_contract_data(
        contract_name=contract_name, requested_version=requested_version)
    assert version == requested_version
    version, _data = blockchain_interface.find_raw_contract_data(
        contract_name=contract_name, requested_version="latest")
    assert version == requested_version

    requested_version = "v1.1.4"
    version, _data = blockchain_interface.find_raw_contract_data(
        contract_name=contract_name, requested_version=requested_version)
    assert version == requested_version
    version, _data = blockchain_interface.find_raw_contract_data(
        contract_name=contract_name, requested_version="earliest")
    assert version == requested_version

    # Deploy different contracts and check their versions
    registry = InMemoryContractRegistry()
    contract, receipt = blockchain_interface.deploy_contract(
        deployer_address=origin,
        registry=registry,
        contract_name=contract_name,
        contract_version="v1.1.4")
    assert contract.version == "v1.1.4"
    assert contract.functions.VERSION().call() == 1
    contract, receipt = blockchain_interface.deploy_contract(
        deployer_address=origin,
        registry=registry,
        contract_name=contract_name,
        contract_version="earliest")
    assert contract.version == "v1.1.4"
    assert contract.functions.VERSION().call() == 1

    contract, receipt = blockchain_interface.deploy_contract(
        deployer_address=origin,
        registry=registry,
        contract_name=contract_name,
        contract_version="v1.2.3")
    assert contract.version == "v1.2.3"
    assert contract.functions.VERSION().call() == 2
    contract, receipt = blockchain_interface.deploy_contract(
        deployer_address=origin,
        registry=registry,
        contract_name=contract_name,
        contract_version="latest")
    assert contract.version == "v1.2.3"
    assert contract.functions.VERSION().call() == 2
    contract, receipt = blockchain_interface.deploy_contract(
        deployer_address=origin,
        registry=registry,
        contract_name=contract_name)
    assert contract.version == "v1.2.3"
    assert contract.functions.VERSION().call() == 2