Example #1
0
    def registrar(self):
        RegistrarFactory = get_registrar(self.web3)
        deploy_txn_hash = RegistrarFactory.deploy()
        registrar_address = self.wait.for_contract_address(deploy_txn_hash)
        registrar = RegistrarFactory(address=registrar_address)

        return registrar
Example #2
0
def test_deploy_registrar_operation(web3, chain):
    registrar_deploy_txn = DeployRegistrar().execute(chain=chain)['deploy-transaction-hash']
    registrar_address = chain.wait.for_contract_address(registrar_deploy_txn, timeout=30)

    assert registrar_address

    registrar = get_registrar(web3, registrar_address)

    assert registrar
Example #3
0
 def registrar(self):
     if not self.has_registrar:
         raise KeyError(
             "The configuration for the {0} chain does not include a "
             "registrar.  Please set this value to the address of the "
             "deployed registrar contract.".format(self.chain_name))
     return get_registrar(
         self.web3,
         address=self.config['registrar'],
     )
Example #4
0
 def RegistrarFactory(self):
     return get_registrar(self.web3)
Example #5
0
def test_migrate_cmd(project_dir, write_project_file, MATH):
    class MigrationA(migrations.Migration):
        migration_id = '0001_deploy_math'
        dependencies = []

        operations = [
            migrations.DeployContract('Math'),
        ]

        compiled_contracts = {
            'Math': MATH,
        }

    class MigrationB(migrations.Migration):
        migration_id = '0002_increment'
        dependencies = ['0001_deploy_math']

        operations = [
            migrations.TransactContract(
                contract_name='Math',
                method_name='increment',
                arguments=[3],
                contract_address=migrations.Address.defer(key='contract/Math'),
                timeout=30,
            ),
        ]

        compiled_contracts = {
            'Math': MATH,
        }


    write_project_file('contracts/Math.sol', MATH['source'])
    write_project_file('migrations/__init__.py')

    migration_0001_path = os.path.join(
        project_dir, 'migrations', '0001_deploy_math.py',
    )
    with open(migration_0001_path, 'w') as migration_0001:
        write_migration(migration_0001, MigrationA)

    migration_0002_path = os.path.join(
        project_dir, 'migrations', '0002_increment.py',
    )
    with open(migration_0002_path, 'w') as migration_0002:
        write_migration(migration_0002, MigrationB)

    write_project_file('populus.ini', '[chain:local_a]')

    project = Project()

    # sanity
    assert len(project.migrations) == 2

    with project.get_chain('local_a') as chain:
        chain.wait.for_unlock(chain.web3.eth.coinbase, timeout=30)
        project.config.set('chain:local_a', 'deploy_from', chain.web3.eth.coinbase)
        RegistrarFactory = get_registrar(web3=chain.web3)
        deploy_transaction_hash = RegistrarFactory.deploy()
        registrar_address = chain.wait.for_contract_address(deploy_transaction_hash, timeout=60)
        project.config.set('chain:local_a', 'registrar', registrar_address)
        project.write_config()

    runner = CliRunner()
    result = runner.invoke(main, ['migrate', 'local_a'])

    assert result.exit_code == 0, result.output + str(result.exception)

    with project.get_chain('local_a') as chain:
        registrar = chain.registrar
        math_address = registrar.call().getAddress('contract/Math')
        Math = chain.contract_factories.Math(address=math_address)
        assert Math.call().counter() == 3
def test_migrate_cmd(project_dir, write_project_file, MATH):
    class MigrationA(migrations.Migration):
        migration_id = '0001_deploy_math'
        dependencies = []

        operations = [
            migrations.DeployContract('Math'),
        ]

        compiled_contracts = {
            'Math': MATH,
        }

    class MigrationB(migrations.Migration):
        migration_id = '0002_increment'
        dependencies = ['0001_deploy_math']

        operations = [
            migrations.TransactContract(
                contract_name='Math',
                method_name='increment',
                arguments=[3],
                contract_address=migrations.Address.defer(key='contract/Math'),
                timeout=30,
            ),
        ]

        compiled_contracts = {
            'Math': MATH,
        }

    write_project_file('contracts/Math.sol', MATH['source'])
    write_project_file('migrations/__init__.py')

    migration_0001_path = os.path.join(
        project_dir,
        'migrations',
        '0001_deploy_math.py',
    )
    with open(migration_0001_path, 'w') as migration_0001:
        write_migration(migration_0001, MigrationA)

    migration_0002_path = os.path.join(
        project_dir,
        'migrations',
        '0002_increment.py',
    )
    with open(migration_0002_path, 'w') as migration_0002:
        write_migration(migration_0002, MigrationB)

    write_project_file('populus.ini', '[chain:local_a]')

    project = Project()

    # sanity
    assert len(project.migrations) == 2

    with project.get_chain('local_a') as chain:
        chain.wait.for_unlock(chain.web3.eth.coinbase, timeout=30)
        project.config.set('chain:local_a', 'deploy_from',
                           chain.web3.eth.coinbase)
        RegistrarFactory = get_registrar(web3=chain.web3)
        deploy_transaction_hash = RegistrarFactory.deploy()
        registrar_address = chain.wait.for_contract_address(
            deploy_transaction_hash, timeout=60)
        project.config.set('chain:local_a', 'registrar', registrar_address)
        project.write_config()

    runner = CliRunner()
    result = runner.invoke(main, ['migrate', 'local_a'])

    assert result.exit_code == 0, result.output + str(result.exception)

    with project.get_chain('local_a') as chain:
        registrar = chain.registrar
        math_address = registrar.call().getAddress('contract/Math')
        Math = chain.contract_factories.Math(address=math_address)
        assert Math.call().counter() == 3