示例#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")
示例#2
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")
示例#3
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
示例#4
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")
示例#5
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")
示例#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
示例#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
示例#8
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)
示例#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")
示例#10
0
文件: _sql.py 项目: sebczech/oursql
def ExecuteSQLOnProxySign(datadir,sqlcommand, pub_key, pri_key, success = True):
    _lib.StartTest("Execute SQL on Proxy with external sign "+sqlcommand)
    
    sqlgetinfo = sqlcommand + "/* PUBKEY:"+str(pub_key)+"; */"
    
    rows = _lib.DBGetRows(datadir, sqlgetinfo, True)
    
    signData = {}
    
    for row in rows:
        signData[row[0]] = row[1]
    
    _lib.FatalAssert(len(signData),"Problem getting signature info")
    
    stringtosign = signData["StringToSign"].decode('hex')
    
    sig = pri_key.sign(stringtosign,sigencode=ecdsa.util.sigencode_der)
    
    sig = sig.encode('hex')
    
    finalsql = sqlcommand+"/* DATA:"+signData["Transaction"]+"; SIGN:"+sig+";*/"
    
    res = _lib.DBExecute(datadir,finalsql,True)
    
    if success:
        _lib.FatalAssert(res=="","Error for proxy SQL call: "+res)
    else:
        _lib.FatalAssert(res!="","Error expected for the SQL call")

    return True
示例#11
0
文件: _sql.py 项目: sebczech/oursql
def ExecuteSQLOnProxyFail(datadir,sqlcommand):
    _lib.StartTest("Execute SQL on Proxy "+sqlcommand)

    res = _lib.DBExecute(datadir,sqlcommand,True)
    
    _lib.FatalAssert(res!="","Error was expected. But query is success")

    return True
示例#12
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")
示例#13
0
文件: _sql.py 项目: sebczech/oursql
def ExecuteSQLOnProxy(datadir,sqlcommand):
    _lib.StartTest("Execute SQL on Proxy "+sqlcommand)

    res = _lib.DBExecute(datadir,sqlcommand,True)
    
    _lib.FatalAssert(res=="","Error for proxy SQL call: "+res)

    return True
示例#14
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")
示例#15
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
示例#16
0
def GetCountUnapprovedTransactions(datadir):

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

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

    c = re.findall(regex, res)

    return c[0]
示例#17
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 
示例#18
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
示例#19
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
示例#20
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
示例#21
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
示例#22
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
示例#23
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
示例#24
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
示例#25
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
示例#26
0
文件: _sql.py 项目: sebczech/oursql
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
示例#27
0
文件: _sql.py 项目: sebczech/oursql
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
示例#28
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")
示例#29
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
示例#30
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