Esempio n. 1
0
def test(testfilter):
    global datadir1
    global datadir2
    global datadir3

    _lib.StartTestGroup("Blocks exhange between nodes")

    _lib.CleanTestFolders()

    inf = MakeBlockchainWithBlocks('30000')
    datadir = inf[0]
    address1 = inf[1]
    address1_2 = inf[2]
    address1_3 = inf[3]

    #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1")
    startnode.StartNode(datadir, address1, '30000', "Server 1")
    datadir1 = datadir
    managenodes.RemoveAllNodes(datadir1)

    d = StartNodeAndImport('30001', '30000', "Server 2")
    datadir2 = d[0]
    address2 = d[1]

    d = StartNodeAndImport('30002', '30000', "Server 3")
    datadir3 = d[0]
    address3 = d[1]

    time.sleep(1)
    nodes = managenodes.GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 1")
    nodes = managenodes.GetNodes(datadir2)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 2")
    nodes = managenodes.GetNodes(datadir3)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 3")

    # get balance

    startnode.StopNode(datadir1, "Server 1")
    datadir1 = ""

    startnode.StopNode(datadir2, "Server 2")
    datadir2 = ""

    startnode.StopNode(datadir3, "Server 3")
    datadir3 = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Esempio n. 2
0
def StartNodeAndImport(port,
                       importport,
                       title,
                       dbproxyport,
                       suffix="",
                       host="localhost"):

    datadir = _lib.CreateTestFolder(suffix)

    # this will create config file to remember other node address
    configfile = "{\"Port\": " + str(
        port) + ",\"Nodes\":[{\"Host\": \"localhost\",\"Port\":" + str(
            importport) + "}]}"
    _lib.SaveConfigFile(datadir, configfile)

    address = initblockchain.ImportBockchain(datadir, "localhost", importport)

    _complex.AddMinterToConfig(datadir, address)

    if dbproxyport > 0:
        _complex.AddProxyToConfig(datadir, "localhost:" + str(dbproxyport))
        _complex.AddInternalKeyToConfig(datadir,
                                        address)  # init internal signing

    startnode.StartNode(datadir, address, port, title, host)

    #check nodes. must be minimum 1 and import port must be present
    nodes = managenodes.GetNodes(datadir)
    _lib.FatalAssert(len(nodes) > 0, "Should be minimum 1 nodes in output")

    return [datadir, address]
Esempio n. 3
0
def StartNodeAndImport(port, importport, title, suffix=""):

    datadir = _lib.CreateTestFolder(suffix)

    address = initblockchain.ImportBockchain(datadir, "localhost", importport)

    # this will create config file to remember other node address
    configfile = "{\"MinterAddress\":\"" + address + "\",\"Port\": " + str(
        port) + ",\"Nodes\":[{\"Host\": \"localhost\",\"Port\":" + str(
            importport) + "}]}"
    _lib.SaveConfigFile(datadir, configfile)

    startnode.StartNode(datadir, address, port, title)

    #check nodes. must be minimum 1 and import port must be present
    nodes = managenodes.GetNodes(datadir)
    _lib.FatalAssert(len(nodes) > 0, "Should be minimum 1 nodes in output")

    return [datadir, address]
