Ejemplo n.º 1
0
def StopNode(datadir, comment=""):
    _lib.StartTestGroup("Stop node " + comment)
    # get process of the node. find this process exists
    _lib.StartTest("Check node state")
    res = _lib.ExecuteNode(['nodestate', '-configdir', datadir])
    _lib.FatalAssertSubstr(res, "Server is running",
                           "Server should be runnning")

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

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

    PID = int(match.group(1))

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

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

    _lib.CheckPIDNotRunning(PID, 7)

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

    _lib.StartTest("Stop node again")
    res = _lib.ExecuteNode(['stopnode', '-configdir', datadir])
    _lib.FatalAssert(res == "", "Should not be any output on succes stop")
Ejemplo n.º 2
0
def ExecuteSQLOnProxySign(datadir,sqlcommand, pub_key, pri_key, success = True):
    _lib.StartTest("Execute SQL on Proxy with external sign "+sqlcommand)
    
    sqlgetinfo = sqlcommand + "/* PUBKEY:"+str(pub_key)+"; */"
    
    rows = _lib.DBGetRows(datadir, sqlgetinfo, True)
    
    signData = {}
    
    for row in rows:
        signData[row[0]] = row[1]
    
    _lib.FatalAssert(len(signData),"Problem getting signature info")
    
    stringtosign = signData["StringToSign"].decode('hex')
    
    sig = pri_key.sign(stringtosign,sigencode=ecdsa.util.sigencode_der)
    
    sig = sig.encode('hex')
    
    finalsql = sqlcommand+"/* DATA:"+signData["Transaction"]+"; SIGN:"+sig+";*/"
    
    res = _lib.DBExecute(datadir,finalsql,True)
    
    if success:
        _lib.FatalAssert(res=="","Error for proxy SQL call: "+res)
    else:
        _lib.FatalAssert(res!="","Error expected for the SQL call")

    return True
Ejemplo n.º 3
0
def test(testfilter):
    global datadir1
    global datadir2
    
    _lib.StartTestGroup("Run node with 30 blocks and test import from second node")
    
    _lib.CleanTestFolders()
    
    inf = blocksnodes.MakeBlockchainWithBlocks('30000')
    datadir = inf[0]
    address1 = inf[1]
    address1_2 = inf[2]
    address1_3 = inf[3]
    
    for x in range(5, 31):
        _lib.StartTestGroup("Create block #"+str(x))
        for y in range(0, x-1):
            tx=_transfers.Send(datadir,address1,address1_2,0.001)
        
        txlist = transactions.GetUnapprovedTransactions(datadir)
        _lib.FatalAssert(len(txlist) == x-1,"Should be "+str(x-1)+" unapproved transaction")
        
        blockchash = _blocks.MintBlock(datadir,address1)
        blocks = _blocks.WaitBlocks(datadir, x)
        _lib.FatalAssert(len(blocks) == x,"Should be "+str(x)+" blocks on server 1")
    
    
    #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1")
    startnode.StartNode(datadir, address1,'30000', "Server 1")
    datadir1 = datadir
    managenodes.RemoveAllNodes(datadir1)
    
    d = pullsync.StartNodeAndImport('30001', '30000', "Server 2", 0, "_2_", "xxx.com" )
    datadir2 = d[0]
    address2 = d[1]
    
    blocks = _blocks.GetBlocks(datadir2)
    
    # wait when all 30 bocks are on node 2
    blocks = _blocks.WaitBlocks(datadir2, 30, 100)# 100 sec
    
    _lib.FatalAssert(len(blocks) == 30,"Should be 17 blocks on server 2")
    
    startnode.StopNode(datadir1,"Server 1")
    datadir1 = ""
    
    time.sleep(4)# allow to complete blocks adding
    startnode.StopNode(datadir2,"Server 2")
    datadir2 = ""
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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
Ejemplo n.º 6
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]
Ejemplo n.º 7
0
def ExecuteSQLOnProxyFail(datadir,sqlcommand):
    _lib.StartTest("Execute SQL on Proxy "+sqlcommand)

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

    return True
Ejemplo n.º 8
0
def ExecuteSQLOnProxy(datadir,sqlcommand):
    _lib.StartTest("Execute SQL on Proxy "+sqlcommand)

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

    return True
Ejemplo n.º 9
0
def RemoveAllNodes(datadir):
    nodes = GetNodes(datadir)

    for n in nodes:
        nv = nodes[n]
        RemoveNode(datadir, nv[0], nv[1])

    nodes = GetNodes(datadir)

    _lib.FatalAssert(len(nodes) == 0, "Should be 0 nodes in output")
