Esempio n. 1
0
 def deploy(self, term: str, phlo_limit: int, phlo_price: int,
            valid_after_block_number: int, deployer: PrivateKey) -> str:
     timestamp = int(time.time() * 1000)
     deploy_data = {
         "term": term,
         "timestamp": timestamp,
         "phloLimit": phlo_limit,
         "phloPrice": phlo_price,
         "validAfterBlockNumber": valid_after_block_number
     }
     deploy_proto = DeployDataProto(
         term=term,
         timestamp=timestamp,
         phloLimit=phlo_limit,
         phloPrice=phlo_price,
         validAfterBlockNumber=valid_after_block_number)
     deploy_req = {
         "data": deploy_data,
         "deployer": deployer.get_public_key().to_hex(),
         "signature": sign_deploy_data(deployer, deploy_proto).hex(),
         "sigAlgorithm": "secp256k1"
     }
     deploy_url = self.url + '/deploy'
     rep = requests.post(deploy_url, json=deploy_req)
     _check_reponse(rep)
     return rep.text
Esempio n. 2
0
def test_sign_deploy(key: PrivateKey, terms: str, phlo_price: int, phlo_limit: int, valid_after_block_no: int,
                     timestamp_millis: int):
    runner = CliRunner()
    result = runner.invoke(cli, ['sign-deploy', '--private-key', key.to_hex(),
                                 '--term', terms,
                                 "--phlo-price", phlo_price,
                                 "--phlo-limit", phlo_limit,
                                 "--valid-after-block-number", valid_after_block_no,
                                 "--timestamp", timestamp_millis,
                                 "--sig-algorithm", "secp256k1"
                                 ])
    assert result.exit_code == 0
    sig = result.output.strip()

    data = DeployDataProto(
        deployer=key.get_public_key().to_bytes(),
        term=terms,
        phloPrice=phlo_price,
        phloLimit=phlo_limit,
        validAfterBlockNumber=valid_after_block_no,
        timestamp=timestamp_millis,
        sigAlgorithm='secp256k1',
    )
    assert verify_deploy_data(key.get_public_key(), bytes.fromhex(sig), data)
Esempio n. 3
0
def test_client_deploy(key: PrivateKey, terms: str, phlo_price: int,
                       phlo_limit: int, valid_after_block_no: int,
                       timestamp_millis: int) -> None:
    class DummyDeploySerivce(DeployServiceServicer):
        def doDeploy(self, request: DeployDataProto,
                     context: grpc.ServicerContext) -> DeployResponse:
            return DeployResponse(result=request.sig.hex())

    with deploy_service(DummyDeploySerivce()) as (server, port), \
            RClient(TEST_HOST, port) as client:
        ret = client.deploy(key, terms, phlo_price, phlo_limit,
                            valid_after_block_no, timestamp_millis)
        assert verify_deploy_data(
            key.get_public_key(), bytes.fromhex(ret),
            create_deploy_data(key, terms, phlo_price, phlo_limit,
                               valid_after_block_no, timestamp_millis))
Esempio n. 4
0
def test_submit_deploy(key: PrivateKey, terms: str, phlo_price: int, phlo_limit: int, valid_after_block_no: int,
                       timestamp_millis: int):
    class DummyDeploySerivce(DeployServiceServicer):
        def doDeploy(self, request: DeployDataProto, context: grpc.ServicerContext) -> DeployResponse:
            return DeployResponse(result=request.sig.hex())

    with deploy_service(DummyDeploySerivce()) as (server, port):
        runner = CliRunner()
        result = runner.invoke(cli, ['submit-deploy', '--deployer', key.get_public_key().to_hex(),
                                     '--term', terms,
                                     "--phlo-price", phlo_price,
                                     "--phlo-limit", phlo_limit,
                                     "--valid-after-block-number", valid_after_block_no,
                                     "--timestamp", timestamp_millis,
                                     "--sig-algorithm", "secp256k1",
                                     "--sig", "1111",
                                     "--host", 'localhost',
                                     "--port", port
                                     ])
        assert result.exit_code == 0
Esempio n. 5
0
def make_peer(
    *,
    docker_client: DockerClient,
    network: str,
    name: str,
    bonds_file: str,
    command_timeout: int,
    bootstrap: Node,
    private_key: PrivateKey,
    allowed_peers: Optional[List[str]] = None,
    mem_limit: Optional[str] = None,
    wallets_file: Optional[str] = None,
    cli_flags: Optional[AbstractSet] = None,
    cli_options: Optional[Dict] = None,
    extra_volumes: Optional[List[str]] = None,
    synchrony_constraint_threshold: float = 0.0,
    max_peer_queue_size: int = 10,
    give_up_after_skipped: int = 0,
    drop_peer_after_retries: int = 0,
    number_of_active_validators: int = 10,
    epoch_length: int = 10000,
    quarantine_length: int = 50000
) -> Node:
    assert isinstance(name, str)
    assert '_' not in name, 'Underscore is not allowed in host name'
    name = make_peer_name(network, name)

    bootstrap_address = bootstrap.get_rnode_address()

    container_command_flags = set([
        "--prometheus",
        "--no-upnp",
        "--allow-private-addresses"
    ])

    if cli_flags is not None:
        container_command_flags.update(cli_flags)

    container_command_options = {
        "--bootstrap":                      bootstrap_address,
        "--validator-private-key":          private_key.to_hex(),
        "--validator-public-key":           private_key.get_public_key().to_hex(),
        "--host":                           name,
        "--synchrony-constraint-threshold": synchrony_constraint_threshold,
        "--frrd-max-peer-queue-size":            max_peer_queue_size,
        "--frrd-give-up-after-skipped":          give_up_after_skipped,
        "--frrd-drop-peer-after-retries":        drop_peer_after_retries,
        "--number-of-active-validators":    number_of_active_validators,
        "--epoch-length":                   epoch_length,
        "--quarantine-length":              quarantine_length
    }

    if cli_options is not None:
        container_command_options.update(cli_options)

    container = make_node(
        docker_client=docker_client,
        name=name,
        network=network,
        bonds_file=bonds_file,
        container_command='run',
        container_command_flags=container_command_flags,
        container_command_options=container_command_options,
        command_timeout=command_timeout,
        extra_volumes=extra_volumes,
        allowed_peers=allowed_peers,
        mem_limit=mem_limit if not None else '4G',
        wallets_file=wallets_file,
    )
    return container
Esempio n. 6
0
def add_funds(rgov: rgovAPI, key: PrivateKey, rev: int):
    one = 100000000
    bal = rgov.checkBalance(key.get_public_key().get_rev_address())
    if bal < one:
        rgov.transfer(admin.get_public_key().get_rev_address(),
                      key.get_public_key().get_rev_address(), rev * one, admin)