Esempio n. 4
0
def test(testfilter):
    global datadirs
    _lib.CleanTestFolders()
    #return _complex.Make5BlocksBC()
    #return _complex.PrepareNodes()

    dirs = _complex.Copy6Nodes()
    
    nodes = []
    
    i = 1
    for d in dirs:
        #get address in wallets in this dir 
        balances = _transfers.GetGroupBalance(d)
        address = balances.keys()[0]
        
        port = str(30000 + i )
        
        nodes.append({'index':i - 1, 'port':port, 'datadir':d,'address':address,"title":"Server "+str(i)})
        
        #_transfers.ReindexUTXO(d)
        #txlist = transactions.GetUnapprovedTransactions(d)
        #print txlist
        #start this node 
        #print os.path.basename(d)
        startnode.StartNodeConfig(d)
        
        i = i + 1
        datadirs.append(d)
        
    #check nodes on each node is correct 
    for node in nodes:
        #print os.path.basename(node['datadir'])
        nodeslist = managenodes.GetNodes(node['datadir'])
        
        _lib.FatalAssert(len(nodeslist) == 2,"Should be 2 nodes on "+node["title"])
        
        if node['index'] == 0:
            _lib.FatalAssert("localhost:30005" in nodeslist,"Node 6 should be on the node 0")
            _lib.FatalAssert("localhost:30004" in nodeslist,"Node 5 should be on the node 0")
        if node['index'] == 1:
            _lib.FatalAssert("localhost:30002" in nodeslist,"Node 2 should be on the node 1")
            _lib.FatalAssert("localhost:30003" in nodeslist,"Node 3 should be on the node 1")
    #raise ValueError('Stop')
    # test blocks branches
    # ensure subnetworks are fine
    managenodes.AddNode(nodes[2]["datadir"],"localhost",'30003')
    managenodes.AddNode(nodes[4]["datadir"],"localhost",'30005')
    
    _lib.StartTestGroup("Check blockchain before updates")
    blocks1 = _blocks.GetBlocks(nodes[0]["datadir"])
    blocks2 = _blocks.GetBlocks(nodes[1]["datadir"])
    
    _lib.FatalAssert(len(blocks1) == 9,"First branch should have 9 blocks")
    _lib.FatalAssert(len(blocks2) == 8,"Second branch should have 8 blocks")
    
    _lib.FatalAssert(blocks1[2] == blocks2[1],"7 block must be same for both")
    _lib.FatalAssert(blocks1[1] != blocks2[0],"8 block must be different")
    
    #======================================================================================
    # remove node 6 from the first branch
    managenodes.RemoveAllNodes(nodes[5]["datadir"])
    nodeslist = managenodes.GetNodes(nodes[5]["datadir"])
    _lib.FatalAssert(len(nodeslist) == 0,"Should be 0 nodes on the node 6")
    
    # remove this node from 2 other nodes where it is known
    managenodes.RemoveNode(nodes[0]["datadir"], "localhost" ,"30005")
    managenodes.RemoveNode(nodes[4]["datadir"], "localhost" ,"30005")
    
    nodeslist = managenodes.GetNodes(nodes[0]["datadir"])
    _lib.FatalAssert(len(nodeslist) == 1,"Should be 1 nodes on the node 1")
    
    nodeslist = managenodes.GetNodes(nodes[4]["datadir"])
    _lib.FatalAssert(len(nodeslist) == 1,"Should be 1 nodes on the node 5")
    
    # add one more blockon the first node
    balances = _transfers.GetGroupBalance(nodes[0]["datadir"])
    
    addr1 = balances.keys()[0]
    addr2 = balances.keys()[1]
    amount = "%.8f" % round(balances[addr1][0]/10,8)
    
    for x in range(1, 11):
        _transfers.Send(nodes[0]["datadir"],addr1,addr2,amount)
        
    _blocks.WaitBlocks(nodes[0]["datadir"],10)
    
    # and again new block.
    balances = _transfers.GetGroupBalance(nodes[0]["datadir"])
    
    addr1 = balances.keys()[1]
    addr2 = balances.keys()[0]
    amount = "%.8f" % round(balances[addr1][0]/12,8)
    
    for x in range(1, 12):
        _transfers.Send(nodes[0]["datadir"],addr1,addr2,amount)
        
    _blocks.WaitBlocks(nodes[0]["datadir"],11)
    
    # create 2 more blocks on branch 2
    balances = _transfers.GetGroupBalance(nodes[1]["datadir"])
    
    addr3 = balances.keys()[0]
    amount = "%.8f" % round(balances[addr3][0]/30,8)
    
    for x in range(1, 10):
        # send to address on the firs node
        _transfers.Send(nodes[1]["datadir"],addr3,addr1,amount)
        
    _blocks.WaitBlocks(nodes[1]["datadir"],9)
    
    for x in range(1, 11):
        # send to address on the firs node
        _transfers.Send(nodes[1]["datadir"],addr3,addr1,amount)
        
    _blocks.WaitBlocks(nodes[1]["datadir"],10)
    
    # now branch 2 has more blocks than the node 6.
    # connect node 6 with the branch 2
    _lib.StartTestGroup("Connect network 2 with the node 6")
    managenodes.AddNode(nodes[1]["datadir"],"localhost",'30005')
    managenodes.AddNode(nodes[4]["datadir"],"localhost",'30002')
    managenodes.AddNode(nodes[4]["datadir"],"localhost",'30003')
    managenodes.AddNode(nodes[4]["datadir"],"localhost",'30005')
    
    managenodes.WaitNodes(nodes[1]["datadir"],3)
    managenodes.WaitNodes(nodes[2]["datadir"],3)
    managenodes.WaitNodes(nodes[3]["datadir"],3)
    
    # should be 10 blocks after sync
    _blocks.WaitBlocks(nodes[5]["datadir"],10)
    
    # must be unapproved transactions from previous block 8
    #txlist = transactions.GetUnapprovedTransactions(nodes[5]["datadir"])
    _lib.StartTestGroup("Wait 11 blocks on every node of net 2")
    # new block is created from free transaction after reset of some blocks
    _blocks.WaitBlocks(nodes[5]["datadir"],11)
    _blocks.WaitBlocks(nodes[1]["datadir"],11)
    _blocks.WaitBlocks(nodes[2]["datadir"],11)
    _blocks.WaitBlocks(nodes[3]["datadir"],11)
    
    transactions.GetUnapprovedTransactionsEmpty(nodes[5]["datadir"])
    
    
    #at this point branch 2 + node 6 have 11 blocks.
    #branch 1 has also 11
    _lib.StartTestGroup("Connect all nodes")
    managenodes.AddNode(nodes[1]["datadir"],"localhost",'30000')
    #wait while all nodes know about other nodes
    
    netnodes = managenodes.WaitNodes(nodes[0]["datadir"],5)
    
    netnodes = managenodes.WaitNodes(nodes[1]["datadir"],5)
    
    netnodes = managenodes.WaitNodes(nodes[2]["datadir"],5)
    
    netnodes = managenodes.WaitNodes(nodes[3]["datadir"],5)
    
    netnodes = managenodes.WaitNodes(nodes[4]["datadir"],5)
    
    netnodes = managenodes.WaitNodes(nodes[5]["datadir"],5)
    
    nodeslist = managenodes.GetNodes(nodes[1]["datadir"])
    
    _lib.FatalAssert(len(nodeslist) == 5,"Should be 5 nodes on the node 2")
    
    # add more transactions on the node 0 to get 12-th block
    balances = _transfers.GetGroupBalance(nodes[0]["datadir"])
    
    addr1 = balances.keys()[0]
    addr2 = balances.keys()[2]
    amount = "%.8f" % round(balances[addr1][0]/14,8)
    
    # here a node can have some already prepared transactions . we will add 12. but total can be more
    
    for x in range(1, 13):
        tx = _transfers.Send(nodes[0]["datadir"],addr1,addr2,amount)
        
    _blocks.WaitBlocks(nodes[0]["datadir"],12)
   
    # now sync should start. branch 2 will change branch
    _blocks.WaitBlocks(nodes[1]["datadir"],12)
    
    _lib.StartTestGroup("Wait final blocks")
    
    # after some time new block should be created from all unconfirmed transactions
    _blocks.WaitBlocks(nodes[1]["datadir"],13)
    _blocks.WaitBlocks(nodes[0]["datadir"],13)
    
    _lib.StartTestGroup("Check blockchain after updates")
    blocks2_0 = _blocks.GetBlocks(nodes[0]["datadir"])

    _lib.FatalAssert(len(blocks2_0) == 13,"13 block must be on node 0")
    
    blocks2_1 = _blocks.GetBlocks(nodes[1]["datadir"])
    _lib.FatalAssert(len(blocks2_1) == 13,"13 block must be on node 1")
        
    _lib.StartTestGroup("Node 2 "+os.path.basename(nodes[2]["datadir"]))
    _blocks.WaitBlocks(nodes[2]["datadir"],13)
    
    blocks2_2 = _blocks.GetBlocks(nodes[2]["datadir"])
    
    _lib.FatalAssert(len(blocks2_2) == 13,"13 block must be on node 2")
    #_lib.FatalAssert(blocks2_2[1] == blocks2_1[1],"2-nd from top blocks on 2 must be same as on 1")
    
    _lib.StartTestGroup("Node 3 "+os.path.basename(nodes[3]["datadir"]))
    
    _blocks.WaitBlocks(nodes[3]["datadir"],13)
    blocks2_3 = _blocks.GetBlocks(nodes[3]["datadir"])
    
    _lib.FatalAssert(len(blocks2_3) == 13,"13 block must be on node 3")
    #_lib.FatalAssert(blocks2_3[1] == blocks2_1[1],"2-nd from top blocks on  3 must be same as on 1")
    
    _lib.StartTestGroup("Node 4 "+os.path.basename(nodes[4]["datadir"]))
    
    _blocks.WaitBlocks(nodes[4]["datadir"],13)
    blocks2_4 = _blocks.GetBlocks(nodes[4]["datadir"])
    
    _lib.FatalAssert(len(blocks2_4) == 13,"13 block must be on node 4")
    #_lib.FatalAssert(blocks2_4[1] == blocks2_1[1],"2-nd from top blocks on 4 must be same as on 1")
    
    _lib.StartTestGroup("Node 5 "+os.path.basename(nodes[5]["datadir"]))
    
    _blocks.WaitBlocks(nodes[5]["datadir"],13)
    blocks2_5 = _blocks.GetBlocks(nodes[5]["datadir"])
    
    _lib.FatalAssert(len(blocks2_5) == 13,"13 block must be on node 5")
    #_lib.FatalAssert(blocks2_5[1] == blocks2_1[1],"2-nd from top blocks on 5 must be same as on 1")
    
    _lib.StartTestGroup("Final checks")
    
    # should be empty list of transactions now
    # we commented because it is not always empty and it is not bad
    #transactions.GetUnapprovedTransactionsEmpty(nodes[1]["datadir"])
    
    for node in nodes:
        startnode.StopNode(node['datadir'])
        datadirs[node['index']] = ""
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Esempio n. 5
0
def test(testfilter):
    global datadir1
    global datadir2
    global datadir3

    _lib.StartTestGroup("Blocks exhange between nodes")

    _lib.CleanTestFolders()

    inf = MakeBlockchainWithBlocks('30000')
    datadir = inf[0]
    address1 = inf[1]
    address1_2 = inf[2]
    address1_3 = inf[3]

    #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1")
    _complex.AddProxyToConfig(datadir, "localhost:40001")
    _complex.AddInternalKeyToConfig(datadir, address1)  # init internal signing

    startnode.StartNode(datadir, address1, '30000', "Server 1")
    datadir1 = datadir
    managenodes.RemoveAllNodes(datadir1)

    d = blocksnodes.StartNodeAndImport('30001', '30000', "Server 2", 40002,
                                       '_2_')
    datadir2 = d[0]
    address2 = d[1]

    d = blocksnodes.StartNodeAndImport('30002', '30000', "Server 3", 40003,
                                       '_3_')
    datadir3 = d[0]
    address3 = d[1]

    time.sleep(1)
    nodes = managenodes.GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 1")
    nodes = managenodes.GetNodes(datadir2)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 2")
    nodes = managenodes.GetNodes(datadir3)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 3")

    # get balance
    _sql.ExecuteSQLOnProxy(
        datadir1,
        "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    _sql.ExecuteSQLOnProxy(datadir1, "INSERT INTO test SET b='row1'")
    _sql.ExecuteSQLOnProxy(datadir1, "INSERT INTO test SET a=2,b='row2'")
    _sql.ExecuteSQLOnProxy(datadir1, "INSERT INTO test (b) VALUES ('row3')")

    blocks = _blocks.WaitBlocks(datadir1, 5)
    _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 1")
    blocks = _blocks.WaitBlocks(datadir2, 5)
    _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 2")
    blocks = _blocks.WaitBlocks(datadir3, 5)
    _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 3")

    time.sleep(1)  # while all caches are cleaned

    managenodes.RemoveAllNodes(datadir1)
    managenodes.RemoveAllNodes(datadir2)
    managenodes.RemoveAllNodes(datadir3)

    rows = _lib.DBGetRows(datadir1, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table on node 1")
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table on node 2")
    rows = _lib.DBGetRows(datadir3, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table on node 3")

    _sql.ExecuteSQLOnProxy(datadir1, "INSERT INTO test (b) VALUES ('row4')")

    time.sleep(1)  # while all caches are cleaned

    rows = _lib.DBGetRows(datadir1, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 4, "Must be 4 rows in a table on node 1")
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table on node 2")
    rows = _lib.DBGetRows(datadir3, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table on node 3")

    startnode.StopNode(datadir1, "Server 1")
    datadir1 = ""

    startnode.StopNode(datadir2, "Server 2")
    datadir2 = ""

    startnode.StopNode(datadir3, "Server 3")
    datadir3 = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Esempio n. 6
0
def test(testfilter):
    global datadir1
    global datadir2
    global datadir3

    _lib.StartTestGroup("Test data exahcnge with non-public address node")

    _lib.CleanTestFolders()

    inf = blocksnodes.MakeBlockchainWithBlocks('30000')
    datadir = inf[0]
    address1 = inf[1]
    address1_2 = inf[2]
    address1_3 = inf[3]

    #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1")
    startnode.StartNode(datadir, address1, '30000', "Server 1")
    datadir1 = datadir
    managenodes.RemoveAllNodes(datadir1)

    d = StartNodeAndImport('30001', '30000', "Server 2", 0, "_2_", "xxx.com")
    datadir2 = d[0]
    address2 = d[1]

    d = StartNodeAndImport('30002', '30000', "Server 3", 0, "_3_")
    datadir3 = d[0]
    address3 = d[1]

    time.sleep(2)
    nodes = managenodes.GetNodes(datadir1)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 1")
    nodes = managenodes.GetNodes(datadir2)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 2")
    nodes = managenodes.GetNodes(datadir3)
    _lib.FatalAssert(len(nodes) == 2, "Should be 2 nodes on server 3")

    # make transaction on first node
    tx = _transfers.Send(datadir, address1, address2, 0.1)

    time.sleep(5)

    # this TX should appear on second node too
    txlist = transactions.GetUnapprovedTransactions(datadir2)
    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    tx = _transfers.Send(datadir2, address2, address1, 0.01)

    txlist = transactions.GetUnapprovedTransactions(datadir2)
    _lib.FatalAssert(
        len(txlist) == 2, "Should be 2 unapproved transactions on second node")

    time.sleep(1)
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(
        len(txlist) == 2, "Should be 2 unapproved transactions on first node")

    # make block on a secod node
    tx = _transfers.Send(datadir2, address2, address1, 0.01)
    tx = _transfers.Send(datadir2, address2, address1, 0.01)

    blocks = _blocks.WaitBlocks(datadir2, 5)
    _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 2")

    time.sleep(1)

    blocks = _blocks.WaitBlocks(datadir1, 5)
    _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 1")
    blocks = _blocks.WaitBlocks(datadir3, 5)
    _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 3")

    time.sleep(1)
    # create block on the first node and check it appears on first
    for x in range(5):
        tx = _transfers.Send(datadir, address1, address2, 0.1)

    blocks = _blocks.WaitBlocks(datadir1, 6)
    _lib.FatalAssert(len(blocks) == 6, "Should be 5 blocks on server 1")
    # extra transaction to pull
    tx = _transfers.Send(datadir, address1, address2, 0.1)

    time.sleep(7)

    # new block should be pulled
    blocks = _blocks.WaitBlocks(datadir2, 6)
    _lib.FatalAssert(len(blocks) == 6, "Should be 6 blocks on server 2")

    txlist = transactions.GetUnapprovedTransactions(datadir1)

    time.sleep(2)

    txlist = transactions.GetUnapprovedTransactions(datadir2)

    _lib.FatalAssert(
        len(txlist) == 1, "Should be 1 unapproved transactions on second node")

    startnode.StopNode(datadir1, "Server 1")
    datadir1 = ""

    startnode.StopNode(datadir2, "Server 2")
    datadir2 = ""

    startnode.StopNode(datadir3, "Server 3")
    datadir3 = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Esempio n. 7
0
def test(testfilter):
    global datadirs
    _lib.CleanTestFolders()
    #return _complex.Make5BlocksBC()
    #return _complex.PrepareNodes()

    dirs = _complex.Copy6Nodes()
    
    nodes = []
    
    i = 1
    for d in dirs:
        #get address in wallets in this dir 
        balances = _transfers.GetGroupBalance(d)
        address = balances.keys()[0]
        
        port = str(30000 + i )
        
        nodes.append({'index':i - 1, 'port':port, 'datadir':d,'address':address,"title":"Server "+str(i)})
        
        #_transfers.ReindexUTXO(d)
        #txlist = transactions.GetUnapprovedTransactions(d)
        #print txlist
        #start this node 
        #print os.path.basename(d)
        startnode.StartNodeConfig(d)
        
        i = i + 1
        datadirs.append(d)
        
    #check nodes on each node is correct 
    for node in nodes:
        #print os.path.basename(node['datadir'])
        nodeslist = managenodes.GetNodes(node['datadir'])
        
        _lib.FatalAssert(len(nodeslist) == 2,"Should be 2 nodes on "+node["title"])
        
        if node['index'] == 0:
            _lib.FatalAssert("localhost:30005" in nodeslist,"Node 6 should be on the node 0")
            _lib.FatalAssert("localhost:30004" in nodeslist,"Node 5 should be on the node 0")
        if node['index'] == 1:
            _lib.FatalAssert("localhost:30002" in nodeslist,"Node 2 should be on the node 1")
            _lib.FatalAssert("localhost:30003" in nodeslist,"Node 3 should be on the node 1")
    #raise ValueError('Stop')
    # test blocks branches
    _lib.StartTestGroup("Check blockchain before updates")
    blocks1 = _blocks.GetBlocks(nodes[0]["datadir"])
    blocks2 = _blocks.GetBlocks(nodes[1]["datadir"])
    
    _lib.FatalAssert(len(blocks1) == 9,"First branch should have 9 blocks")
    _lib.FatalAssert(len(blocks2) == 8,"Second branch should have 8 blocks")
    
    _lib.FatalAssert(blocks1[2] == blocks2[1],"7 block must be same for both")
    _lib.FatalAssert(blocks1[1] != blocks2[0],"8 block must be different")
    
    _lib.StartTestGroup("Connect subnetworks")
    managenodes.AddNode(nodes[0]["datadir"],"localhost",'30001')
   
    # wait whle blocks are exachanged
    _blocks.WaitBlocks(nodes[1]["datadir"],9)
    
    # get unapproved transactions (after block cancel)
    txlist = _transfers.WaitUnapprovedTransactions(nodes[1]["datadir"], 7)
    
    _lib.FatalAssert(len(txlist) == 7,"SHould be 7 unapproved TXs")
    
    #send another 2 TXs to have 9 required TXs
    balances = _transfers.GetGroupBalance(nodes[1]["datadir"])
    
    mainbalance = _transfers.GetGroupBalance(nodes[0]["datadir"])

    addr1 = balances.keys()[0]
    amount = "%.8f" % round(balances[addr1][0]/5,8)
    
    _transfers.Send(nodes[1]["datadir"],addr1,mainbalance.keys()[0],amount)
    _transfers.Send(nodes[1]["datadir"],addr1,mainbalance.keys()[0],amount)
    
    # wait while new block created and posted to all other
    b1 = _blocks.WaitBlocks(nodes[1]["datadir"],10)
    b2 = _blocks.WaitBlocks(nodes[0]["datadir"],10)
    
    _lib.StartTestGroup("Check blockchain after updates")
    blocks2_0 = _blocks.GetBlocks(nodes[0]["datadir"])

    _lib.FatalAssert(len(blocks2_0) == 10,"10 block must be on node 0")
    _lib.FatalAssert(blocks2_0[1] == blocks1[0],"9 block must be same for both")
    
    blocks2_1 = _blocks.GetBlocks(nodes[1]["datadir"])
    _lib.FatalAssert(len(blocks2_1) == 10,"10 block must be on node 1")
    _lib.FatalAssert(blocks2_1[1] == blocks1[0],"9 block must be same for both")
        
    _lib.StartTestGroup("Node 2 "+os.path.basename(nodes[2]["datadir"]))
    _blocks.WaitBlocks(nodes[2]["datadir"],10)
    
    blocks2_2 = _blocks.GetBlocks(nodes[2]["datadir"])
    
    _lib.FatalAssert(len(blocks2_2) == 10,"10 block must be on node 2")
    _lib.FatalAssert(blocks2_2[1] == blocks2_1[1],"2-nd from top blocks on 2 must be same as on 1")
    
    _lib.StartTestGroup("Node 3 "+os.path.basename(nodes[3]["datadir"]))
    
    _blocks.WaitBlocks(nodes[3]["datadir"],10)
    blocks2_3 = _blocks.GetBlocks(nodes[3]["datadir"])
    
    _lib.FatalAssert(len(blocks2_3) == 10,"10 block must be on node 3")
    _lib.FatalAssert(blocks2_3[1] == blocks2_1[1],"2-nd from top blocks on  3 must be same as on 1")
    
    _lib.StartTestGroup("Node 4 "+os.path.basename(nodes[4]["datadir"]))
    
    _blocks.WaitBlocks(nodes[4]["datadir"],10)
    blocks2_4 = _blocks.GetBlocks(nodes[4]["datadir"])
    
    _lib.FatalAssert(len(blocks2_4) == 10,"10 block must be on node 4")
    _lib.FatalAssert(blocks2_4[1] == blocks2_1[1],"2-nd from top blocks on 4 must be same as on 1")
    
    _lib.StartTestGroup("Node 5 "+os.path.basename(nodes[5]["datadir"]))
    
    _blocks.WaitBlocks(nodes[5]["datadir"],10)
    blocks2_5 = _blocks.GetBlocks(nodes[5]["datadir"])
    
    _lib.FatalAssert(len(blocks2_5) == 10,"10 block must be on node 5")
    _lib.FatalAssert(blocks2_5[1] == blocks2_1[1],"2-nd from top blocks on 5 must be same as on 1")
    
    _lib.StartTestGroup("Final checks")
    # should be empty list of transactions now
    transactions.GetUnapprovedTransactionsEmpty(nodes[1]["datadir"])
    
    for node in nodes:
        startnode.StopNode(node['datadir'])
        datadirs[node['index']] = ""
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Esempio n. 8
0
def test(testfilter):
    global datadirs
    _lib.CleanTestFolders()
    #return _complex.PrepareNodesWithSQL()

    _lib.StartTestGroup("Load ready BC into 6 nodes")

    dirs = _complex.Copy6NodesSQL()

    nodes = []

    i = 1
    for d in dirs:
        #get address in wallets in this dir
        balances = _transfers.GetGroupBalance(d)
        address = balances.keys()[0]

        port = str(30000 + i)

        nodes.append({
            'index': i - 1,
            'port': port,
            'datadir': d,
            'address': address,
            "title": "Server " + str(i)
        })

        #_transfers.ReindexUTXO(d)
        #txlist = transactions.GetUnapprovedTransactions(d)
        #print txlist
        #start this node
        #print os.path.basename(d)
        startnode.StartNodeConfig(d)

        i = i + 1
        datadirs.append(d)

    #check nodes on each node is correct
    for node in nodes:
        #print os.path.basename(node['datadir'])
        nodeslist = managenodes.GetNodes(node['datadir'])

        _lib.FatalAssert(
            len(nodeslist) == 2, "Should be 2 nodes on " + node["title"])

        if node['index'] == 0:
            _lib.FatalAssert("localhost:30005" in nodeslist,
                             "Node 6 should be on the node 0")
            _lib.FatalAssert("localhost:30004" in nodeslist,
                             "Node 5 should be on the node 0")
        if node['index'] == 1:
            _lib.FatalAssert("localhost:30002" in nodeslist,
                             "Node 2 should be on the node 1")
            _lib.FatalAssert("localhost:30003" in nodeslist,
                             "Node 3 should be on the node 1")
    #raise ValueError('Stop')
    # test blocks branches
    _lib.StartTestGroup("Check blockchain before updates")
    blocks1 = _blocks.GetBlocks(nodes[0]["datadir"])
    blocks2 = _blocks.GetBlocks(nodes[1]["datadir"])

    _lib.FatalAssert(len(blocks1) == 9, "First branch should have 9 blocks")
    _lib.FatalAssert(len(blocks2) == 8, "Second branch should have 8 blocks")

    _lib.FatalAssert(blocks1[2] == blocks2[1], "7 block must be same for both")
    _lib.FatalAssert(blocks1[1] != blocks2[0], "8 block must be different")

    _lib.StartTestGroup("Connect subnetworks")
    managenodes.AddNode(nodes[0]["datadir"], "localhost", '30001')

    # wait while blocks are exachanged
    _blocks.WaitBlocks(nodes[1]["datadir"], 9)

    s = 1
    time.sleep(2)

    while s < 10:
        rows1 = _lib.DBGetRows(nodes[1]['datadir'], "SELECT * FROM test", True)
        rows2 = _lib.DBGetRows(nodes[2]['datadir'], "SELECT * FROM test", True)
        rows3 = _lib.DBGetRows(nodes[3]['datadir'], "SELECT * FROM test", True)

        if ((rows1[1][1] == "row2_updated"
             or rows1[1][1] == "row2_updated_other")
                and (rows2[1][1] == "row2_updated"
                     or rows2[1][1] == "row2_updated_other")
                and (rows3[1][1] == "row2_updated"
                     or rows3[1][1] == "row2_updated_other")):
            break

        time.sleep(1)
        s = s + 1

    # get unapproved transactions (after block cancel)
    txlist = _transfers.WaitUnapprovedTransactions(nodes[1]["datadir"], 5, 15)
    #print(txlist)
    _lib.FatalAssert(
        len(txlist) == 5,
        "Should be 5 unapproved TXs, but has " + str(len(txlist)))

    #send another 2 TXs to have 9 required TXs
    balances = _transfers.GetGroupBalance(nodes[1]["datadir"])

    mainbalance = _transfers.GetGroupBalance(nodes[0]["datadir"])
    addr1 = balances.keys()[0]
    amount = "%.8f" % round(balances[addr1][0] / 5, 8)

    # add yet mode 4 TXs to complete a block
    _transfers.Send(nodes[1]["datadir"], addr1, mainbalance.keys()[0], amount)

    # 3 SQL txs
    # on another node. should go to the second node too
    _sql.ExecuteSQLOnProxy(nodes[0]['datadir'],
                           "INSERT INTO test SET b='row11', a=11")
    _sql.ExecuteSQLOnProxy(nodes[1]['datadir'],
                           "UPDATE test set b='row5_update_other' WHERE a=5")

    time.sleep(2)

    txlist = _transfers.WaitUnapprovedTransactions(nodes[0]["datadir"], 1, 10)
    # there should be minimum 1 tx, maximum 2. Because currency TX's can be based on other 1 currency TX's that are not yet on other nodes (from canceled block)
    _lib.FatalAssert(
        len(txlist) >= 1 and len(txlist) <= 2,
        "SHould be from 1 to 2 unapproved TXs on node 1")

    txlist = _transfers.WaitUnapprovedTransactions(nodes[1]["datadir"], 8, 10)

    _lib.FatalAssert(len(txlist) == 8, "SHould be 8 unapproved TXs")

    # after this TX new block should be created
    _sql.ExecuteSQLOnProxy(
        nodes[1]['datadir'],
        "UPDATE test set b='row11_update_other' WHERE a=11")

    # wait while new block created and posted to all other
    b1 = _blocks.WaitBlocks(nodes[1]["datadir"], 10)
    b2 = _blocks.WaitBlocks(nodes[0]["datadir"], 10)

    _lib.StartTestGroup("Check blockchain after updates")
    blocks2_0 = _blocks.GetBlocks(nodes[0]["datadir"])

    _lib.FatalAssert(len(blocks2_0) == 10, "10 block must be on node 0")
    _lib.FatalAssert(blocks2_0[1] == blocks1[0],
                     "9 block must be same for both")

    blocks2_1 = _blocks.GetBlocks(nodes[1]["datadir"])
    _lib.FatalAssert(len(blocks2_1) == 10, "10 block must be on node 1")
    _lib.FatalAssert(blocks2_1[1] == blocks1[0],
                     "9 block must be same for both")

    _lib.StartTestGroup("Node 2 " + os.path.basename(nodes[2]["datadir"]))
    _blocks.WaitBlocks(nodes[2]["datadir"], 10)

    blocks2_2 = _blocks.GetBlocks(nodes[2]["datadir"])

    _lib.FatalAssert(len(blocks2_2) == 10, "10 block must be on node 2")
    _lib.FatalAssert(blocks2_2[1] == blocks2_1[1],
                     "2-nd from top blocks on 2 must be same as on 1")

    _lib.StartTestGroup("Node 3 " + os.path.basename(nodes[3]["datadir"]))

    _blocks.WaitBlocks(nodes[3]["datadir"], 10)
    blocks2_3 = _blocks.GetBlocks(nodes[3]["datadir"])

    _lib.FatalAssert(len(blocks2_3) == 10, "10 block must be on node 3")
    _lib.FatalAssert(blocks2_3[1] == blocks2_1[1],
                     "2-nd from top blocks on  3 must be same as on 1")

    _lib.StartTestGroup("Node 4 " + os.path.basename(nodes[4]["datadir"]))

    _blocks.WaitBlocks(nodes[4]["datadir"], 10)
    blocks2_4 = _blocks.GetBlocks(nodes[4]["datadir"])

    _lib.FatalAssert(len(blocks2_4) == 10, "10 block must be on node 4")
    _lib.FatalAssert(blocks2_4[1] == blocks2_1[1],
                     "2-nd from top blocks on 4 must be same as on 1")

    _lib.StartTestGroup("Node 5 " + os.path.basename(nodes[5]["datadir"]))

    _blocks.WaitBlocks(nodes[5]["datadir"], 10)
    blocks2_5 = _blocks.GetBlocks(nodes[5]["datadir"])

    _lib.FatalAssert(len(blocks2_5) == 10, "10 block must be on node 5")
    _lib.FatalAssert(blocks2_5[1] == blocks2_1[1],
                     "2-nd from top blocks on 5 must be same as on 1")

    rows1 = _lib.DBGetRows(nodes[0]['datadir'], "SELECT * FROM test", True)
    rows2 = _lib.DBGetRows(nodes[1]['datadir'], "SELECT * FROM test", True)

    _lib.FatalAssert(rows1 == rows2,
                     "Table contents on node 1 and 2 must be same")

    rows3 = _lib.DBGetRows(nodes[2]['datadir'], "SELECT * FROM test", True)

    _lib.FatalAssert(rows1 == rows3,
                     "Table contents on node 1 and 3 must be same")

    rows4 = _lib.DBGetRows(nodes[3]['datadir'], "SELECT * FROM test", True)

    _lib.FatalAssert(rows1 == rows4,
                     "Table contents on node 1 and 4 must be same")

    rows5 = _lib.DBGetRows(nodes[4]['datadir'], "SELECT * FROM test", True)

    _lib.FatalAssert(rows1 == rows5,
                     "Table contents on node 1 and 5 must be same")

    rows6 = _lib.DBGetRows(nodes[5]['datadir'], "SELECT * FROM test", True)

    _lib.FatalAssert(rows1 == rows6,
                     "Table contents on node 1 and 6 must be same")

    _lib.StartTestGroup("Final checks")
    # should be empty list of transactions now
    transactions.GetUnapprovedTransactionsEmpty(nodes[1]["datadir"])

    for node in nodes:
        startnode.StopNode(node['datadir'])
        datadirs[node['index']] = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Esempio n. 9
0
def PrepareNodes():
    
    nodeport = '30000'
    
    _lib.StartTestGroup("Wallet Balance")
    
    _lib.CleanTestFolders()
    
    datadir_tmp = CopyBlockchainWithBlocks("_1_")
    
    blocks = _blocks.GetBlocks(datadir_tmp)
    
    balances = _transfers.GetGroupBalance(datadir_tmp)
    
    datadirs = []
    
    address1 = balances.keys()[0]
    
    # address1_3 becomes a minter. we will send money from other 2 and this will receive rewards
    startnode.StartNode(datadir_tmp, address1,nodeport)
    datadir = datadir_tmp
    datadirs.append(datadir_tmp)
    
    nodes = []
    
    for i in range(1, 6):
        port = str(30000+i)
        d = blocksnodes.StartNodeAndImport(port, nodeport, "Server "+str(i),"_"+str(i+1)+"_")
        datadir_n = d[0]
        address_n = d[1]
        
        nodes.append({'number':i, 'port':port, 'datadir':datadir_n,'address':address_n})
        datadirs.append(datadir_n)
    
    _lib.StartTestGroup("Temp Data Dirs")
    _lib.StartTest("Node 0 "+os.path.basename(datadir))
    
    for node in nodes:
        _lib.StartTest("Node "+str(node['number'])+" "+os.path.basename(node['datadir']))
        
    # commmon transfer of blocks between nodes
    _lib.StartTestGroup("Transfer of blocks between nodes")
    
    blocks = _blocks.GetBlocks(datadir)
    blockslen = len(blocks)
    
    balance1 = _transfers.GetBalance(datadir, address1)
    as1 = "%.8f" % round(balance1[0]/10,8)
    
    # should be 6 transactions
    _transfers.Send(datadir,address1, nodes[0]['address'] ,as1)
    _transfers.Send(datadir,address1, nodes[1]['address'] ,as1)
    _transfers.Send(datadir,address1, nodes[2]['address'] ,as1)
    
    _transfers.Send(datadir,address1, nodes[0]['address'] ,as1)
    _transfers.Send(datadir,address1, nodes[1]['address'] ,as1)
    _transfers.Send(datadir,address1, nodes[2]['address'] ,as1)
    
    blocks = _blocks.WaitBlocks(datadir, blockslen + 1)
    
    _lib.FatalAssert(len(blocks) == blockslen + 1, "Expected "+str(blockslen +1)+" blocks")
    
    #wait while block is posted to all other nodes
    time.sleep(1)
    # check on each node
    for node in nodes:
        blocks = _blocks.WaitBlocks(node['datadir'], blockslen + 1)
        _lib.FatalAssert(len(blocks) == blockslen + 1, "Expected "+str(blockslen +1)+" blocks o node "+str(node['number']))
    
    _lib.StartTestGroup("Create 2 branches of blockchain")
    
    # remove connection between subnetworks
    managenodes.RemoveAllNodes(nodes[0]['datadir'])
    managenodes.RemoveAllNodes(nodes[1]['datadir'])
    managenodes.RemoveAllNodes(nodes[2]['datadir'])
    managenodes.RemoveAllNodes(nodes[3]['datadir'])
    managenodes.RemoveAllNodes(nodes[4]['datadir'])
    managenodes.RemoveAllNodes(datadir)
    
    # first group - main and 4,5 nodes
    managenodes.AddNode(datadir,"localhost",'30004')
    managenodes.AddNode(datadir,"localhost",'30005')
    managenodes.AddNode(nodes[3]['datadir'],"localhost",'30005')
    
    #second group 1,2,3
    managenodes.AddNode(nodes[0]['datadir'],"localhost",'30002')
    managenodes.AddNode(nodes[0]['datadir'],"localhost",'30003')
    managenodes.AddNode(nodes[1]['datadir'],"localhost",'30003')
    
    time.sleep(1)
    
    #check nodes
    
    nodes0 = managenodes.GetNodes(datadir)
    _lib.FatalAssert("localhost:30005", "Node 5 is not in the list of 0")
    _lib.FatalAssert("localhost:30004", "Node 4 is not in the list of 0")
    
    nodes1 = managenodes.GetNodes(nodes[0]['datadir'])
    
    _lib.FatalAssert("localhost:30002", "Node 2 is not in the list of 1")
    _lib.FatalAssert("localhost:30003", "Node 3 is not in the list of 1")
    
    nodes2 = managenodes.GetNodes(nodes[1]['datadir'])
    
    _lib.FatalAssert("localhost:30001", "Node 1 is not in the list of 2")
    _lib.FatalAssert("localhost:30003", "Node 3 is not in the list of 2")
    
    _lib.StartTestGroup("2 new blocks on first branch")
    
    balance1 = _transfers.GetBalance(datadir, address1)
    as1 = "%.8f" % round(balance1[0]/20,8)
    
    # 7 TX for 8-th block
    tx = [""] * 15
    tx[0] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[0]
    tx[1] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[1]
    tx[2] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[2]
    tx[3] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[3]
    tx[4] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[4]
    tx[5] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[5]
    tx[6] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    print tx[6]
    
    time.sleep(7)
    # 8 TX for 9-th block
    tx[7] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[7]
    tx[8] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[8]
    tx[9] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[9]
    tx[10] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[10]
    tx[11] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[11]
    tx[12] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[12]
    tx[13] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[13]
    tx[14] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    print tx[14]
    
    blocks1 = _blocks.WaitBlocks(nodes[4]['datadir'], blockslen + 3)
    time.sleep(3)
    
    _lib.FatalAssert(len(blocks1) == blockslen + 3, "Expected "+str(blockslen +3)+" blocks for branch 1")
    
    _lib.StartTestGroup("1 new block on second branch")
    
    balance2 = _transfers.GetBalance(nodes[0]['datadir'], nodes[0]['address'])
    as2 = "%.8f" % round(balance2[0]/10,8)
    
    # 7 new TX
    tx1 = _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[1]['address'] ,as2)
    tx2 = _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    tx3 = _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    
    blocks2 = _blocks.WaitBlocks(nodes[2]['datadir'], blockslen + 2)
    _lib.FatalAssert(len(blocks2) == blockslen + 2, "Expected "+str(blockslen +2)+" blocks for branch 2")
    
    dstdir = _lib.getCurrentDir()+"/datafortests/"
    #configs for cluster 1
    copyConfig(datadir, dstdir+"bc6nodes_1/config.t", address1, nodeport, nodes[3]['port'], nodes[4]['port'])
    
    copyConfig(nodes[3]['datadir'], dstdir+"bc6nodes_5/config.t", nodes[3]['address'], nodes[3]['port'], nodeport, nodes[4]['port'])
    
    copyConfig(nodes[4]['datadir'], dstdir+"bc6nodes_6/config.t", nodes[4]['address'], nodes[4]['port'], nodeport, nodes[3]['port'])
    
    #config for cluster 2
    copyConfig(nodes[0]['datadir'], dstdir+"bc6nodes_2/config.t", nodes[0]['address'], nodes[0]['port'], nodes[1]['port'], nodes[2]['port'])
    
    copyConfig(nodes[1]['datadir'], dstdir+"bc6nodes_3/config.t", nodes[1]['address'], nodes[1]['port'], nodes[0]['port'], nodes[2]['port'])
    
    copyConfig(nodes[2]['datadir'], dstdir+"bc6nodes_4/config.t", nodes[2]['address'], nodes[2]['port'], nodes[0]['port'], nodes[1]['port'])
    
    #print os.path.basename(datadir)
    startnode.StopNode(datadir)
    
    dstdir = _lib.getCurrentDir()+"/datafortests/bc6nodes_1/"
    #print dstdir

    copyfile(datadir+"/wallet.dat", dstdir+"wallet.t")
    
    try:
        os.remove(dstdir+"db.sql")
    except OSError:
        pass

    DumpBCDB(datadir, dstdir+"db.sql")
    
    i = 2
    
    for node in nodes:
        #print os.path.basename(node['datadir'])
        startnode.StopNode(node['datadir'])
        
        dstdir = _lib.getCurrentDir()+"/datafortests/bc6nodes_"+str(i)+"/"
        #print dstdir
        copyfile(node['datadir']+"/wallet.dat", dstdir+"wallet.t")
        
        try:
            os.remove(dstdir+"db.sql")
        except OSError:
            pass
        
        DumpBCDB(node['datadir'], dstdir+"db.sql")
        
        i=i+1
    
    return [datadir, address1, nodes, blockslen+1, datadirs]
Esempio n. 10
0
def PrepareNodesWithSQL():
    
    nodeport = '30000'
    
    _lib.StartTestGroup("Prepare 6 nodes with SQL commands in BC")
    
    _lib.CleanTestFolders()
    
    datadir_tmp = CopyBlockchainWithBlocks("_1_")
    
    blocks = _blocks.GetBlocks(datadir_tmp)
    
    balances = _transfers.GetGroupBalance(datadir_tmp)
    
    datadirs = []
    
    address1 = balances.keys()[0]
    
    # address1_3 becomes a minter. we will send money from other 2 and this will receive rewards
    AddProxyToConfig(datadir_tmp, "localhost:40040")
    AddInternalKeyToConfig(datadir_tmp, address1) # init internal signing
    
    startnode.StartNode(datadir_tmp, address1,nodeport)
    datadir = datadir_tmp
    datadirs.append(datadir_tmp)
    
    nodes = []
    
    for i in range(1, 6):
        port = str(30000+i)
        dbproxyport = str(40040+i)
        d = blocksnodes.StartNodeAndImport(port, nodeport, "Server "+str(i), int(dbproxyport),"_"+str(i+1)+"_")
        datadir_n = d[0]
        address_n = d[1]
        
        nodes.append({'number':i, 'port':port, 'datadir':datadir_n,'address':address_n,'proxyport':dbproxyport})
        datadirs.append(datadir_n)
    
    _lib.StartTestGroup("Temp Data Dirs")
    _lib.StartTest("Node 0 "+os.path.basename(datadir))
    
    for node in nodes:
        _lib.StartTest("Node "+str(node['number'])+" "+os.path.basename(node['datadir']))
        
    # commmon transfer of blocks between nodes
    _lib.StartTestGroup("Transfer of blocks between nodes")
    
    blocks = _blocks.GetBlocks(datadir)
    blockslen = len(blocks)
    
    balance1 = _transfers.GetBalance(datadir, address1)
    as1 = "%.8f" % round(balance1[0]/10,8)
    
    # should be 6 transactions. 3 currency and 3 SQL
    _transfers.Send(datadir,address1, nodes[0]['address'] ,as1)
    _transfers.Send(datadir,address1, nodes[1]['address'] ,as1)
    _transfers.Send(datadir,address1, nodes[2]['address'] ,as1)
    
    _sql.ExecuteSQLOnProxy(datadir,"CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row1'")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET a=2,b='row2'")
    
    blocks = _blocks.WaitBlocks(datadir, blockslen + 1)
    
    _lib.FatalAssert(len(blocks) == blockslen + 1, "Expected "+str(blockslen +1)+" blocks")
    
    #wait while block is posted to all other nodes
    time.sleep(2)
    # check on each node
    for node in nodes:
        blocks = _blocks.WaitBlocks(node['datadir'], blockslen + 1)
        _lib.FatalAssert(len(blocks) == blockslen + 1, "Expected "+str(blockslen +1)+" blocks o node "+str(node['number']))
    
    _lib.StartTestGroup("Create 2 branches of blockchain")
    
    while True:
        time.sleep(4)# to complete all operations in progress
    
        
    
        # remove connection between subnetworks
        managenodes.RemoveAllNodes(nodes[0]['datadir'])
        managenodes.RemoveAllNodes(nodes[1]['datadir'])
        managenodes.RemoveAllNodes(nodes[2]['datadir'])
        managenodes.RemoveAllNodes(nodes[3]['datadir'])
        managenodes.RemoveAllNodes(nodes[4]['datadir'])
        managenodes.RemoveAllNodes(datadir)
    
        time.sleep(1)
        nodes0 = managenodes.GetNodes(datadir)
        nodes1 = managenodes.GetNodes(nodes[0]['datadir'])
        nodes2 = managenodes.GetNodes(nodes[1]['datadir'])
        
        if len(nodes0) == 0 and len(nodes1) == 0 and len(nodes2) == 0:
            break
        _lib.StartTestGroup("Nodes addresses are still not clean")
        
    # first group - main and 4,5 nodes
    managenodes.AddNode(datadir,"localhost",'30004')
    managenodes.AddNode(datadir,"localhost",'30005')
    managenodes.AddNode(nodes[3]['datadir'],"localhost",'30005')
    
    #second group 1,2,3
    managenodes.AddNode(nodes[0]['datadir'],"localhost",'30002')
    managenodes.AddNode(nodes[0]['datadir'],"localhost",'30003')
    managenodes.AddNode(nodes[1]['datadir'],"localhost",'30003')
    
    time.sleep(1)
    
    #check nodes
    
    nodes0 = managenodes.GetNodes(datadir)
    _lib.FatalAssert("localhost:30005", "Node 5 is not in the list of 0")
    _lib.FatalAssert("localhost:30004", "Node 4 is not in the list of 0")
    
    nodes1 = managenodes.GetNodes(nodes[0]['datadir'])
    
    _lib.FatalAssert("localhost:30002", "Node 2 is not in the list of 1")
    _lib.FatalAssert("localhost:30003", "Node 3 is not in the list of 1")
    
    nodes2 = managenodes.GetNodes(nodes[1]['datadir'])
    
    _lib.FatalAssert("localhost:30001", "Node 1 is not in the list of 2")
    _lib.FatalAssert("localhost:30003", "Node 3 is not in the list of 2")
    
    _lib.StartTestGroup("2 new blocks on first branch")
    
    balance1 = _transfers.GetBalance(datadir, address1)
    as1 = "%.8f" % round(balance1[0]/20,8)
    
    # 7 TX for 8-th block
    tx = [""] * 15
    tx[0] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    
    tx[1] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    
    tx[2] = _transfers.Send(datadir,address1, nodes[3]['address'] ,as1)
    
    _sql.ExecuteSQLOnProxy(datadir,"UPDATE test SET b='row2_updated' WHERE a=2")
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row3'")
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row4'")
    
    _sql.ExecuteSQLOnProxy(datadir,"UPDATE test SET b='row4_updated' WHERE a=4")
    
    time.sleep(7)
    # 8 TX for 9-th block
    tx[7] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    
    tx[8] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    
    tx[9] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    
    tx[10] = _transfers.Send(datadir,address1, nodes[4]['address'] ,as1)
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row7', a=7")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row8', a=8")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row9', a=9")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row10', a=10")
    
    blocks1 = _blocks.WaitBlocks(nodes[4]['datadir'], blockslen + 3)
    time.sleep(3)
    
    _lib.FatalAssert(len(blocks1) == blockslen + 3, "Expected "+str(blockslen +3)+" blocks for branch 1")
    
    rows = _lib.DBGetRows(nodes[3]['datadir'],"SELECT * FROM test",True)
    _lib.FatalAssert(len(rows) == 8, "Must be 8 rows in a table on 3-th node")
    
    rows = _lib.DBGetRows(nodes[4]['datadir'],"SELECT * FROM test",True)
    _lib.FatalAssert(len(rows) == 8, "Must be 8 rows in a table on 4-th node")
    
    _lib.StartTestGroup("1 new block on second branch")
    
    balance2 = _transfers.GetBalance(nodes[0]['datadir'], nodes[0]['address'])
    as2 = "%.8f" % round(balance2[0]/10,8)
    
    # 7 new TX
    _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[1]['address'] ,as2)
    _transfers.Send(nodes[0]['datadir'], nodes[0]['address'], nodes[2]['address'] ,as2)
    
    # unique row
    _sql.ExecuteSQLOnProxy(nodes[0]['datadir'],"INSERT INTO test SET b='row5', a = 5")
    # identical as in parallel
    _sql.ExecuteSQLOnProxy(nodes[0]['datadir'],"INSERT INTO test SET b='row7', a=7")
    # other value and same ID
    _sql.ExecuteSQLOnProxy(nodes[0]['datadir'],"INSERT INTO test SET b='row3_other', a=3")
    # update same
    _sql.ExecuteSQLOnProxy(nodes[0]['datadir'],"UPDATE test SET b='row2_updated_other' WHERE a=2")
    # delete
    _sql.ExecuteSQLOnProxy(nodes[0]['datadir'],"DELETE FROM test WHERE a=7")
    
    blocks2 = _blocks.WaitBlocks(nodes[0]['datadir'], blockslen + 2)
    _lib.FatalAssert(len(blocks2) == blockslen + 2, "Expected "+str(blockslen +2)+" blocks for branch 2. Node 1")
    
    blocks2 = _blocks.WaitBlocks(nodes[1]['datadir'], blockslen + 2)
    _lib.FatalAssert(len(blocks2) == blockslen + 2, "Expected "+str(blockslen +2)+" blocks for branch 2. Node 2")
    
    blocks2 = _blocks.WaitBlocks(nodes[2]['datadir'], blockslen + 2)
    _lib.FatalAssert(len(blocks2) == blockslen + 2, "Expected "+str(blockslen +2)+" blocks for branch 2. Node 2")
    
    time.sleep(3)# to allow to update all references after block add
    
    #rows = _lib.DBGetRows(datadir,"SELECT * FROM test",True)
    #print "0",rows
    #rows = _lib.DBGetRows(nodes[0]['datadir'],"SELECT * FROM test",True)
    #print "1",rows
    #rows = _lib.DBGetRows(nodes[1]['datadir'],"SELECT * FROM test",True)
    #print "2",rows
    #rows = _lib.DBGetRows(nodes[2]['datadir'],"SELECT * FROM test",True)
    #print "3",rows
    #rows = _lib.DBGetRows(nodes[3]['datadir'],"SELECT * FROM test",True)
    #print "4",rows
    #rows = _lib.DBGetRows(nodes[4]['datadir'],"SELECT * FROM test",True)
    #print "5",rows
    
    # index 2 is 4-th node (3-rd in second network)
    rows = _lib.DBGetRows(nodes[2]['datadir'],"SELECT * FROM test",True)
    
    _lib.FatalAssert(len(rows) == 4, "Must be 4 rows in a table on 4-th node")
    
    dstdir = _lib.getCurrentDir()+"/datafortests/"
    #configs for cluster 1
    copyConfig(datadir, dstdir+"bc6nodessql_1/config.t", address1, nodeport, nodes[3]['port'], nodes[4]['port'])
    
    copyConfig(nodes[3]['datadir'], dstdir+"bc6nodessql_5/config.t", nodes[3]['address'], nodes[3]['port'], nodeport, nodes[4]['port'])
    
    copyConfig(nodes[4]['datadir'], dstdir+"bc6nodessql_6/config.t", nodes[4]['address'], nodes[4]['port'], nodeport, nodes[3]['port'])
    
    #config for cluster 2
    copyConfig(nodes[0]['datadir'], dstdir+"bc6nodessql_2/config.t", nodes[0]['address'], nodes[0]['port'], nodes[1]['port'], nodes[2]['port'])
    
    copyConfig(nodes[1]['datadir'], dstdir+"bc6nodessql_3/config.t", nodes[1]['address'], nodes[1]['port'], nodes[0]['port'], nodes[2]['port'])
    
    copyConfig(nodes[2]['datadir'], dstdir+"bc6nodessql_4/config.t", nodes[2]['address'], nodes[2]['port'], nodes[0]['port'], nodes[1]['port'])
    
    #print os.path.basename(datadir)
    startnode.StopNode(datadir)
    
    dstdir = _lib.getCurrentDir()+"/datafortests/bc6nodessql_1/"
    #print dstdir

    copyfile(datadir+"/wallet.dat", dstdir+"wallet.t")
    
    try:
        os.remove(dstdir+"db.sql")
    except OSError:
        pass

    DumpBCDB(datadir, dstdir+"db.sql")
    
    i = 2
    
    for node in nodes:
        #print os.path.basename(node['datadir'])
        startnode.StopNode(node['datadir'])
        
        dstdir = _lib.getCurrentDir()+"/datafortests/bc6nodessql_"+str(i)+"/"
        #print dstdir
        copyfile(node['datadir']+"/wallet.dat", dstdir+"wallet.t")
        
        try:
            os.remove(dstdir+"db.sql")
        except OSError:
            pass
        
        DumpBCDB(node['datadir'], dstdir+"db.sql")
        
        i=i+1
    
    return [datadir, address1, nodes, blockslen+1, datadirs]