Ejemplo n.º 10
0
def test(testfilter):
    global datadir1
    global datadir2

    _lib.StartTestGroup("Import long blockchain")

    _lib.CleanTestFolders()

    _lib.StartTestGroup("Copy blockchain from dataset")

    datadir1 = _lib.CreateTestFolder()
    datadir2 = _lib.CreateTestFolder()

    _lib.CopyTestData(datadir1, "bigchain")

    balances = _transfers.GetGroupBalance(datadir1)
    address = balances.keys()[0]

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

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

    #managenodes.RemoveAllNodes(datadir1)

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

    #managenodes.RemoveAllNodes(datadir2)

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

    blocks1 = _blocks.GetBlocks(datadir1)

    state = _node.NodeState(datadir1)

    _node.WaitBlocksInState(datadir2, len(blocks1), 120)

    blocks2 = _blocks.WaitBlocks(datadir2, len(blocks1), 120)

    #print len(blocks1), len(blocks2)

    _lib.FatalAssert(
        len(blocks1) == len(blocks2),
        "Number of bocks must be same on both servers")

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

    datadir1 = ""
    datadir2 = ""

    _lib.EndTestGroupSuccess()
Ejemplo n.º 11
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]
Ejemplo n.º 12
0
def GetBalance(datadir, address):
    _lib.StartTest("Request balance for a node wallet " + address)
    res = _lib.ExecuteNode(
        ['getbalance', '-configdir', datadir, "-address", address])
    _lib.FatalAssertSubstr(res, "Balance of", "Balance info is not found")

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

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

    addr = match.group(1)

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

    balance = [0, 0, 0]

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

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

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

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

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

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

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

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

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

    return balance
Ejemplo n.º 13
0
def test(testfilter):
    global datadir, datadir2

    _lib.StartTestGroup("SQL basic")

    _lib.CleanTestFolders()

    datadir = _lib.CreateTestFolder('_1_')
    datadir2 = _lib.CreateTestFolder('_2_')

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

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    tx1 = _sql.ExecuteSQL(
        datadir, address,
        "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")

    # check new table exists
    tables = _lib.DBGetRows(datadir, "SHOW TABLES")
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break

    _lib.FatalAssert(found, "Table not found in the DB")

    blocks = _blocks.WaitBlocks(datadir, 2)

    tx2 = _sql.ExecuteSQL(datadir, address, "INSERT INTO test SET b='row1'")
    tx3 = _sql.ExecuteSQL(datadir, address,
                          "INSERT INTO test SET a=2,b='row2'")
    time.sleep(1)
    tx4 = _sql.ExecuteSQL(datadir, address,
                          "INSERT INTO test (b) VALUES ('row3')")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")

    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table")

    blocks = _blocks.WaitBlocks(datadir, 3)

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

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

    # update data
    _sql.ExecuteSQL(datadir, address,
                    " update test SET b=\"row3 updated\" where a=3")
    _sql.ExecuteSQL(datadir, address,
                    " update test SET b=\"row2 updated\" where a = '2'")

    blocks = _blocks.WaitBlocks(datadir, 4)
    time.sleep(1)  # while all caches are cleaned

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")
    for row in rows:
        if row[0] == "1":
            _lib.FatalAssert(row[1] == "row1",
                             "Row 1 value is wrong. Got: " + row[1])

        if row[0] == "2":
            _lib.FatalAssert(row[1] == "row2 updated",
                             "Row 2 value is wrong. Got: " + row[1])

        if row[0] == "3":
            _lib.FatalAssert(row[1] == "row3 updated",
                             "Row 3 value is wrong. Got: " + row[1])

    error = _sql.ExecuteSQLFailure(datadir, address,
                                   "INSERT INTO test SET a=2,b='row2'")

    txid = _sql.ExecuteSQL(datadir, address, " DELETE  from   test where a=3")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")
    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table")

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

    startnode.StartNode(datadir2, address2, '30001', "Server 2")
    blocks = _blocks.WaitBlocks(datadir2, 4)

    # must be 3 rows because delete transaction was not posted to that node
    # but this will be changed in 3 seconds. we do this check less 3 seconds after server start
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test")
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table")

    txid = _sql.ExecuteSQL(datadir, address, " DELETE  from   test where a=2")

    time.sleep(2)
    # should be 1 row on first node
    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")

    _lib.FatalAssert(len(rows) == 1, "Must be 1 rows in a table")

    time.sleep(1)  # give time to send transaction
    # and 2 row on second
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test")

    _lib.FatalAssert(len(rows) == 1, "Must be 1 rows in a table")

    startnode.StopNode(datadir)
    datadir = ""

    startnode.StopNode(datadir2)
    datadir2 = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 14
