コード例 #1
0
def parseWalletBalance(res, address):
    # 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
コード例 #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
コード例 #3
0
ファイル: startnode.py プロジェクト: sebczech/oursql
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")
コード例 #4
0
ファイル: startnode.py プロジェクト: sebczech/oursql
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")
コード例 #5
0
ファイル: _transfers.py プロジェクト: diegslva/oursql
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
コード例 #6
0
ファイル: _wallet.py プロジェクト: sebczech/oursql
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
コード例 #7
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
コード例 #8
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
コード例 #9
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
コード例 #10
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
コード例 #11
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
コード例 #12
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
コード例 #13
0
ファイル: initblockchain.py プロジェクト: w1r2p1/democoin
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
コード例 #14
0
ファイル: startnode.py プロジェクト: w1r2p1/democoin
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
コード例 #15
0
ファイル: blocksbasic.py プロジェクト: diegslva/oursql
def test(testfilter):
    _lib.StartTestGroup("Blocks making")

    _lib.CleanTestFolders()
    datadir = _lib.CreateTestFolder()

    r = PrepareBlockchain(datadir, '30000')
    address = r[0]

    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    amount1 = '1'
    amount2 = '2'
    amount3 = '3'

    txid1 = _transfers.Send(datadir, address, address2, amount1)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    time.sleep(1)
    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")

    time.sleep(1)
    txid3 = _transfers.Send(datadir, address, address3, amount3)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    time.sleep(1)
    txid4 = _transfers.Send(datadir, address3, address2, amount1)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 4, "Should be 4 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions")

    if txid4 not in txlist.keys():
        _lib.Fatal("Transaction 4 is not in the list of transactions")

    _lib.FatalAssertFloat(amount1, txlist[txid1][2],
                          "Amount of transaction 1 is wrong")

    _lib.FatalAssertFloat(amount2, txlist[txid2][2],
                          "Amount of transaction 2 is wrong")

    _lib.FatalAssertFloat(amount3, txlist[txid3][2],
                          "Amount of transaction 3 is wrong")

    _lib.FatalAssertFloat(amount1, txlist[txid4][2],
                          "Amount of transaction 4 is wrong")

    blockchash = _blocks.MintBlock(datadir, address)

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 2, "Should be 2 blocks in blockchain")

    _lib.StartTestGroup("Send 30 transactions")

    microamount = 0.01
    # send many transactions
    for i in range(1, 10):
        _lib.StartTest("Iteration " + str(i))
        txid1 = _transfers.Send(datadir, address, address2, microamount)
        txid2 = _transfers.Send(datadir, address2, address3, microamount)
        txid3 = _transfers.Send(datadir, address3, address, microamount)

        txlist = transactions.GetUnapprovedTransactions(datadir)

        _lib.FatalAssert(
            len(txlist) == i * 3,
            "Should be " + str(i * 3) + " unapproved transaction")

        if txid1 not in txlist.keys():
            _lib.Fatal(
                "Transaction 1 is not in the list of transactions after iteration "
                + str(i))

        if txid2 not in txlist.keys():
            _lib.Fatal(
                "Transaction 2 is not in the list of transactions after iteration "
                + str(i))

        if txid3 not in txlist.keys():
            _lib.Fatal(
                "Transaction 3 is not in the list of transactions after iteration "
                + str(i))

        time.sleep(1)

    blockchash = _blocks.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 3, "Should be 3 blocks in blockchain")

    _lib.StartTestGroup("Send 30 transactions. Random value")

    microamountmax = 0.01
    microamountmin = 0.0095
    # send many transactions
    for i in range(1, 11):
        _lib.StartTest("Iteration " + str(i))
        a1 = random.uniform(microamountmin, microamountmax)
        a2 = random.uniform(microamountmin, microamountmax)
        a3 = random.uniform(microamountmin, microamountmax)
        txid1 = _transfers.Send(datadir, address, address2, a1)
        txid2 = _transfers.Send(datadir, address2, address3, a2)
        txid3 = _transfers.Send(datadir, address3, address, a3)

        txlist = transactions.GetUnapprovedTransactions(datadir)

        _lib.FatalAssert(
            len(txlist) == i * 3,
            "Should be " + str(i * 3) + " unapproved transaction")

        if txid1 not in txlist.keys():
            _lib.Fatal(
                "Transaction 1 is not in the list of transactions after iteration "
                + str(i))

        if txid2 not in txlist.keys():
            _lib.Fatal(
                "Transaction 2 is not in the list of transactions after iteration "
                + str(i))

        if txid3 not in txlist.keys():
            _lib.Fatal(
                "Transaction 3 is not in the list of transactions after iteration "
                + str(i))

        time.sleep(1)

    blockchash = _blocks.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain")

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
コード例 #16
0
ファイル: blocksbasic.py プロジェクト: diegslva/oursql
def PrepareBlockchain(datadir, port):
    _lib.StartTestGroup("Create blockchain. Try to start a server")

    _lib.StartTest("Try to start without blockchain")
    res = _lib.ExecuteNode(['startnode', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "No database config",
                           "Blockchain is not yet inited. Should fail")

    _lib.StartTest("Create first address")
    res = _lib.ExecuteNode(['createwallet', '-configdir', 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)

    dbconfig = _lib.GetDBCredentials(datadir)

    _lib.StartTest("Create blockchain")
    res = _lib.ExecuteNode([
        'initblockchain', '-configdir', datadir, '-minter', address,
        '-mysqlhost', dbconfig['host'], '-mysqlport', dbconfig['port'],
        '-mysqluser', dbconfig['user'], '-mysqlpass', dbconfig['password'],
        '-mysqldb', dbconfig['database'], '-logs', 'trace'
    ])
    _lib.FatalAssertSubstr(res, "Done!", "Blockchain init failed")

    _lib.StartTest("Start normal")
    res = _lib.ExecuteNode([
        'startnode', '-configdir', datadir, '-port', port, '-minter', address
    ])
    _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")

    _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")

    time.sleep(1)
    _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")

    return [address, PID]
コード例 #17
0
def test(testfilter):
    global datadir1
    global datadir2
    global datadir3

    _lib.StartTestGroup("Manage nodes list")

    _lib.CleanTestFolders()
    datadir1 = _lib.CreateTestFolder('_1_')
    datadir2 = _lib.CreateTestFolder('_2_')

    _lib.StartTestGroup("Create blockchain and run node 1")
    r = blocksbasic.PrepareBlockchain(datadir1, '30000')
    address = r[0]

    startnode.StartNode(datadir1, address, '30000', "Server 1")

    address2 = initblockchain.ImportBockchain(datadir2, "localhost", '30000')

    #RemoveAllNodes(datadir1)
    nodes = GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 0, "Should be 0 nodes in output")

    AddNode(datadir1, "localhost", '30001')

    nodes = GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 1, "Should be 1 nodes in output")

    RemoveNode(datadir1, "localhost", '30001')

    nodes = GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 0, "Should be 0 nodes in output")

    startnode.StartNode(datadir2, address2, '30001', "Server 2")

    #RemoveAllNodes(datadir2)

    #AddNode(datadir1, "localhost",'30001')

    nodes = GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 1, "Should be 1 nodes in output")

    startnode.StopNode(datadir2, "Server 2")

    startnode.StartNode(datadir2, address2, '30001', "Server 2")

    nodes = GetNodes(datadir1)

    _lib.FatalAssert(len(nodes) == 1, "Should be 1 nodes in output")
    _lib.FatalAssert(
        nodes.keys()[0] == "localhost:30001"
        or nodes.keys()[0] == "127.0.0.1:30001", "Wrong node in the list")

    # check transactions work fine between nodes
    _transfers.Send(datadir1, address, address2, '3')

    txlist = transactions.GetUnapprovedTransactions(datadir1)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    blocks = _blocks.WaitBlocks(datadir1, 2)

    # send another 2 TX to make a block
    tx = _transfers.Send(datadir1, address, address2, '0.01')

    tx = _transfers.Send(datadir1, address, address2, '0.01')

    blocks = _blocks.WaitBlocks(datadir1, 3)
    time.sleep(2)

    tx = txid1 = _transfers.Send(datadir1, address, address2, '1')
    time.sleep(1)

    txlist = transactions.GetUnapprovedTransactions(datadir1)

    _lib.FatalAssert(
        len(txlist) == 1,
        "Should be 1 unapproved transaction. Got " + str(len(txlist)))

    time.sleep(3)
    # and now get transactions from second node
    txlist = _transfers.WaitUnapprovedTransactions(datadir2, 1)

    _lib.FatalAssert(
        len(txlist) == 1,
        "Should be 1 unapproved transaction on second node. Got " +
        str(len(txlist)) + " " + str(txlist))
    #print txid1
    #print txlist
    if txid1 not in txlist.keys():
        _lib.Fatal(
            "Transaction 1 is not in the list of transactions on second node")

    # start one more node
    datadir3 = _lib.CreateTestFolder('_3_')
    address3 = initblockchain.ImportBockchain(datadir3, "localhost", '30000')

    startnode.StartNode(datadir3, address3, '30002', "Server 3")

    #RemoveAllNodes(datadir3)

    #AddNode(datadir3, "localhost",'30001')

    time.sleep(2)  # wait while nodes exchange addresses

    nodes = GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes in output of 1")

    nodes = GetNodes(datadir2)

    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes in output of 2")

    nodes = GetNodes(datadir3)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes in output of 3")

    txid1 = _transfers.Send(datadir1, address, address3, '4')

    # unapproved TX is pulled from node 1 on start
    txlist3 = transactions.GetUnapprovedTransactions(datadir3)

    _lib.FatalAssert(
        len(txlist3) == 1, "Should be 1 unapproved transactions on 3")

    time.sleep(3)  # we need to give a chance to sync all

    txlist1 = transactions.GetUnapprovedTransactions(datadir1)
    txlist2 = transactions.GetUnapprovedTransactions(datadir2)

    _lib.FatalAssert(
        len(txlist1) == 2, "Should be 2 unapproved transactions on 1")
    _lib.FatalAssert(
        len(txlist2) == 2, "Should be 2 unapproved transactions on 2")

    if txid1 not in txlist1.keys():
        _lib.Fatal(
            "Transaction 2 is not in the list of transactions on node 1")

    if txid1 not in txlist2.keys():
        _lib.Fatal(
            "Transaction 2 is not in the list of transactions on node 2")

    # send one more TX. Block must be created
    txid3 = _transfers.Send(datadir1, address, address2, '1')

    blocks = _blocks.WaitBlocks(datadir3, 4)
    blocks = _blocks.WaitBlocks(datadir2, 4)
    blocks = _blocks.WaitBlocks(datadir1, 4)
    time.sleep(1)

    transactions.GetUnapprovedTransactionsEmpty(datadir1)
    transactions.GetUnapprovedTransactionsEmpty(datadir2)
    transactions.GetUnapprovedTransactionsEmpty(datadir3)

    # check if a block is present on all nodes. it must be 2 block on every node
    blockshashes = _blocks.GetBlocks(datadir1)

    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain on 1")

    blockshashes = _blocks.GetBlocks(datadir2)
    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain on 2")

    blockshashes = _blocks.GetBlocks(datadir3)
    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain on 3")

    startnode.StopNode(datadir1, "Server 1")
    startnode.StopNode(datadir2, "Server 2")
    startnode.StopNode(datadir3, "Server 3")

    #_lib.RemoveTestFolder(datadir1)
    #_lib.RemoveTestFolder(datadir2)

    datadir1 = ""
    datadir2 = ""
    datadir3 = ""

    _lib.EndTestGroupSuccess()
