Exemple #1
0
def test_resume_deploy_contracts(web3, auction_options,
                                 already_deployed_contract_addresses):
    if (already_deployed_contract_addresses.auction is not None
            and already_deployed_contract_addresses.locker is None):
        with pytest.raises(ValueError):
            deploy_auction_contracts(
                web3=web3,
                auction_options=auction_options,
                already_deployed_contracts=already_deployed_contract_addresses,
            )
    else:
        deployed_contracts: DeployedAuctionContracts = deploy_auction_contracts(
            web3=web3,
            auction_options=auction_options,
            already_deployed_contracts=already_deployed_contract_addresses,
        )

        if already_deployed_contract_addresses.auction is not None:
            assert (deployed_contracts.auction.address ==
                    already_deployed_contract_addresses.auction)
        if already_deployed_contract_addresses.locker is not None:
            assert (deployed_contracts.locker.address ==
                    already_deployed_contract_addresses.locker)
        if already_deployed_contract_addresses.slasher is not None:
            assert (deployed_contracts.slasher.address ==
                    already_deployed_contract_addresses.slasher)
def contracts_not_initialized(auction_options) -> DeployedAuctionContracts:
    """return the three auction related contracts where locker and slasher are not initialized"""

    contracts = deploy_auction_contracts(web3=test_json_rpc,
                                         auction_options=auction_options)

    return contracts
Exemple #3
0
def test_deploy_contracts(web3, auction_options: AuctionOptions):

    deployed_contracts: DeployedAuctionContracts = deploy_auction_contracts(
        web3=web3, auction_options=auction_options)

    assert (deployed_contracts.auction.functions.startPrice().call() ==
            auction_options.start_price)
    assert (deployed_contracts.auction.functions.auctionDurationInDays().call(
    ) == auction_options.auction_duration)
    assert (deployed_contracts.auction.functions.minimalNumberOfParticipants().
            call() == auction_options.minimal_number_of_participants)
    assert (deployed_contracts.auction.functions.maximalNumberOfParticipants().
            call() == auction_options.maximal_number_of_participants)

    assert deployed_contracts.locker.functions.initialized().call() is False

    assert deployed_contracts.slasher.functions.initialized().call() is False
Exemple #4
0
def deploy(
    start_price: int,
    auction_duration: int,
    minimal_number_of_participants: int,
    maximal_number_of_participants: int,
    release_timestamp: int,
    release_date: pendulum.DateTime,
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
) -> None:

    if release_date is not None and release_timestamp is not None:
        raise click.BadParameter(
            f"Both --release-date and --release-timestamp have been specified")
    if release_date is None and release_timestamp is None:
        raise click.BadParameter(
            f"Please specify a release date with --release-date or --release-timestamp"
        )

    if release_date is not None:
        release_timestamp = int(release_date.timestamp())

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    auction_options = AuctionOptions(
        start_price * ETH_IN_WEI,
        auction_duration,
        minimal_number_of_participants,
        maximal_number_of_participants,
        release_timestamp,
    )

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    contracts = deploy_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        auction_options=auction_options,
    )

    initialize_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        contracts=contracts,
        release_timestamp=release_timestamp,
        private_key=private_key,
    )

    click.echo("Auction address: " + contracts.auction.address)
    click.echo("Deposit locker address: " + contracts.locker.address)
    click.echo("Validator slasher address: " + contracts.slasher.address)
def deploy(
    start_price: int,
    auction_duration: int,
    minimal_number_of_participants: int,
    maximal_number_of_participants: int,
    use_token: bool,
    token_address: Optional[str],
    release_timestamp: int,
    release_date: pendulum.DateTime,
    keystore: str,
    jsonrpc: str,
    gas: int,
    gas_price: int,
    nonce: int,
    auto_nonce: bool,
    already_deployed_auction,
    already_deployed_locker,
    already_deployed_slasher,
) -> None:

    if use_token and token_address is None:
        raise click.BadParameter(
            "The flag `use-token` was provided, the token address must also be provided via `token-address`"
        )
    if token_address is not None and not use_token:
        raise click.BadParameter(
            "A token address has been provided, "
            "please use the flag --use-token to confirm you want to deploy a token auction"
        )

    if release_date is not None and release_timestamp is not None:
        raise click.BadParameter(
            "Both --release-date and --release-timestamp have been specified")
    if release_date is None and release_timestamp is None:
        raise click.BadParameter(
            "Please specify a release date with --release-date or --release-timestamp"
        )

    if already_deployed_auction is not None and already_deployed_locker is None:
        raise click.BadOptionUsage(
            "--auction",
            "Cannot resume deployment from already deployed auction without already deployed locker. "
            "Locker address is part of auction's constructor argument.",
        )

    if release_date is not None:
        release_timestamp = int(release_date.timestamp())

    web3 = connect_to_json_rpc(jsonrpc)
    private_key = retrieve_private_key(keystore)

    auction_options = AuctionOptions(
        start_price * ETH_IN_WEI,
        auction_duration,
        minimal_number_of_participants,
        maximal_number_of_participants,
        release_timestamp,
        token_address,
    )

    nonce = get_nonce(web3=web3,
                      nonce=nonce,
                      auto_nonce=auto_nonce,
                      private_key=private_key)
    transaction_options = build_transaction_options(gas=gas,
                                                    gas_price=gas_price,
                                                    nonce=nonce)

    contracts = deploy_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        private_key=private_key,
        auction_options=auction_options,
        already_deployed_contracts=DeployedContractsAddresses(
            already_deployed_locker, already_deployed_slasher,
            already_deployed_auction),
    )

    initialize_auction_contracts(
        web3=web3,
        transaction_options=transaction_options,
        contracts=contracts,
        release_timestamp=release_timestamp,
        token_address=token_address,
        private_key=private_key,
    )
    slasher: Contract = contracts.slasher

    click.echo("Auction address: " + contracts.auction.address)
    click.echo("Deposit locker address: " + contracts.locker.address)
    click.echo("Validator slasher address: " + slasher.address)
    warning_messages = get_errors_messages_on_contracts_links(contracts)
    if warning_messages:
        warning_messages.append(
            "Verify what is wrong with `auction-deploy status`.")
        click.secho(linesep.join(warning_messages), fg="red")
Exemple #6
0
def deployed_contracts(web3, auction_options):

    deployed_contracts: DeployedAuctionContracts = deploy_auction_contracts(
        web3=web3, auction_options=auction_options)

    return deployed_contracts