0
def test(testfilter):
    global datadir

    nodeport = '30000'

    _lib.StartTestGroup("Wallet Balance")

    _lib.CleanTestFolders()

    datadir_tmp = CopyBlockchainWithBlocks()

    balances = _transfers.GetGroupBalance(datadir_tmp)

    address1 = balances.keys()[0]
    address1_2 = balances.keys()[1]
    address1_3 = balances.keys()[2]

    balance = _transfers.GetBalance(datadir_tmp, address1)

    _lib.FatalAssert(balance[0] == balances[address1][0],
                     "Balance is different from group result")
    # address1_3 becomes a minter. we will send money from other 2 and this will receive rewards
    startnode.StartNode(datadir_tmp, address1_3, nodeport)
    datadir = datadir_tmp

    blocks = _blocks.GetBlocks(datadir)
    blockslen = len(blocks)

    #create 2 wallet locations and 2 wallets in each of them
    walletdatadir1 = _lib.CreateTestFolder("wallet")
    walletdatadir2 = _lib.CreateTestFolder("wallet")

    addresses = _wallet.GetWallets(walletdatadir2)

    _lib.FatalAssert(len(addresses) == 0, "Expected 0 wallets")

    waddress1_1 = _wallet.CreateWallet(walletdatadir1)
    waddress1_2 = _wallet.CreateWallet(walletdatadir1)

    waddress2_1 = _wallet.CreateWallet(walletdatadir2)
    waddress2_2 = _wallet.CreateWallet(walletdatadir2)

    addresses = _wallet.GetWallets(walletdatadir2)

    _lib.FatalAssert(len(addresses) == 2, "Expected 2 wallets")

    addresses = _wallet.GetWallets(walletdatadir1)

    _lib.FatalAssert(
        len(addresses) == 2, "Expected 2 wallets for second folder")

    #send some funds to all that wallets
    amounttosend = "%.8f" % round(balances[address1][0] / 8, 8)

    # for next block minimum 6 TXt are required
    _transfers.Send(datadir, address1, waddress1_1, amounttosend)
    tx2_1 = _transfers.Send(datadir, address1, waddress1_2, amounttosend)
    _transfers.Send(datadir, address1, waddress2_1, amounttosend)
    _transfers.Send(datadir, address1, waddress1_1, amounttosend)
    _transfers.Send(datadir, address1, waddress1_1, amounttosend)
    _transfers.Send(datadir, address1, waddress1_1, amounttosend)

    # we control how blocks are created. here we wait on a block started and then send another 3 TX
    # we will get 2 more blocks here
    #blocks = _blocks.WaitBlocks(datadir, blockslen + 1)
    time.sleep(3)
    #_lib.FatalAssert(len(blocks) == blockslen + 1, "Expected "+str(blockslen + 1)+" blocks")

    # 7 TX are required  for next block
    _transfers.Send(datadir, address1, waddress2_2, amounttosend)

    amounttosend2 = "%.8f" % round(balances[address1_2][0] / 8, 8)

    _transfers.Send(datadir, address1_2, waddress1_1, amounttosend2)
    tx2_2 = _transfers.Send(datadir, address1_2, waddress1_2, amounttosend2)

    _transfers.Send(datadir, address1_2, waddress1_2, amounttosend2)
    _transfers.Send(datadir, address1_2, waddress1_2, amounttosend2)
    _transfers.Send(datadir, address1_2, waddress1_2, amounttosend2)
    _transfers.Send(datadir, address1_2, waddress1_2, amounttosend2)

    # wait to complete blocks
    blocks = _blocks.WaitBlocks(datadir, blockslen + 2)
    time.sleep(5)
    _lib.FatalAssert(
        len(blocks) == blockslen + 2,
        "Expected " + str(blockslen + 2) + " blocks")

    #get balances on wallets
    am1 = _wallet.GetBalanceWallet(walletdatadir1, waddress1_1, "localhost",
                                   nodeport)
    am2 = _wallet.GetBalanceWallet(walletdatadir1, waddress1_2, "localhost",
                                   nodeport)
    am3 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_1, "localhost",
                                   nodeport)
    am4 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_2, "localhost",
                                   nodeport)

    _lib.FatalAssert(
        am1[1] == round(float(amounttosend) * 4 + float(amounttosend2), 8),
        "Expected balance is different for wallet 1_1")
    _lib.FatalAssert(
        am2[1] == round(float(amounttosend) + float(amounttosend2) * 5, 8),
        "Expected balance is different for wallet 1_2")
    _lib.FatalAssert(am3[1] == float(amounttosend),
                     "Expected balance is different for wallet 2_1")
    _lib.FatalAssert(am4[1] == float(amounttosend),
                     "Expected balance is different for wallet 2_2")

    #get group blances on a wallet loc
    balances_new = _transfers.GetGroupBalance(datadir)

    #get balances on node wallets

    balances1 = _wallet.GetGroupBalanceWallet(walletdatadir1, "localhost",
                                              nodeport)
    balances2 = _wallet.GetGroupBalanceWallet(walletdatadir2, "localhost",
                                              nodeport)

    _lib.FatalAssert(
        am1[1] == balances1[waddress1_1][1],
        "Expected balance is different from group listing for 1_1")
    _lib.FatalAssert(
        am2[1] == balances1[waddress1_2][1],
        "Expected balance is different from group listing for 1_2")
    _lib.FatalAssert(
        am3[1] == balances2[waddress2_1][1],
        "Expected balance is different from group listing for 2_1")
    _lib.FatalAssert(
        am4[1] == balances2[waddress2_2][1],
        "Expected balance is different from group listing for 2_2")

    newbalance1 = round(balances[address1][0] - float(amounttosend) * 7, 8)

    _lib.FatalAssert(newbalance1 == balances_new[address1][1],
                     "Expected balance is different after spending")

    #send from wallets . 8 TXs
    _wallet.Send(walletdatadir1, waddress1_1, address1, amounttosend,
                 "localhost", nodeport)
    _wallet.Send(walletdatadir1, waddress1_1, address1_2, amounttosend2,
                 "localhost", nodeport)
    _wallet.Send(walletdatadir1, waddress1_2, address1, amounttosend,
                 "localhost", nodeport)

    amounttosend3 = "%.8f" % round(float(amounttosend2) / 8, 8)

    _wallet.Send(walletdatadir1, waddress1_2, address1_2, amounttosend3,
                 "localhost", nodeport)
    _wallet.Send(walletdatadir1, waddress1_2, address1_2, amounttosend3,
                 "localhost", nodeport)
    _wallet.Send(walletdatadir1, waddress1_2, address1_2, amounttosend3,
                 "localhost", nodeport)
    _wallet.Send(walletdatadir1, waddress1_2, address1_2, amounttosend3,
                 "localhost", nodeport)
    tx2_3 = _wallet.Send(walletdatadir1, waddress1_2, address1_2,
                         amounttosend3, "localhost", nodeport)

    blocks = _blocks.WaitBlocks(datadir, blockslen + 3)
    _lib.FatalAssert(
        len(blocks) == blockslen + 3,
        "Expected " + str(blockslen + 3) + " blocks")
    time.sleep(3)

    am1_back = _wallet.GetBalanceWallet(walletdatadir1, waddress1_1,
                                        "localhost", nodeport)
    am1_expected = round(am1[1] - float(amounttosend) - float(amounttosend2),
                         8)

    _lib.FatalAssert(
        am1_back[1] == am1_expected,
        "Expected balance after sending from wallet 1_1 is wrong: " +
        str(am1_back) + ", expected " + str(am1_expected))

    am2_back = _wallet.GetBalanceWallet(walletdatadir1, waddress1_2,
                                        "localhost", nodeport)

    sa = '%0.8f' % (am2_back[1] + 0.00000001)
    _wallet.SendTooMuch(walletdatadir1, waddress1_2, address1, sa, "localhost",
                        nodeport)

    _lib.StartTestGroup("Node in config")

    _wallet.SetNodeConfig(walletdatadir1, "localhost", nodeport)

    balances1 = _wallet.GetGroupBalanceWalletNoNode(walletdatadir1)

    am1 = _wallet.GetBalanceWalletNoNode(walletdatadir1, waddress1_1)
    am2 = _wallet.GetBalanceWalletNoNode(walletdatadir1, waddress1_2)

    _lib.FatalAssert(
        am1[1] == balances1[waddress1_1][1],
        "Expected balance is different from group listing for 1_1 " +
        str(am1) + " " + str(balances1))
    _lib.FatalAssert(
        am2[1] == balances1[waddress1_2][1],
        "Expected balance is different from group listing for 1_2 " +
        str(am2) + " " + str(balances1))

    tx4 = _wallet.SendNoNode(walletdatadir1, waddress1_2, address1_2,
                             '%0.8f' % (am2[1] / 2))

    _lib.StartTestGroup("Unspent transactions")

    unspent = _wallet.GetUnspentNoNode(walletdatadir1, waddress1_2)

    txunspent = []

    for i in unspent:
        txunspent.append(i[2])

    _lib.FatalAssert(
        tx2_3 in txunspent, "Unspent TX in not in array of expected " +
        str(txunspent) + " " + str(tx2_3))

    unspent2 = _wallet.GetUnspent(walletdatadir2, waddress1_2, "localhost",
                                  nodeport)

    _lib.FatalAssert(
        len(unspent) == len(unspent2),
        "NNNumber of unspent TXs should be same. No config")

    txunspent = []

    for i in unspent2:
        txunspent.append(i[2])

    _lib.FatalAssert(tx2_3 in txunspent,
                     "Unspent TX in not in array of expected. No config")

    _lib.StartTestGroup("Get wallet history")

    history = _wallet.GetHistoryNoNode(walletdatadir1, waddress1_2)

    _lib.FatalAssert(len(history) == 12, "Expected 3 records in a history")

    history = _wallet.GetHistory(walletdatadir2, waddress2_2, "localhost",
                                 nodeport)

    _lib.FatalAssert(len(history) == 1, "Expected 1 record in a history")

    _lib.StartTestGroup("Pending balance")

    # we cancel. we don't need it anymore. for next tests we need 0 TXs
    #transactions.CancelTransaction(datadir,tx4)

    am3 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_1, "localhost",
                                   nodeport)

    addb1_2 = _transfers.GetBalance(datadir, address1_2)

    amounttosend2 = "%.8f" % round(am3[0] / 2 - 0.00000001, 8)

    _wallet.Send(walletdatadir2, waddress2_1, address1_2, amounttosend2,
                 "localhost", nodeport)

    am3_2 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_1, "localhost",
                                     nodeport)

    addb1_2_2 = _transfers.GetBalance(datadir, address1_2)

    _lib.FatalAssert(am3[1] == am3_2[1],
                     "Approved balance should be unchanged")
    _lib.FatalAssert(
        round(am3[0] - float(amounttosend2), 8) == am3_2[0],
        "Total balance should be changed")
    _lib.FatalAssert(
        round(am3[2] - float(amounttosend2), 8) == am3_2[2],
        "Pending balance should be changed")

    _lib.FatalAssert(
        round(addb1_2_2[2] - addb1_2[2], 8) == round(am3[2] - am3_2[2], 8),
        "Pending difference should be same")

    txlist = transactions.GetUnapprovedTransactions(datadir)

    amounttosend2 = "%.8f" % round(am3[1] / 2, 8)

    _wallet.Send(walletdatadir2, waddress2_1, address1_2, amounttosend2,
                 "localhost", nodeport)

    am3_3 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_1, "localhost",
                                     nodeport)

    addb1_2_3 = _transfers.GetBalance(datadir, address1_2)

    _lib.FatalAssert(am3[1] == am3_3[1],
                     "Approved balance should be unchanged")

    _lib.FatalAssert(
        math.fabs(round(am3_2[0] - float(amounttosend2), 8) - am3_3[0]) <=
        0.00000001, "Total balance should be changed")
    _lib.FatalAssert(
        math.fabs(round(am3_2[2] - float(amounttosend2) - am3_3[2], 8)) <=
        0.00000001, "Pending balance should be changed")

    _lib.FatalAssert(
        math.fabs(
            round(addb1_2_3[2] - addb1_2[2], 8) - round(am3[2] - am3_3[2], 8))
        <= 0.00000002, "Pending difference should be same after 2 sends")

    startnode.StopNode(datadir)
    datadir = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
