Example #1
0
def StartNodeConfig(datadir, comment=""):
    _lib.StartTestGroup("Start node " + comment)

    _lib.StartTest("Start normal")
    res = _lib.ExecuteNode(['startnode', '-configdir', datadir])
    _lib.FatalAssertStr(res, "", "Should not be any output on succes start")

    # get process of the node. find this process exists
    _lib.StartTest("Check node state")
    res = _lib.ExecuteNode(['nodestate', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Server is running",
                           "Server should be runnning")

    # get address from this response
    match = re.search(r'Process: (\d+),', res, re.M)

    if not match:
        _lib.Fatal("Can not get process ID from the response " + res)

    PID = int(match.group(1))

    _lib.FatalAssertPIDRunning(PID, "Can not find process with ID " + str(PID))

    _lib.StartTest("Start node again. should not be allowed")
    res = _lib.ExecuteNode(['startnode', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Already running or PID file exists",
                           "Second attempt to run should fail")
Example #2
0
def ImportBockchain(datadir, host, port):
    _lib.StartTestGroup("Import blockchain")

    _lib.StartTest("Create first address before importing blockchain")
    res = _lib.ExecuteNode(['createwallet', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Your new address",
                           "Address creation returned wrong result")

    _lib.FatalRegex(r'.+: (.+)', res, "Address can not be found in " + res)

    # get address from this response
    match = re.search(r'.+: (.+)', res)

    if not match:
        _lib.Fatal("Address can not be found in " + res)

    address = match.group(1)

    dbconfig = _lib.GetDBCredentials(datadir)

    _lib.StartTest("Import blockchain from node 1")
    res = _lib.ExecuteNode([
        'importblockchain', '-configdir', datadir, '-nodehost', host,
        '-nodeport', port, '-mysqlhost', dbconfig['host'], '-mysqlport',
        dbconfig['port'], '-mysqluser', dbconfig['user'], '-mysqlpass',
        dbconfig['password'], '-mysqldb', dbconfig['database'], '-logs',
        'trace,error'
    ])

    _lib.FatalAssertSubstr(res, "Done!", "Blockchain init failed")

    return address
Example #3
0
def StartNodeInteractive(datadir, address, port, comment=""):
    _lib.StartTest("Start node (debug) " + comment)
    res = _lib.ExecuteHangNode([
        'startintnode', '-configdir', datadir, '-port', port, '-minter',
        address
    ], datadir)
    _lib.FatalAssertSubstr(res, "Process started", "No process start marker")
Example #4
0
def DumpBCDB(datadir, dumpfile):
    if os.path.isfile(dumpfile):
        os.remove(dumpfile)
        
    _lib.StartTest("Dump BC DB for future tests")
    res = _lib.ExecuteNode(['dumpblockchain','-configdir',datadir,'-dumpfile',dumpfile])
    _lib.FatalAssertSubstr(res,"Blockchain DB was dumped to a file","Dump was not succes")
Example #5
0
def GetBalanceWalletNoNode(datadir, address):
    _lib.StartTest("Request balance for a wallet " + address)
    res = _lib.ExecuteWallet(
        ['getbalance', '-configdir', datadir, "-address", address])
    _lib.FatalAssertSubstr(res, "Balance of", "Balance info is not found")

    return parseWalletBalance(res, address)
Example #6
0
def GetUnapprovedTransactions(datadir, skiperroronempty=False):

    _lib.StartTest("Get unapproved transactions")
    res = _lib.ExecuteNode(['unapprovedtransactions', '-configdir', datadir])

    if not skiperroronempty:
        _lib.FatalAssertSubstr(res, "--- Transaction",
                               "Output should contains list of transactions")

    regex = re.compile(ur"--- Transaction ([^:]+):(.*?)    ---", re.DOTALL)
    transactions = re.findall(regex, res)
    #print(res)
    txlist = {}

    for i in range(len(transactions)):
        tp = "CURRENCY"
        regex = ur"FROM ([A-Za-z0-9 ]+) TO ([A-Za-z0-9]+) VALUE ([0-9.]+)"
        txinfo = re.findall(regex, transactions[i][1])

        if len(txinfo) < 1:
            tp = "SQL"
            regex = ur"SQL: ([^\n]+)\n"
            #print(transactions[i][1])
            txinfo = re.findall(regex, transactions[i][1])
            txinfo = [txinfo[0]]
        else:
            txinfo = list(txinfo[0])

        txlist[transactions[i][0]] = [tp] + txinfo

    return txlist
Example #7
0
def GetUnapprovedTransactions(datadir):
    
    _lib.StartTest("Get unapproved transactions")
    res = _lib.ExecuteNode(['unapprovedtransactions','-configdir',datadir])
    
    _lib.FatalAssertSubstr(res,"--- Transaction","Output should contains list of transactions")

    regex = ur"--- Transaction ([^:]+):"

    transactions = re.findall(regex, res)

    regex = ur"FROM ([A-Za-z0-9]+) TO ([A-Za-z0-9]+) VALUE ([0-9.]+)"
    
    txinfo = re.findall(regex, res)
    
    if len(txinfo) < len(transactions):
        regex = ur"SQL: ([^\n]+)\n"
        txinfo = re.findall(regex, res)
    
    txlist={}
    
    for i in range(len(transactions)):
        txlist[transactions[i]] = txinfo[i]
    
    return txlist
Example #8
0
def StopNode(datadir, comment=""):
    _lib.StartTestGroup("Stop node " + comment)
    # get process of the node. find this process exists
    _lib.StartTest("Check node state")
    res = _lib.ExecuteNode(['nodestate', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Server is running",
                           "Server should be runnning")

    # get address from this response
    match = re.search(r'Process: (\d+),', res, re.M)

    if not match:
        _lib.Fatal("Can not get process ID from the response " + res)

    PID = int(match.group(1))

    _lib.FatalAssertPIDRunning(PID, "Can not find process with ID " + str(PID))

    _lib.StartTest("Stop node")
    res = _lib.ExecuteNode(['stopnode', '-configdir', datadir])
    _lib.FatalAssert(res == "", "Should not be any output on succes stop")

    _lib.CheckPIDNotRunning(PID, 7)

    _lib.FatalAssertPIDNotRunning(
        PID, "Process with ID " + str(PID) + " should not exist")

    _lib.StartTest("Stop node again")
    res = _lib.ExecuteNode(['stopnode', '-configdir', datadir])
    _lib.FatalAssert(res == "", "Should not be any output on succes stop")
Example #9
0
def CancelTransaction(datadir, txid):
    _lib.StartTest("Cancel transaction")

    res = _lib.ExecuteNode(
        ['canceltransaction', '-configdir', datadir, '-transaction', txid])

    _lib.FatalAssertSubstr(res, "Done!", "Cancel of transaction failed")
Example #10
0
def AddNode(datadir, nodehost, nodeport):
    _lib.StartTest("Add node " + nodehost + ":" + str(nodeport))
    res = _lib.ExecuteNode([
        'addnode', '-configdir', datadir, '-nodehost', nodehost, '-nodeport',
        nodeport, '-logs', 'trace'
    ])
    _lib.FatalAssertSubstr(res, "Success!",
                           "Output should contain success message")
Example #11
0
def SendTooMuchNoNode(datadir, fromaddr, to, amount):
    _lib.StartTest("Send too much money. From " + fromaddr + " to " + to +
                   " amount " + str(amount))
    res = _lib.ExecuteWallet([
        'send', '-configdir', datadir, '-from', fromaddr, '-to', to, '-amount',
        str(amount)
    ])
    _lib.FatalAssertSubstr(res, "No enough funds",
                           "Sending of money didn't fail as expected")
Example #12
0
def GetUnspent(datadir,address,host, port):
    _lib.StartTest("Get unspent transactions list")
    res = _lib.ExecuteWallet(['showunspent','-datadir',datadir,'-address',address,"-nodehost",host,"-nodeport",port])
    _lib.FatalAssertSubstr(res,"Balance - ","No list of transactions and balance")
    
    regex = ur"([0-9.]+)\s+from\s+(.+) in transaction (.+) output #(\d+)"

    txres = re.findall(regex, res)
    
    return txres 
Example #13
0
def GetHistory(datadir,address,host, port):
    _lib.StartTest("Get address transactions history for "+address)
    res = _lib.ExecuteWallet(['showhistory','-datadir',datadir,'-address',address,"-nodehost",host,"-nodeport",port])
    _lib.FatalAssertSubstr(res,"History of transactions","No history result")
    
    regex = ur"([0-9.]+)\s+(Out To|In from)\s+([a-zA-Z0-9]+)"

    hist = re.findall(regex, res)
    
    return hist
Example #14
0
def GetWallets(datadir):
    _lib.StartTest("Get wallets")
    res = _lib.ExecuteWallet(['listaddresses', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Wallets (addresses)", "No list of wallets")

    regex = ur"(1[a-zA-Z0-9]{30,100})"

    addresses = re.findall(regex, res)

    return addresses
Example #15
0
def CreateWallet(datadir):
    _lib.StartTest("Create new wallet")
    res = _lib.ExecuteWallet(['createwallet', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Your new address", "Address creation failed")
    match = re.search(r'.+: (.+)', res)

    if not match:
        _lib.Fatal("Address can not be found in " + res)

    address = match.group(1)

    return address
Example #16
0
def GetBlocks(datadir):
    _lib.StartTest("Load blocks chain")
    res = _lib.ExecuteNode(
        ['printchain', '-datadir', datadir, '-view', "short"])
    _lib.FatalAssertSubstr(
        res, "Hash: ",
        "Blockchain display returned wrong data or no any blocks")

    regex = ur"Hash: ([a-z0-9A-Z]+)"

    blocks = re.findall(regex, res)

    return blocks
Example #17
0
def GetGroupBalanceWalletNoNode(datadir):
    _lib.StartTest("Request group balance for addresses in a wallet")
    res = _lib.ExecuteWallet(['listbalances','-datadir',datadir])
    _lib.FatalAssertSubstr(res,"Balance for all addresses:","Balance result not printed")

    regex = ur"([a-z0-9A-Z]+): ([0-9.]+) .Approved - ([0-9.]+), Pending - ([0-9.-]+)"

    balancesres = re.findall(regex, res)
    balances = {}
    
    for r in balancesres:
        balances[r[0]] = [round(float(r[1]),8),round(float(r[2]),8),round(float(r[3]),8)]
    
    return balances
Example #18
0
def ImportBockchain(datadir,host,port):
    _lib.StartTestGroup("Import blockchain")
    
    _lib.StartTest("Create first address before importing blockchain")
    res = _lib.ExecuteNode(['createwallet','-datadir',datadir])
    _lib.FatalAssertSubstr(res,"Your new address","Address creation returned wrong result")

    _lib.FatalRegex(r'.+: (.+)', res, "Address can not be found in "+res);
    
    # get address from this response 
    match = re.search( r'.+: (.+)', res)

    if not match:
        _lib.Fatal("Address can not be found in "+res)
        
    address = match.group(1)
    
    _lib.StartTest("Import blockchain from node 1")
    res = _lib.ExecuteNode(['initblockchain','-datadir',datadir, '-nodehost', host, '-nodeport', port,'-logs','trace,error'])

    _lib.FatalAssertSubstr(res,"Done!","Blockchain init failed")
    
    return address
Example #19
0
def InitBockchain(datadir):
    _lib.StartTestGroup("Init blockchain")

    _lib.StartTest("Create first address")
    res = _lib.ExecuteNode(['createwallet', '-datadir', datadir])
    _lib.FatalAssertSubstr(res, "Your new address",
                           "Address creation returned wrong result")

    # get address from this response
    match = re.search(r'.+: (.+)', res)

    if not match:
        _lib.Fatal("Address can not be found in " + res)

    address = match.group(1)

    _lib.StartTest("Create blockchain")
    res = _lib.ExecuteNode([
        'createblockchain', '-datadir', datadir, '-address', address,
        '-genesis', 'This is the initial block in chain', '-logs', 'trace'
    ])
    _lib.FatalAssertSubstr(res, "Done!", "Blockchain init failed")

    return address
Example #20
0
def MintBlock(datadir, minter):
    _lib.StartTest("Force to Mint a block")
    res = _lib.ExecuteNode([
        'makeblock', '-datadir', datadir, '-minter', minter, '-logs', 'trace'
    ])
    _lib.FatalAssertSubstr(res, "New block mined with the hash",
                           "Block making failed")

    match = re.search(r'New block mined with the hash ([0-9a-zA-Z]+).', res)

    if not match:
        _lib.Fatal("New block hash can not be found in response " + res)

    blockhash = match.group(1)

    return blockhash
Example #21
0
def SendNoNode(datadir,fromaddr,to,amount):
    _lib.StartTest("Send money. From "+fromaddr+" to "+to+" amount "+str(amount))
    
    res = _lib.ExecuteWallet(['send','-datadir',datadir,'-from',fromaddr,'-to',to,'-amount',str(amount)])
    
    _lib.FatalAssertSubstr(res,"Success. New transaction:","Sending of money failed. NO info about new transaction")
    
    # get transaction from this response 
    match = re.search( r'Success. New transaction: (.+)', res)

    if not match:
        _lib.Fatal("Transaction ID can not be found in "+res)
        
    txid = match.group(1)

    return txid
Example #22
0
def ExecuteSQLFailure(datadir,fromaddr,sqlcommand):
    _lib.StartTest("Execute SQL by "+fromaddr+" "+sqlcommand+" , expect failure")

    res = _lib.ExecuteNode(['sql','-configdir',datadir,'-from',fromaddr,'-sql',sqlcommand])
    
    _lib.FatalAssertSubstr(res,"Error: ","Error was expected")
    
    # get transaction from this response 
    match = re.search( r'Error: (.+)', res)

    if not match:
        _lib.Fatal("No error message")
        
    error = match.group(1)

    return error
Example #23
0
def ExecuteSQL(datadir,fromaddr,sqlcommand):
    _lib.StartTest("Execute SQL by "+fromaddr+" "+sqlcommand)

    res = _lib.ExecuteNode(['sql','-configdir',datadir,'-from',fromaddr,'-sql',sqlcommand])
    
    _lib.FatalAssertSubstr(res,"Success. New transaction:","Executing SQL failes. NO info about new transaction. SQL error")
    
    # get transaction from this response 
    match = re.search( r'Success. New transaction: (.+)', res)

    if not match:
        _lib.Fatal("Transaction ID can not be found in "+res)
        
    txid = match.group(1)

    return txid
Example #24
0
def WaitUnapprovedTransactionsEmpty(datadir, maxseconds = 10):
    c = 0
    
    while True:
        _lib.StartTest("Get unapproved transactions")
        res = _lib.ExecuteNode(['unapprovedtransactions','-datadir',datadir])
        
        if "Total transactions: 0" in res:
            break
        
        c=c+1
        
        if c > maxseconds:
            break
        
        time.sleep(1)
    
    _lib.FatalAssertSubstr(res,"Total transactions: 0","Output should not contains list of transactions")
Example #25
0
def GetNodes(datadir):
    _lib.StartTest("Get nodes")
    res = _lib.ExecuteNode(
        ['shownodes', '-configdir', datadir, '-logs', 'trace'])

    _lib.FatalAssertSubstr(res, "Nodes:",
                           "Output should contain list of nodes")

    regex = ur"  ([^: ]+):(\d+)"

    nodes = re.findall(regex, res)

    nodeslist = {}

    for n in nodes:
        nodeslist[n[0] + ':' + n[1]] = n

    return nodeslist
Example #26
0
def CreateWallet(datadir):
    _lib.StartTestGroup("Create Wallet")
    
    _lib.StartTest("Create one more address")
    res = _lib.ExecuteNode(['createwallet','-configdir',datadir,'-logs','trace'])
    _lib.FatalAssertSubstr(res,"Your new address","Address creation returned wrong result")

    _lib.FatalRegex(r'.+: (.+)', res, "Address can not be found in "+res);
    
    # get address from this response 
    match = re.search( r'.+: (.+)', res)

    if not match:
        _lib.Fatal("Address can not be found in "+res)
        
    address = match.group(1)
    
    return address
Example #27
0
def WaitUnapprovedTransactions(datadir, count, maxseconds=10):
    c = 0

    while True:
        _lib.StartTest("Get unapproved transactions")
        res = _lib.ExecuteNode(
            ['unapprovedtransactions', '-configdir', datadir])

        c = c + 1

        if "--- Transaction" not in res:
            if c > maxseconds:
                break

            time.sleep(1)

            continue

        regex = ur"--- Transaction ([^:]+):"

        transactions = re.findall(regex, res)

        regex = ur"FROM ([A-Za-z0-9]+) TO ([A-Za-z0-9]+) VALUE ([0-9.]+)"

        txinfo = re.findall(regex, res)

        if len(txinfo) >= count:
            break

        if c > maxseconds:
            break

        time.sleep(1)

    _lib.FatalAssertSubstr(res, "--- Transaction",
                           "Output should contains list of transactions")

    txlist = {}

    for i in range(len(transactions)):
        txlist[transactions[i]] = txinfo[i]

    return txlist
Example #28
0
def GetBalance(datadir, address):
    _lib.StartTest("Request balance for a node wallet " + address)
    res = _lib.ExecuteNode(
        ['getbalance', '-configdir', datadir, "-address", address])
    _lib.FatalAssertSubstr(res, "Balance of", "Balance info is not found")

    # get balance from this response
    match = re.search(r'Balance of \'([^\']+)\':', res)

    if not match:
        _lib.Fatal("Address can not be found in " + res)

    addr = match.group(1)

    _lib.FatalAssert(addr == address,
                     "Address in a response is not same as requested. " + res)

    balance = [0, 0, 0]

    match = re.search(r'Approved\s+-\s+([0-9.]+)', res)

    if not match:
        _lib.Fatal("Approved Balance can not be found in " + res)

    balance[1] = round(float(match.group(1)), 8)

    match = re.search(r'Total\s+-\s+([0-9.]+)', res)

    if not match:
        _lib.Fatal("Total Balance can not be found in " + res)

    balance[0] = round(float(match.group(1)), 8)

    match = re.search(r'Pending\s+-\s+([0-9.-]+)', res)

    if not match:
        _lib.Fatal("Pending Balance can not be found in " + res)

    balance[2] = round(float(match.group(1)), 8)

    return balance
Example #29
0
def GetBlocksExt(datadir):
    _lib.StartTest("Load blocks chain. Parse extended")
    res = _lib.ExecuteNode(
        ['printchain', '-datadir', datadir, '-view', "short"])
    _lib.FatalAssertSubstr(
        res, "Hash: ",
        "Blockchain display returned wrong data or no any blocks")

    regex = ur"Hash: ([a-z0-9A-Z]+)"

    blocks = re.findall(regex, res)

    regex = ur"Transactions: ([0-9]+)"

    transaction = re.findall(regex, res)

    blocksr = {}

    for ind, b in enumerate(blocks):
        blocksr[b] = transaction[ind]

    return blocksr
Example #30
0
def NodeState(datadir):
    _lib.StartTest("Check node state")
    res = _lib.ExecuteNode(['nodestate', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Number of blocks", "No info about blocks")

    state = {}

    match = re.search(r'Number of blocks - (\d+)', res)

    if not match:
        _lib.Fatal("Number of blocks is not found " + res)

    state['blocks'] = match.group(1)

    match = re.search(r'Number of unapproved transactions - (\d+)', res)

    if not match:
        _lib.Fatal("Numberof unapproved transactions not found " + res)

    state['unapproved'] = match.group(1)

    match = re.search(r'Number of unspent transactions outputs - (\d+)', res)

    if not match:
        _lib.Fatal("Number of unspent transactions outputs -  not found " +
                   res)

    state['unspent'] = match.group(1)

    state['inprogress'] = False

    match = re.search(r'Loaded (\d+) of (\d+) blocks', res)

    if match:
        state['totalnumber'] = match.group(2)
        state['inprogress'] = True

    return state