コード例 #18
0
def Make5BlocksBC():
    datadir = _lib.CreateTestFolder()
    
    _lib.StartTest("Create first address")
    res = _lib.ExecuteNode(['createwallet','-configdir',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)

    dbconfig = _lib.GetDBCredentials(datadir)

    _lib.StartTest("Create blockchain")
    res = _lib.ExecuteNode(['initblockchain','-configdir',datadir, 
                            '-minter', address, 
                            '-mysqlhost', dbconfig['host'], 
                            '-mysqlport', dbconfig['port'],
                            '-mysqluser', dbconfig['user'],
                            '-mysqlpass', dbconfig['password'],
                            '-mysqldb', dbconfig['database'],
                            '-logs','trace'])
    
    _lib.FatalAssertSubstr(res,"Done!","Blockchain init failed")
    
    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.StartTestGroup("Do transfers")

    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    amount1 = '1'
    amount2 = '2'
    amount3 = '3'
    
    _lib.StartTestGroup("Send 1 transaction")
    
    # one TX in first block
    txid1 = _transfers.Send(datadir,address,address2,amount1)
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 1,"Should be 1 unapproved transaction")
    
    blockchash = _blocks.MintBlock(datadir,address)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 2,"Should be 2 blocks in blockchain")
    
    _lib.StartTestGroup("Send 2 transactions")
    # 2 TX in second block
    txid2 = _transfers.Send(datadir,address,address3,amount2)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 1,"Should be 1 unapproved transaction")
    
    txid3 = _transfers.Send(datadir,address,address3,amount3)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    
    _lib.FatalAssert(len(txlist) == 2,"Should be 2 unapproved transaction")
    
    blockchash = _blocks.MintBlock(datadir,address)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 3,"Should be 3 blocks in blockchain")
   
    _lib.StartTestGroup("Send 3 transactions")
    
    microamount = 0.01
    
    txid1 = _transfers.Send(datadir,address,address2,microamount)
    txid2 = _transfers.Send(datadir,address2,address3,microamount)
    txid3 = _transfers.Send(datadir,address3,address,microamount)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    
    _lib.FatalAssert(len(txlist) == 3,"Should be 3 unapproved transaction")
    
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 4,"Should be 4 blocks in blockchain")
    
    _lib.StartTestGroup("Send 4 transactions. Random value")
    
    microamountmax = 0.01
    microamountmin = 0.0095
    
    a1 = round(random.uniform(microamountmin, microamountmax),8)
    a2 = round(random.uniform(microamountmin, microamountmax),8)
    a3 = round(random.uniform(microamountmin, microamountmax),8)
    a4 = round(random.uniform(microamountmin, microamountmax),8)
    txid1 = _transfers.Send(datadir,address,address2,a1)
    txid2 = _transfers.Send(datadir,address2,address3,a2)
    txid3 = _transfers.Send(datadir,address3,address,a3)
    txid3 = _transfers.Send(datadir,address3,address,a4)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    
    _lib.FatalAssert(len(txlist) == 4,"Should be 4 unapproved transaction")
    
    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions after iteration "+str(i))

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions after iteration "+str(i))

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions after iteration "+str(i))
        
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 5,"Should be 5 blocks in blockchain")
    
    _lib.StartTestGroup("Send 5 transactions. Random value")
    
    txid1 = _transfers.Send(datadir,address,address2,a4)
    txid2 = _transfers.Send(datadir,address2,address3,a3)
    txid3 = _transfers.Send(datadir,address3,address,a2)
    txid3 = _transfers.Send(datadir,address3,address,a1)
    txid1 = _transfers.Send(datadir,address,address2,a1)
    
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 6,"Should be 6 blocks in blockchain")
    
    dstdir = _lib.getCurrentDir()+"/datafortests/bcwith4blocks/"
    
    copyfile(datadir+"/wallet.dat", dstdir+"wallet.t")
    DumpBCDB(datadir, dstdir+"db.sql")
    #copyfile(datadir+"/nodeslist.db", dstdir+"nodeslist.t")
    #copyfile(datadir+"/blockchain.db", dstdir+"blockchain.t")
    
    return [datadir, address, address2, address3]