def test(testfilter):
    global datadir1
    global datadir2

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

    _lib.CleanTestFolders()

    datadir = _lib.CreateTestFolder()

    address1_2 = transactions.CreateWallet(datadir)
    address1_3 = transactions.CreateWallet(datadir)

    _lib.CopyTestConsensusConfig(datadir, "hardpow", address1_3)

    address1_1 = startnode.InitBockchain(datadir)
    _complex.AddProxyToConfig(datadir, "localhost:40041")
    _complex.AddInternalKeyToConfig(datadir,
                                    address1_2)  # init internal signing

    startnode.StartNode(datadir, address1_1, '30000')
    datadir1 = datadir

    tx = _transfers.Send(datadir, address1_1, address1_2, 2)

    # node 1 should start minting now

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

    # list of transactions must be emoty on 2-nd node
    transactions.GetUnapprovedTransactionsEmpty(datadir2)
    time.sleep(1)
    transactions.GetUnapprovedTransactionsEmpty(datadir2)
    time.sleep(1)
    transactions.GetUnapprovedTransactionsEmpty(datadir2)
    time.sleep(1)

    # wait 2-nd block
    blocks = _blocks.WaitBlocks(datadir2, 2)
    _lib.FatalAssert(len(blocks) == 2, "Should be 2 blocks on server 2")

    # 2 new TX to make next block
    tx = _transfers.Send(datadir, address1_1, address1_2, 1)
    tx = _transfers.Send(datadir, address1_1, address1_2, 1)
    time.sleep(1)
    tx = _transfers.Send(datadir, address1_1, address1_2, 1)

    # on second node only the last TX should appear soon
    txlist = _transfers.WaitUnapprovedTransactions(datadir2, 1, 6)

    # there can be 2 cases. this TX can be based on other TX which is currently under building of a block
    # in this case TX will fail on pull
    if (len(txlist) == 0):
        # wait while 3-rd block appears, after this TX should be added
        blocks = _blocks.WaitBlocks(datadir2, 3)
        _lib.FatalAssert(len(blocks) == 3, "Should be 3 blocks on server 2")

        txlist = _transfers.WaitUnapprovedTransactions(datadir2, 1, 6)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 transaction on server 2")

    _lib.FatalAssert(tx in txlist.keys(), "3-rd TX shoul be in keys")

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

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

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 17
0
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]
Ejemplo n.º 18
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()
Ejemplo n.º 19
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()
Ejemplo n.º 20
0
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()
Ejemplo n.º 21
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()
Ejemplo n.º 22
0
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()
Ejemplo n.º 23
0
def test(testfilter):
    global datadir, datadir2

    _lib.StartTestGroup("SQL Sync with Proxy. care offline")

    _lib.CleanTestFolders()

    datadir = _lib.CreateTestFolder('_1_')

    startnode.StartNodeWithoutBlockchain(datadir)

    address = startnode.InitBockchain(datadir)
    _complex.AddProxyToConfig(datadir, "localhost:40041")
    _complex.AddInternalKeyToConfig(datadir, address)  # init internal signing

    startnode.StartNode(datadir, address, '30000')

    _lib.StartTestGroup("Do initial transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    _sql.ExecuteSQLOnProxy(
        datadir,
        "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")

    # check new table exists
    tables = _lib.DBGetRows(datadir, "SHOW TABLES", True)
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break

    _lib.FatalAssert(found, "Table not found in the DB")

    blocks = _blocks.WaitBlocks(datadir, 2)
    time.sleep(1)

    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET b='row1'")

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

    _complex.AddProxyToConfig(datadir2, "localhost:40042")
    _complex.AddInternalKeyToConfig(datadir2,
                                    address2)  # init internal signing

    startnode.StartNode(datadir2, address2, '30001', "Server 2")
    blocks = _blocks.WaitBlocks(datadir2, 2)

    _sql.ExecuteSQLOnProxy(datadir2, "INSERT INTO test SET b='row1.2'")

    # must be 1 row , because the first row from the first node is not yet in a block and is not synced
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 1, "Must be 1 row in a table on node 2")

    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET b='row2'")
    # should be 1 row on first node
    rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table on node 1")

    # wait 3-rd block
    blocks = _blocks.WaitBlocks(datadir, 3)

    time.sleep(1)  # give time to send transaction

    # wait 3-rd block on a second node
    blocks = _blocks.WaitBlocks(datadir2, 3)
    time.sleep(1)
    # and 2 row on second
    rows2 = _lib.DBGetRows(datadir2, "SELECT * FROM test ORDER BY a", True)
    _lib.FatalAssert(len(rows2) == 2, "Must be 2 rows in a table")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test ORDER BY a", True)
    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table")

    _lib.FatalAssert(
        set(rows) == set(rows2),
        "COntents of tables on both nodes must be same")

    _lib.StartTestGroup("Check cancel of following transactions")

    # temporary stop second node
    startnode.StopNode(datadir2)

    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET b='row3'")

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

    _sql.ExecuteSQLOnProxy(datadir2, "INSERT INTO test SET b='row3.2'")
    _sql.ExecuteSQLOnProxy(datadir,
                           "UPDATE test SET b='row3_updated' WHERE a=3")
    _sql.ExecuteSQLOnProxy(datadir2,
                           "UPDATE test SET b='row3_updated_2' WHERE a=3")

    _sql.ExecuteSQLOnProxy(datadir,
                           "UPDATE test SET b='row3_updated_again' WHERE a=3")

    blocks = _blocks.WaitBlocks(datadir, 4)
    time.sleep(1)  # give time to send transaction

    blocks = _blocks.WaitBlocks(datadir2, 4)
    time.sleep(1)  # give time to send transaction

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test ORDER BY a", True)

    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table")

    rows2 = _lib.DBGetRows(datadir2, "SELECT * FROM test ORDER BY a", True)

    _lib.FatalAssert(len(rows2) == 3, "Must be 3 rows in a table")

    _lib.FatalAssert(
        set(rows) == set(rows2),
        "COntents of tables on both nodes must be same")

    startnode.StopNode(datadir)
    datadir = ""

    startnode.StopNode(datadir2)
    datadir2 = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 24
