def deploy_base_contract(blockchain_interface: BlockchainDeployerInterface, deployer: BaseContractDeployer, transacting_power: TransactingPower, skipt_test: bool): contract_name = deployer.contract_name latest_version, _data = blockchain_interface.find_raw_contract_data( contract_name, "latest") raw_contracts = blockchain_interface._raw_contract_cache overrides = dict() if len(raw_contracts[contract_name]) != 1: try: overrides_func = CONSTRUCTOR_OVERRIDES[contract_name][ latest_version] overrides = overrides_func(blockchain_interface, transacting_power, deployer) except KeyError: pass version = "latest" if skipt_test else "earliest" try: deployer.deploy(transacting_power=transacting_power, contract_version=version, deployment_mode=constants.FULL, **overrides) except ValidationError: pass # Skip errors related to initialization
def skip_test(blockchain_interface: BlockchainDeployerInterface, contract_name: str): latest_version, _data = blockchain_interface.find_raw_contract_data(contract_name, "latest") raw_contracts = blockchain_interface._raw_contract_cache try: force_skip = latest_version in FORCE_SKIP[contract_name] except KeyError: force_skip = False return force_skip or len(raw_contracts[contract_name]) == 1
def deploy_earliest_contract(blockchain_interface: BlockchainDeployerInterface, deployer: BaseContractDeployer): contract_name = deployer.contract_name latest_version, _data = blockchain_interface.find_raw_contract_data(contract_name, "latest") try: overrides = CONSTRUCTOR_OVERRIDES[contract_name][latest_version] except KeyError: overrides = dict() try: deployer.deploy(contract_version="earliest", **overrides) except ValidationError: pass # Skip errors related to initialization
def deploy_base_contract(blockchain_interface: BlockchainDeployerInterface, deployer: BaseContractDeployer, skipt_test: bool): contract_name = deployer.contract_name latest_version, _data = blockchain_interface.find_raw_contract_data(contract_name, "latest") try: overrides = CONSTRUCTOR_OVERRIDES[contract_name][latest_version] except KeyError: overrides = dict() version = "latest" if skipt_test else "earliest" try: deployer.deploy(contract_version=version, deployment_mode=constants.FULL, **overrides) except ValidationError: pass # Skip errors related to initialization
def test_multiversion_contract(): # Prepare compiler base_dir = os.path.join(dirname(abspath(__file__)), "contracts", "multiversion") v1_dir = os.path.join(base_dir, "v1") v2_dir = os.path.join(base_dir, "v2") root_dir = SolidityCompiler.default_contract_dir() solidity_compiler = SolidityCompiler(source_dirs=[ SourceDirs(root_dir, {v2_dir}), SourceDirs(root_dir, {v1_dir}) ]) # Prepare chain blockchain_interface = BlockchainDeployerInterface( provider_uri='tester://pyevm/2', compiler=solidity_compiler) blockchain_interface.connect() origin = blockchain_interface.client.accounts[0] blockchain_interface.transacting_power = TransactingPower( password=INSECURE_DEVELOPMENT_PASSWORD, 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
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
def test_deployer_interface_multiversion_contract(): # Prepare compiler base_dir = TEST_MULTIVERSION_CONTRACTS v1_dir, v2_dir = base_dir / 'v1', base_dir / 'v2' # TODO: Check type of sources # I am a contract administrator and I an compiling a new updated version of an existing contract... # Represents "Manually hardcoding" a new source directory on BlockchainDeployerInterface.SOURCES. BlockchainDeployerInterface.SOURCES = (SourceBundle(base_path=v1_dir), SourceBundle(base_path=v2_dir)) # Prepare chain BlockchainInterfaceFactory._interfaces.clear() blockchain_interface = BlockchainDeployerInterface( provider_uri='tester://pyevm', gas_strategy='free') blockchain_interface.connect() BlockchainInterfaceFactory.register_interface( interface=blockchain_interface) # Lets this test run in isolation origin = blockchain_interface.client.accounts[0] transacting_power = TransactingPower( password=INSECURE_DEVELOPMENT_PASSWORD, signer=Web3Signer(blockchain_interface.client), account=origin) # 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( transacting_power=transacting_power, 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( transacting_power=transacting_power, 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( transacting_power=transacting_power, 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( transacting_power=transacting_power, 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( transacting_power=transacting_power, registry=registry, contract_name=contract_name) assert contract.version == "v1.2.3" assert contract.functions.VERSION().call() == 2