コード例 #19
0
ファイル: transactions.py プロジェクト: sebczech/oursql
def test(testfilter):
    _lib.StartTestGroup("Start/Stop node")

    _lib.CleanTestFolders()
    datadir = _lib.CreateTestFolder()

    startnode.StartNodeWithoutBlockchain(datadir)
    address = startnode.InitBockchain(datadir)
    startnode.StartNode(datadir, address, '30000')
    startnode.StopNode(datadir)

    # create another 3 addresses
    address2 = CreateWallet(datadir)
    address3 = CreateWallet(datadir)

    _lib.StartTestGroup("Do transactions")

    GetUnapprovedTransactionsEmpty(datadir)

    amount1 = '1'
    amount2 = '2'

    txid1 = _transfers.Send(datadir, address, address2, amount1)

    txlist = GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    _lib.FatalAssertFloat(amount1, txlist[txid1][3],
                          "Amount of transaction 1 is wrong")

    _lib.FatalAssertFloat(amount2, txlist[txid2][3],
                          "Amount of transaction 2 is wrong")

    _lib.StartTestGroup("Cancel transaction")

    txid3 = _transfers.Send(datadir, address, address2,
                            float(amount1) + float(amount2))

    txlist = GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    CancelTransaction(datadir, txid3)

    txlist = GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")

    #previous 2 transactions still must be in the list
    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    _transfers.SendTooMuch(datadir, address, address2,
                           15)  # the account should have only 10

    # cancel all transactions
    CancelTransaction(datadir, txid1)
    CancelTransaction(datadir, txid2)

    GetUnapprovedTransactionsEmpty(datadir)

    #==========================================================================
    # send when node server is running
    startnode.StartNode(datadir, address, '30000')

    txid1 = _transfers.Send(datadir, address, address2, amount1)

    txlist = GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    startnode.StopNode(datadir)

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
コード例 #20
0
ファイル: blockscommon.py プロジェクト: sebczech/oursql
def test(testfilter):
    global datadir

    _lib.StartTestGroup("Blocks making")

    nodeport = '30010'

    _lib.CleanTestFolders()
    datadir = _lib.CreateTestFolder()

    startnode.StartNodeWithoutBlockchain(datadir)
    address = startnode.InitBockchain(datadir)
    startnode.StartNode(datadir, address, nodeport)
    startnode.StopNode(datadir)

    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    startnode.StartNode(datadir, address, nodeport)

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    amount1 = '1'
    amount2 = '2'
    amount3 = '3'

    txid1 = _transfers.Send(datadir, address, address2, amount1)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    #block making will be started now
    time.sleep(5)

    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    txid3 = _transfers.Send(datadir, address, address3, amount3)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions")

    _lib.FatalAssertFloat(amount2, txlist[txid2][3],
                          "Amount of transaction 2 is wrong")

    _lib.FatalAssertFloat(amount3, txlist[txid3][3],
                          "Amount of transaction 3 is wrong")

    time.sleep(5)

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    startnode.StopNode(datadir)
    datadir = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