0
def test(testfilter):
    global datadir
    
    _lib.StartTestGroup("SQL Proxy basic")

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

    startnode.StartNodeWithoutBlockchain(datadir)
    
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)
    
    _lib.CopyTestConsensusConfig(datadir,"customnumbers", address2)
    
    address = startnode.InitBockchain(datadir)
    _complex.AddProxyToConfig(datadir, "localhost:40041")
    _complex.AddInternalKeyToConfig(datadir, address3) # init internal signing

    startnode.StartNode(datadir, address, '30000')
    
    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    # address3 signs proxy transactions. it doesn't have money yet
    _transfers.Send(datadir,address, address3 ,5) # needs this to create table
    
    blocks = _blocks.WaitBlocks(datadir, 2)
    time.sleep(1)
    
    _sql.ExecuteSQLOnProxy(datadir, "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    
    tables = _lib.DBGetRows(datadir,"SHOW TABLES")
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break
        
    _lib.FatalAssert(found, "Table test not found in the DB")
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row1'")
    
    blocks = _blocks.WaitBlocks(datadir, 3)
    time.sleep(1)
    
    # now try to create paid table. it should fail because no money
    _sql.ExecuteSQLOnProxyFail(datadir, "CREATE TABLE members (id INT auto_increment PRIMARY KEY, name VARCHAR(20))")
    
    # send money
    _transfers.Send(datadir,address, address3 ,10) # this table creation costs 10 
    
    _sql.ExecuteSQLOnProxy(datadir, "CREATE TABLE members (id INT auto_increment PRIMARY KEY, name VARCHAR(20))")
    
    tables = _lib.DBGetRows(datadir,"SHOW TABLES")
    found = False
    for table in tables:
        if table[0] == "members":
            found = True
            break
    
    _lib.FatalAssert(found, "Table not found in the DB")
    
    _sql.ExecuteSQLOnProxyFail(datadir, "INSERT INTO members SET name='user1'")
    # but should be abe to isert to free table
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row2'")
    
    blocks = _blocks.WaitBlocks(datadir, 4)
    time.sleep(2)
    
    _transfers.Send(datadir,address, address3 ,1) 
    
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user1'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user2'")
    _sql.ExecuteSQLOnProxyFail(datadir, "INSERT INTO members SET name='user3'")
    
    bal1 = _transfers.GetBalance(datadir, address)
    bal2 = _transfers.GetBalance(datadir, address2)
    bal3 = _transfers.GetBalance(datadir, address3)

    _lib.FatalAssert(bal1[1] == 45.0, "Balance of a first addres is expected to be 45")
    _lib.FatalAssert(bal2[1] == 15.0, "Balance of a second addres is expected to be 15")
    _lib.FatalAssert(bal3[1] == 0.0, "Balance of a third addres is expected to be 0")
    
    startnode.StopNode(datadir)
    datadir = ""
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
    

    
Ejemplo n.º 25
0
def test(testfilter):
    global datadir, datadir2

    _lib.StartTestGroup("SQL Sync with Proxy")

    _lib.CleanTestFolders()

    datadir = _lib.CreateTestFolder('_1_')

    startnode.StartNodeWithoutBlockchain(datadir)

    address = startnode.InitBockchain(datadir)
    _complex.AddProxyToConfig(datadir, "localhost:40041")
    _complex.AddInternalKeyToConfig(datadir, address)  # init internal signing

    startnode.StartNode(datadir, address, '30000')

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    _sql.ExecuteSQLOnProxy(
        datadir,
        "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")

    # check new table exists
    tables = _lib.DBGetRows(datadir, "SHOW TABLES", True)
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break

    _lib.FatalAssert(found, "Table not found in the DB")

    blocks = _blocks.WaitBlocks(datadir, 2)
    time.sleep(2)

    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET b='row1'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET a=2,b='row2'")
    time.sleep(1)
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test (b) VALUES ('row3')")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True)

    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table")

    blocks = _blocks.WaitBlocks(datadir, 3)

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

    txlist = transactions.GetUnapprovedTransactions(datadir)

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

    # update data
    _sql.ExecuteSQLOnProxy(datadir,
                           " update test SET b=\"row3 updated\" where a=3")
    _sql.ExecuteSQLOnProxy(
        datadir, " update test SET b=\"row2 updated\" where a = '2'")

    blocks = _blocks.WaitBlocks(datadir, 4)
    time.sleep(1)  # while all caches are cleaned

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True)
    for row in rows:
        if row[0] == "1":
            _lib.FatalAssert(row[1] == "row1",
                             "Row 1 value is wrong. Got: " + row[1])

        if row[0] == "2":
            _lib.FatalAssert(row[1] == "row2 updated",
                             "Row 2 value is wrong. Got: " + row[1])

        if row[0] == "3":
            _lib.FatalAssert(row[1] == "row3 updated",
                             "Row 3 value is wrong. Got: " + row[1])

    _sql.ExecuteSQLOnProxyFail(datadir, "INSERT INTO test SET a=2,b='row2'")

    _sql.ExecuteSQLOnProxy(datadir, " DELETE  from   test where a=3")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table")

    datadir2 = _lib.CreateTestFolder('_2_')

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

    _complex.AddProxyToConfig(datadir2, "localhost:40042")
    _complex.AddInternalKeyToConfig(datadir2,
                                    address2)  # init internal signing

    startnode.StartNode(datadir2, address2, '30001', "Server 2")
    blocks = _blocks.WaitBlocks(datadir2, 4)

    # Send money to new node address
    txid1 = _transfers.Send(datadir, address, address2, 1)

    time.sleep(2)

    # must be 2 delete transaction should be imported
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test", True)

    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table")

    _sql.ExecuteSQLOnProxy(datadir, " DELETE  from   test where a=2")

    # send money again
    txid2 = _transfers.Send(datadir, address, address2, 1)

    # should be 1 row on first node
    rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 1, "Must be 1 rows in a table")

    time.sleep(1)  # give time to send transaction
    # and 2 row on second
    rows = _lib.DBGetRows(datadir2, "SELECT * FROM test", True)
    _lib.FatalAssert(len(rows) == 1, "Must be 1 rows in a table")

    blocks = _blocks.WaitBlocks(datadir, 5)
    blocks = _blocks.WaitBlocks(datadir2, 5)
    time.sleep(2)

    # send money back

    txid3 = _transfers.Send(datadir2, address2, address, 2)
    time.sleep(1)
    # insert on second node. check on first
    _sql.ExecuteSQLOnProxy(datadir2, "INSERT INTO test SET a=2,b='row2'")

    time.sleep(3)  # give time to send transaction

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True)

    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table")

    # check balances
    bal1 = _transfers.GetBalance(datadir, address)
    bal2 = _transfers.GetBalance(datadir2, address2)

    _lib.FatalAssert(bal2[2] == -2,
                     "Pending balance should be -2 for second address")
    _lib.FatalAssert(bal1[2] == 2,
                     "Pending balance should be 2 for first address")

    startnode.StopNode(datadir)
    datadir = ""

    startnode.StopNode(datadir2)
    datadir2 = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 26
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]
Ejemplo n.º 27
0
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()
Ejemplo n.º 28
0
def test(testfilter):

    
    _lib.StartTestGroup("SQL basic")

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

    address = startnode.InitBockchain(datadir)
    
    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    tx1 = _sql.ExecuteSQL(datadir,address,"CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    
    # check new table exists
    tables = _lib.DBGetRows(datadir,"SHOW TABLES")
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break
    
    _lib.FatalAssert(found, "Table not found in the DB")
    
    # now add data and make a block 
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test SET b='row1'")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test SET b='row2', a=2")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test  (b) values ('row3')")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test  (a, b) values (4, 'row4')")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test (a, b) values (8, 'row5')")
    
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row1_u1' where a=1")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row2_u1' where a = '2'")
    
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row1_u2' where a= 1")
    
    _sql.ExecuteSQL(datadir,address,"delete from test where a=3")
    
    rows = _lib.DBGetRows(datadir,"SELECT * FROM test")
    
    _lib.FatalAssert(len(rows) == 4, "Must be 4 rows in a table")
    
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    # test execution when transactions are already in a block
    _sql.ExecuteSQLFailure(datadir,address,"INSERT INTO test SET b='row2', a=2")
    _sql.ExecuteSQLFailure(datadir,address,"delete from test where a=3")
    _sql.ExecuteSQLFailure(datadir,address,"UPDATE test SET b='upd' where a=  3")
    _sql.ExecuteSQLFailure(datadir,address,"UPDATE test SET b='upd2', a=3 where a=  2")# we don't allow to change key value
    
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test (a, b) values (6, 'row6')")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row8_u1' where a=8")
    _sql.ExecuteSQL(datadir,address,"delete from test where a=2")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row8_u2' where a=8")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row6_u1' where a=6")
    
    
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
    

    
Ejemplo n.º 29
0
def test(testfilter):
    global datadir

    _lib.StartTestGroup("SQL basic")

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

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

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    tx1 = _sql.ExecuteSQL(
        datadir, address,
        "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")

    # check new table exists
    tables = _lib.DBGetRows(datadir, "SHOW TABLES")
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break

    _lib.FatalAssert(found, "Table not found in the DB")

    blocks = _blocks.WaitBlocks(datadir, 2)
    time.sleep(1)

    tx2 = _sql.ExecuteSQL(datadir, address, "INSERT INTO test SET b='row1'")
    tx3 = _sql.ExecuteSQL(datadir, address,
                          "INSERT INTO test SET a=2,b='row2'")
    time.sleep(1)
    tx4 = _sql.ExecuteSQL(datadir, address,
                          "INSERT INTO test (b) VALUES ('row3')")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")

    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table")

    blocks = _blocks.WaitBlocks(datadir, 3)

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

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

    # update data
    _sql.ExecuteSQL(datadir, address,
                    " update test SET b=\"row3 updated\" where a=3")
    _sql.ExecuteSQL(datadir, address,
                    " update test SET b=\"row2 updated\" where a = '2'")

    blocks = _blocks.WaitBlocks(datadir, 4)
    time.sleep(1)  # while all caches are cleaned

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")
    for row in rows:
        if row[0] == "1":
            _lib.FatalAssert(row[1] == "row1",
                             "Row 1 value is wrong. Got: " + row[1])

        if row[0] == "2":
            _lib.FatalAssert(row[1] == "row2 updated",
                             "Row 2 value is wrong. Got: " + row[1])

        if row[0] == "3":
            _lib.FatalAssert(row[1] == "row3 updated",
                             "Row 3 value is wrong. Got: " + row[1])

    error = _sql.ExecuteSQLFailure(datadir, address,
                                   "INSERT INTO test SET a=2,b='row2'")

    txid = _sql.ExecuteSQL(datadir, address, " DELETE  from   test where a=3")

    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")
    _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table")

    #cancel transaction. rollback should affect
    transactions.CancelTransaction(datadir, txid)

    # should be 0 unapproved transactions
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    # should be 3 rows again
    rows = _lib.DBGetRows(datadir, "SELECT * FROM test")
    _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table")

    startnode.StopNode(datadir)
    datadir = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 30
