예제 #1
0
def addresses():
    rpc = RPC()
    enckey = rpc.wallet.enckey()
    os.environ['ENCKEY'] = enckey
    rpc.wallet.sync()
    stakings = rpc.address.list(type='staking')
    transfers = rpc.address.list(type='transfer')
    addrs = TestAddresses(
        stakings[0],
        stakings[1],
        transfers[0],
        transfers[1],
    )

    state = rpc.staking.state(addrs.unbonded_staking)
    if int(state['unbonded']) > 0:
        rpc.staking.withdraw_all_unbonded(addrs.unbonded_staking,
                                          addrs.transfer1)
        time.sleep(2)
        rpc.wallet.sync()
        balance = rpc.wallet.balance()
        assert int(balance["total"]) > 0
    else:
        balance = rpc.wallet.balance()
    # wait for the pending amount become available
    loop = 0
    while int(balance["pending"]) != 0 and loop < 60:
        rpc.wallet.sync()
        balance = rpc.wallet.balance()
        time.sleep(1)
        loop += 1
    assert int(balance["available"]) > 0
    return addrs
예제 #2
0
def get_rpc(i=0):
    rpc = _rpc_cache.get(i)
    if rpc is None:
        from chainrpc import RPC
        base_port = int(os.environ.get('BASE_PORT', 26650))
        rpc = RPC(
            os.path.join(os.path.dirname(__file__),
                         '../data/node%d/wallet' % i), base_port + 7)
        _rpc_cache[i] = rpc
    return rpc
예제 #3
0
    def __init__(self):
        self.rpc = RPC()
        self.blockchain = Blockchain()
        # wallet a
        self.node0_address = ""
        self.node0_mnemonics = ""

        # wallet b
        self.node1_address = ""
        self.node1_mnemonics = ""
        self.headers = {
            'Content-Type': 'application/json',
        }
예제 #4
0
def addresses():
    rpc = RPC()
    rpc.wallet.sync()
    addrs = TestAddresses(
        rpc.address.list(type='staking')[1],
        rpc.address.list(type='transfer')[0],
        rpc.address.list(type='transfer')[1],
    )

    state = rpc.staking.state(addrs.staking)
    if int(state['unbonded']) > 0:
        rpc.staking.withdraw_all_unbonded(addrs.staking, addrs.transfer1)
        rpc.wallet.sync()
        assert rpc.wallet.balance() > 0
    return addrs
예제 #5
0
- withdraw and deposit
- re-join
- check validators 3
'''

# keep these values same as jail_cluster.json
TARGET_NODE = 'node2'
TARGET_NODE_MNEMONIC = 'symptom labor zone shrug chicken bargain hood define tornado mass inquiry rural step color guitar'
TARGET_NODE_VALIDATOR_SEED = '5c1b9c06ae7485cd0f9d75819f964db3b1306ebd397f5bbdc1dd386a32b7c1c0'
MISSED_BLOCK_THRESHOLD = 5
JAIL_DURATION = 10
BASE_PORT = int(os.environ.get('BASE_PORT', 25560))
TARGET_PORT = BASE_PORT + 2 * 10

supervisor = UnixStreamXMLRPCClient('data/supervisor.sock')
rpc = RPC(BASE_PORT)

# wait for 3 validators online
print('Wait for 3 validators online')
wait_for_validators(rpc, 3)

enckey = rpc.wallet.restore(TARGET_NODE_MNEMONIC, name='target')

print('Stop', TARGET_NODE)
stop_node(supervisor, TARGET_NODE)

print('Waiting for', MISSED_BLOCK_THRESHOLD + 3, 'blocks')
wait_for_blocks(rpc, MISSED_BLOCK_THRESHOLD + 3)

assert len(rpc.chain.validators()['validators']) == 2
예제 #6
0
import os
import time
from chainrpc import RPC
from uuid import uuid1

rpc = RPC()


def test_watch_only_wallet(addresses):
    name = str(uuid1())
    print('name', name)
    enckey, _ = rpc.wallet.create(name)

    view_key_pub = rpc.wallet.view_key(name, enckey=enckey)
    view_key_priv = rpc.wallet.view_key(name, private=True, enckey=enckey)
    transfer_pubkey = rpc.wallet.list_pubkey(name, enckey=enckey)[0]
    transfer_addr = rpc.address.list(name, type='transfer', enckey=enckey)[0]

    name = 'watch_' + name
    enckey = rpc.wallet.restore_basic(view_key_priv, name=name)
    assert rpc.wallet.view_key(name, enckey=enckey) == view_key_pub

    assert rpc.address.create_watch(transfer_pubkey,
                                    name=name,
                                    type='transfer',
                                    enckey=enckey) == transfer_addr

    amount = 10000000
    rpc.wallet.send(transfer_addr,
                    amount,
                    view_keys=[view_key_pub],
예제 #7
0
#!/usr/bin/env python3
import time
import pexpect
import os
import tempfile
import pytest
from chainrpc import RPC
from .common import wait_for_tx, wait_for_blocktime

rpc = RPC()

PASSWD = "123456"
rpc = RPC()

# TODO:it strange that python can not read client-cli output, so deadcode the information
# ./client-cli wallet auth-token -n ${wallet_name}
enckey_offline = "3504eaa586fb548261613c7d9a4dfbadcb52ae26aff3c7e2b9ad88f03db7ee93"
# ./client-cli address new -n ${wallet_name} -t transfer
transfer_address_offline = "dcro1kxl8xy6k8twhes6j972mrzurfvgms0e549z852cgqyl796jss89sadlmgd"
# ./client-cli address list-pub-key -n ${wallet_name} -t transfer
transfer_pubkey_offline = "02a732fb6c34812ea5a46547344d63a360e22d0c4815c837af82a09de7b7fd9797"
view_key_offline = "02b4dabfc862b9cb9f86b8d49520023aa0cccb2ad89446577dd0fee7bc946a79a1"
# ./client-cli view-key -p -n ${wallet_name}
priv_view_key_offline = "3aefe25d235b86e2ec25d0a0ee73267e0a0f10f62a4d96df42fc9e7b2f6cbef3"


def create_wallet_offline_wallet(storage_path):
    '''
    - create temp wallet with unique name
    - read view key and transfer address
    return [wallet_name, view_key_priv, transfer_pubkey]