Пример #1
0
def test_create_delete_schain(skale):
    schains_ids = skale.schains_data.get_all_schains_ids()

    type_of_nodes, lifetime_seconds, name = generate_random_schain_data()
    price_in_wei = skale.schains.get_schain_price(type_of_nodes,
                                                  lifetime_seconds)
    res = skale.manager.create_schain(lifetime_seconds, type_of_nodes,
                                      price_in_wei, name)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1

    schains_ids_number_after = skale.schains_data.get_schains_number()
    assert schains_ids_number_after == len(schains_ids) + 1
    schains_ids_after = skale.schains_data.get_all_schains_ids()

    schains_names = [
        skale.schains_data.get(sid)['name']
        for sid in schains_ids_after
    ]
    assert name in schains_names

    res = skale.manager.delete_schain(name)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1

    schains_ids_number_after = skale.schains_data.get_schains_number()
    assert schains_ids_number_after == len(schains_ids)
    schains_ids_after = skale.schains_data.get_all_schains_ids()

    schains_names = [
        skale.schains_data.get(sid)['name']
        for sid in schains_ids_after
    ]
    assert name not in schains_names
Пример #2
0
def create_node():
    ip, public_ip, port, name = generate_random_node_data()
    port = 10000
    res = skale.manager.create_node(ip, port, name, public_ip)
    receipt = wait_receipt(skale.web3, res['tx'])
    print(receipt)
    return receipt
Пример #3
0
def test_get_set_latency(skale):
    new_latency = 1000
    res = skale.constants.set_latency(new_latency)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1
    res = skale.constants.get_latency()
    assert res == new_latency
Пример #4
0
def test_get_set_check_time(skale):
    new_check_time = 100
    res = skale.constants.set_check_time(new_check_time)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1
    res = skale.constants.get_check_time()
    assert res == new_check_time
Пример #5
0
def remove(ctx, schain_name):
    """ Command that removes schain by name """
    # TODO: check if this function works
    skale = ctx.obj['skale']
    res = skale.manager.delete_schain(schain_name)
    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)
    print(f'sChain {schain_name} removed!')
Пример #6
0
def test_get_set_periods(skale):
    res = skale.constants.set_periods(NEW_REWARD_PERIOD, NEW_DELTA_PERIOD)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1
    reward_period = skale.constants.get_reward_period()
    delta_period = skale.constants.get_delta_period()
    assert reward_period == NEW_REWARD_PERIOD
    assert delta_period == NEW_DELTA_PERIOD
Пример #7
0
def remove(ctx, node_name):
    """ Command to remove node spcified by name """
    skale = ctx.obj['skale']

    node_id = skale.nodes_data.node_name_to_index(node_name)
    res = skale.manager.delete_node_by_root(node_id)

    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)
Пример #8
0
def test_create_node_delete_node_by_root(skale):
    active_node_ids_before = skale.nodes_data.get_active_node_ids()

    ip, public_ip, port, name = generate_random_node_data()
    res = skale.manager.create_node(ip, port, name)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1

    active_node_ids_after = skale.nodes_data.get_active_node_ids()
    assert len(active_node_ids_after) == len(active_node_ids_before) + 1

    node_idx = skale.nodes_data.node_name_to_index(name)

    res = skale.manager.delete_node_by_root(node_idx)
    receipt = wait_receipt(skale.web3, res['tx'])
    assert receipt['status'] == 1
    active_node_ids_after = skale.nodes_data.get_active_node_ids()
    assert len(active_node_ids_after) == len(active_node_ids_before)
Пример #9
0
def cancel_pending_delegation(delegation_id: int, pk_file: str) -> None:
    skale = init_skale_w_wallet_from_config(pk_file)
    if not skale:
        return
    with yaspin(text='Canceling delegation request', color=SPIN_COLOR) as sp:
        tx_res = skale.delegation_service.cancel_pending_delegation(
            delegation_id=delegation_id)
        receipt = wait_receipt(skale.web3, tx_res.hash)
        if not check_receipt(receipt, raise_error=False):
            sp.write(f'Transaction failed, check receipt: {tx_res.hash}')
            return
        sp.write("✔ Delegation request canceled")
Пример #10
0
def create_schain(skale):
    type_of_nodes, lifetime_seconds, old_name = generate_random_schain_data()
    schain_name = generate_random_schain_name()
    price_in_wei = skale.schains.get_schain_price(type_of_nodes,
                                                  lifetime_seconds)

    res = skale.manager.create_schain(lifetime_seconds, type_of_nodes,
                                      price_in_wei, schain_name)
    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)

    schain_struct = skale.schains_data.get_by_name(schain_name)
    schain_nodes = get_nodes_for_schain_config(skale, schain_name)
    return {'schain_struct': schain_struct, 'schain_nodes': schain_nodes}
Пример #11
0
def delegate(validator_id, amount, delegation_period, info, pk_file):
    skale = init_skale_w_wallet_from_config(pk_file)
    if not skale:
        return
    with yaspin(text='Sending delegation request', color=SPIN_COLOR) as sp:
        tx_res = skale.delegation_service.delegate(
            validator_id=validator_id,
            amount=amount,
            delegation_period=delegation_period,
            info=info)
        receipt = wait_receipt(skale.web3, tx_res.hash)
        if not check_receipt(receipt, raise_error=False):
            sp.write(f'Transaction failed, check receipt: {tx_res.hash}')
            return
        sp.write("✔ Delegation request sent")
Пример #12
0
def test_transfer(skale, empty_account):
    receiver_balance = skale.token.get_balance(empty_account.address)
    sender_balance = skale.token.get_balance(skale.wallet.address)

    assert receiver_balance == 0
    assert sender_balance != 0

    res = skale.token.transfer(empty_account.address, TOKEN_TRANSFER_VALUE)
    receipt = wait_receipt(skale.web3, res['tx'])

    assert receipt['status'] == 1

    receiver_balance_after = skale.token.get_balance(empty_account.address)
    sender_balance_after = skale.token.get_balance(skale.wallet.address)

    assert receiver_balance_after == TOKEN_TRANSFER_VALUE
    assert sender_balance_after == sender_balance - TOKEN_TRANSFER_VALUE
Пример #13
0
def token_transfer(skale, address_to, tokens_amount):
    address_from = Web3.toChecksumAddress(skale.wallet.address)
    address_to = Web3.toChecksumAddress(address_to)
    balance_from_before = skale.token.get_balance(address_from)
    balance_to_before = skale.token.get_balance(address_to)
    print('Balance from before {}'.format(balance_from_before))
    print('Balance to before {}'.format(balance_to_before))

    res = skale.token.transfer(address_to, tokens_amount)
    receipt = wait_receipt(skale.web3, res['tx'])
    check_receipt(receipt)

    balance_from_after = skale.token.get_balance(address_from)
    balance_to_after = skale.token.get_balance(address_to)
    print('Balance from after {}'.format(balance_from_after))
    print('Balance to after {}'.format(balance_to_after))
    diff_from = balance_from_before - balance_from_after
    diff_to = balance_to_after - balance_to_before
    assert diff_from == diff_to
    return receipt
Пример #14
0
def check_tx_result(tx_hash, web3):
    receipt = wait_receipt(web3, tx_hash)
    return check_receipt(receipt, raise_error=False)