0
def test(testfilter):
    global datadir

    _lib.StartTestGroup("Init Blockchain on non empty DB")

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

    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.CopyTestConsensusConfig(datadir, "disabledcreate", address2)

    # add some data to the DB
    _lib.DBExecute(
        datadir,
        "create table test (a int unsigned auto_increment primary key, b varchar(10))"
    )
    _lib.DBExecute(datadir, "insert into test SET b='row1'")
    _lib.DBExecute(datadir, "insert into test SET b='row2'")
    _lib.DBExecute(
        datadir,
        "create table members (a int unsigned auto_increment primary key, b varchar(10))"
    )
    _lib.DBExecute(datadir, "insert into members SET b='row1'")
    _lib.DBExecute(datadir, "insert into members SET b='row2'")

    address = startnode.InitBockchain(datadir)
    _complex.AddProxyToConfig(datadir, "localhost:40041")
    _complex.AddInternalKeyToConfig(datadir, address3)  # init internal signing

    startnode.StartNode(datadir, address, '30000')

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blocks = _blocks.GetBlocks(datadir)

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

    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET b='row3'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET b='row4'")

    blocks = _blocks.WaitBlocks(datadir, 3)

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

    time.sleep(1)

    _sql.ExecuteSQLOnProxyFail(datadir, "INSERT INTO test SET b='row3'")

    _transfers.Send(datadir, address, address3, 1)

    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET b='row3'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO test SET b='row4'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET b='row5'")

    startnode.StopNode(datadir)
    datadir = ""

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()