예제 #1
0
def test_mining(init_session, setup_network):
    current_index = get_curr_ind()
    ns = init_session
    layer_avg_size = testconfig['client']['args']['layer-average-size']
    layers_per_epoch = int(testconfig['client']['args']['layers-per-epoch'])
    # check only third epoch
    epochs = 5
    last_layer = epochs * layers_per_epoch

    total_pods = len(setup_network.clients.pods) + len(
        setup_network.bootstrap.pods)

    layer_reached = queries.wait_for_latest_layer(testconfig["namespace"],
                                                  last_layer, layers_per_epoch,
                                                  total_pods)

    tts = 50
    sleep_print_backwards(tts)

    analyse.analyze_mining(testconfig['namespace'], layer_reached,
                           layers_per_epoch, layer_avg_size, total_pods)

    queries.assert_equal_layer_hashes(current_index, ns)
    queries.assert_equal_state_roots(current_index, ns)
    queries.assert_no_contextually_invalid_atxs(current_index, ns)
    validate_hare(current_index, ns)  # validate hare
예제 #2
0
def test_tx_stress(init_session, setup_network):
    wallet_api = WalletAPI(init_session,
                           setup_network.clients.pods,
                           fixed_node=-1)
    tap_balance = wallet_api.get_balance_value(conf.acc_pub)
    tap_acc = Accountant.set_tap_acc(balance=tap_balance)
    accountant = Accountant({conf.acc_pub: tap_acc},
                            tap_init_amount=tap_balance)

    # create 100 accounts
    new_accounts = 100
    amount = 50
    print(
        f"\n\n----- create {new_accounts} new accounts with {amount} coins for each -----"
    )
    actions.send_coins_to_new_accounts(wallet_api, new_accounts, amount,
                                       accountant)

    layer_duration = int(testconfig["client"]["args"]["layer-duration-sec"])
    tts = layer_duration * conf.num_layers_until_process
    sleep_print_backwards(tts)

    print("\n\n----- wait for next layer to start -----")
    cl_num = len(setup_network.clients.pods) + 1  # adding 1 for bootstrap
    wait_for_next_layer(init_session, cl_num, layer_duration)

    tx_num = new_accounts
    print(
        f"\n\n----- send {tx_num} new transactions during the current layer -----"
    )
    actions.send_tx_from_each_account(wallet_api,
                                      accountant,
                                      tx_num,
                                      is_concurrent=True)

    tts = layer_duration * conf.num_layers_until_process
    sleep_print_backwards(tts)

    print(f"\n\n----- validate all accounts nonce and balance -----")
    for acc_pub in accountant.accounts:
        ass_err = f"account {acc_pub} did not have the matching balance"
        assert actions.validate_acc_amount(wallet_api, accountant,
                                           acc_pub), ass_err

    for acc_pub in accountant.accounts:
        ass_err = f"account {acc_pub} did not have the matching nonce"
        assert actions.validate_nonce(wallet_api, accountant, acc_pub), ass_err
예제 #3
0
def send_random_txs(wallet, accountant, amount=1):
    max_tts = 10
    max_rnd_txs = 50

    while True:
        # use same pod for all GRPCs
        wallet.fixed_node = None
        if bool(random.getrandbits(1)):
            wallet.fixed_node = -1

        is_concurrent = bool(random.getrandbits(1))
        tx_num = random.randint(1, max_rnd_txs)
        send_tx_from_each_account(wallet,
                                  accountant,
                                  tx_num,
                                  amount=amount,
                                  gas_limit=None,
                                  is_new_acc=False,
                                  is_concurrent=is_concurrent)
        tts = random.randint(3, max_tts)
        sleep_print_backwards(tts)
예제 #4
0
def test_transactions(init_session, setup_network):
    # create #new_acc_num new accounts by sending them coins from tap
    # check tap balance/nonce
    # sleep until new state is processed
    # send txs from new accounts and create new accounts
    # sleep until new state is processes
    # validate all accounts balance/nonce
    # send txs from all accounts between themselves
    # validate all accounts balance/nonce

    namespace = init_session
    wallet_api = WalletAPI(namespace, setup_network.clients.pods)

    tap_bal = wallet_api.get_balance_value(tx_gen_conf.acc_pub)
    tap_nonce = wallet_api.get_nonce_value(tx_gen_conf.acc_pub)
    tap_pub = tx_gen_conf.acc_pub
    acc = Accountant(
        {tap_pub: Accountant.set_tap_acc(balance=tap_bal, nonce=tap_nonce)},
        tap_init_amount=tap_bal)

    print("\n\n----- create new accounts ------")
    new_acc_num = 10
    amount = 50
    actions.send_coins_to_new_accounts(wallet_api, new_acc_num, amount, acc)

    print("assert tap's nonce and balance")
    ass_err = "tap did not have the matching nonce"
    assert actions.validate_nonce(wallet_api, acc,
                                  tx_gen_conf.acc_pub), ass_err
    ass_err = "tap did not have the matching balance"
    assert actions.validate_acc_amount(wallet_api, acc,
                                       tx_gen_conf.acc_pub), ass_err

    layer_duration = int(testconfig['client']['args']['layer-duration-sec'])
    tts = layer_duration * tx_gen_conf.num_layers_until_process
    sleep_print_backwards(tts)

    print(
        "\n\n------ create new accounts using the accounts created by tap ------"
    )
    # add 1 because we have #new_acc_num new accounts and one tap
    tx_num = new_acc_num + 1
    amount = 5
    actions.send_tx_from_each_account(wallet_api,
                                      acc,
                                      tx_num,
                                      is_new_acc=True,
                                      amount=amount)

    tts = layer_duration * tx_gen_conf.num_layers_until_process
    sleep_print_backwards(tts)

    for acc_pub in acc.accounts:
        ass_err = f"account {acc_pub} did not have the matching balance"
        assert actions.validate_acc_amount(wallet_api, acc, acc_pub), ass_err

    for acc_pub in acc.accounts:
        ass_err = f"account {acc_pub} did not have the matching nonce"
        assert actions.validate_nonce(wallet_api, acc, acc_pub), ass_err

    print("\n\n------ send txs between all accounts ------")
    # send coins from all accounts between themselves (add 1 for tap)
    tx_num = new_acc_num * 2 + 1
    actions.send_tx_from_each_account(wallet_api, acc, tx_num)

    tts = layer_duration * tx_gen_conf.num_layers_until_process
    sleep_print_backwards(tts)

    for acc_pub in acc.accounts:
        ass_err = f"account {acc_pub} did not have the matching balance"
        assert actions.validate_acc_amount(wallet_api, acc, acc_pub), ass_err

    for acc_pub in acc.accounts:
        ass_err = f"account {acc_pub} did not have the matching nonce"
        assert actions.validate_nonce(wallet_api, acc, acc_pub), ass_err