コード例 #21
0
def MakeBlockchainWithBlocks(port):

    datadir = _lib.CreateTestFolder()

    r = blocksbasic.PrepareBlockchain(datadir, port)
    address = r[0]

    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.StartTestGroup("Do _transfers")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    amount1 = '1'
    amount2 = '2'
    amount3 = '3'

    txid1 = _transfers.Send(datadir, address, address2, amount1)
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")
    txid3 = _transfers.Send(datadir, address, address3, amount3)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    txid4 = _transfers.Send(datadir, address3, address2, amount1)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 4, "Should be 4 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions")

    if txid4 not in txlist.keys():
        _lib.Fatal("Transaction 4 is not in the list of transactions")

    _lib.FatalAssertFloat(amount1, txlist[txid1][2],
                          "Amount of transaction 1 is wrong")

    _lib.FatalAssertFloat(amount2, txlist[txid2][2],
                          "Amount of transaction 2 is wrong")

    _lib.FatalAssertFloat(amount3, txlist[txid3][2],
                          "Amount of transaction 3 is wrong")

    _lib.FatalAssertFloat(amount1, txlist[txid4][2],
                          "Amount of transaction 4 is wrong")

    blockchash = blocksbasic.MintBlock(datadir, address)

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 2, "Should be 2 blocks in blockchain")

    _lib.StartTestGroup("Send 3 transactions")

    microamount = 0.01

    txid1 = _transfers.Send(datadir, address, address2, microamount)
    txid2 = _transfers.Send(datadir, address2, address3, microamount)
    txid3 = _transfers.Send(datadir, address3, address, microamount)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal(
            "Transaction 1 is not in the list of transactions after iteration "
            + str(i))

    if txid2 not in txlist.keys():
        _lib.Fatal(
            "Transaction 2 is not in the list of transactions after iteration "
            + str(i))

    if txid3 not in txlist.keys():
        _lib.Fatal(
            "Transaction 3 is not in the list of transactions after iteration "
            + str(i))

    blockchash = blocksbasic.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 3, "Should be 3 blocks in blockchain")

    _lib.StartTestGroup("Send 3 transactions. Random value")

    microamountmax = 0.01
    microamountmin = 0.0095

    a1 = round(random.uniform(microamountmin, microamountmax), 8)
    a2 = round(random.uniform(microamountmin, microamountmax), 8)
    a3 = round(random.uniform(microamountmin, microamountmax), 8)
    txid1 = _transfers.Send(datadir, address, address2, a1)
    txid2 = _transfers.Send(datadir, address2, address3, a2)
    txid3 = _transfers.Send(datadir, address3, address, a3)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal(
            "Transaction 1 is not in the list of transactions after iteration "
            + str(i))

    if txid2 not in txlist.keys():
        _lib.Fatal(
            "Transaction 2 is not in the list of transactions after iteration "
            + str(i))

    if txid3 not in txlist.keys():
        _lib.Fatal(
            "Transaction 3 is not in the list of transactions after iteration "
            + str(i))

    blockchash = blocksbasic.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain")

    return [datadir, address, address2, address3]