예제 #5
0
def test_grpc_stress(init_session, setup_network):
    # use the same node to send all api calls (-1)
    wallet_api = WalletAPI(init_session, setup_network.clients.pods, -1)
    tap_balance = wallet_api.get_balance_value(conf.acc_pub)
    accountant = Accountant(
        {conf.acc_pub: Accountant.set_tap_acc(balance=tap_balance)},
        tap_init_amount=tap_balance)
    api_funcs_lst = [
        wallet_api.get_balance_value, wallet_api.get_nonce_value,
        wallet_api.get_tx_by_id, actions.transfer
    ]

    # create #new_accounts accounts, this will also be the number of
    # concurrent api calls
    new_accounts = 50
    amount = 50
    print(
        f"\n\n----- create {new_accounts} new accounts with {amount} coins for each -----"
    )
    actions.send_coins_to_new_accounts(wallet_api, new_accounts, amount,
                                       accountant)

    layer_duration = int(testconfig["client"]["args"]["layer-duration-sec"])
    tts = layer_duration * conf.num_layers_until_process
    sleep_print_backwards(tts)

    processes = []
    queue = mp.Queue()
    proc_counter = 0
    for func in islice(cycle(api_funcs_lst), 0, new_accounts):
        # get acc pub
        acc_pub = list(accountant.accounts.keys())[proc_counter]
        # this will be the args for wallet_api.get_balance_value and wallet_api.get_nonce_value
        args = (acc_pub, )
        if func == actions.transfer:
            dst = random.choice(list(accountant.accounts.keys()))
            balance = wallet_api.get_balance_value(acc_pub)
            amount = random.randint(1, balance - accountant.tx_cost)
            gas_price = 1
            args = (wallet_api, acc_pub, dst, amount, gas_price, None, None,
                    accountant, None, queue)
        elif func == wallet_api.get_tx_by_id:
            args = (random.choice(wallet_api.tx_ids), )

        proc_counter += 1
        processes.append(mp.Process(target=func, args=args))

    actions.run_processes(processes, accountant, queue)

    tts = layer_duration * conf.num_layers_until_process
    sleep_print_backwards(tts)

    print(f"\n\n----- validate all accounts nonce and balance -----")
    for acc_pub in accountant.accounts:
        ass_err = f"account {acc_pub} did not have the matching balance"
        assert actions.validate_acc_amount(wallet_api, accountant,
                                           acc_pub), ass_err

    for acc_pub in accountant.accounts:
        ass_err = f"account {acc_pub} did not have the matching nonce"
        assert actions.validate_nonce(wallet_api, accountant, acc_pub), ass_err

    errs = find_error_log_msgs(init_session, init_session)
    if errs:
        print_hits_entry_count(errs, "message")
        assert 0, "found log errors"

    assert len(errs) == 0, "found errors in logs"
예제 #6
0
    print(f"\nreceived args:\n{parsed_args}\n")

    # Get a list of active pods
    pods_lst = k8s_handler.get_clients_names_and_ips(parsed_args.namespace)
    my_wallet = WalletAPI(parsed_args.namespace, pods_lst)
    # Get TAP initial values
    tap_nonce = my_wallet.get_nonce_value(conf.acc_pub)
    tap_balance = my_wallet.get_balance_value(conf.acc_pub)
    # Create an accountant to follow state
    tap_acc = Accountant.set_tap_acc(balance=tap_balance, nonce=tap_nonce)
    acc = Accountant({conf.acc_pub: tap_acc}, tap_init_amount=tap_balance)
    acc.tx_cost = parsed_args.gas_price
    # Create new accounts by sending them coins
    actions.send_coins_to_new_accounts(my_wallet, parsed_args.new_accounts,
                                       parsed_args.amount, acc,
                                       parsed_args.gas_price)

    print(f"\n\n{pprint.pformat(acc.accounts)}\n\n")

    # Sleep for 4 layers to let new txs enter the state and new accounts to be valid
    tts = parsed_args.layer_duration * conf.num_layers_until_process
    sleep_print_backwards(tts)

    # Use same pod for every wallet api call
    if parsed_args.same_pod:
        print("Using the same pod for all txs (and nonce querying)")
        my_wallet.fixed_node = -1

    run()
    print("bye bye!")