Beispiel #1
0
def test(testfilter):
    _lib.StartTestGroup("Start/Stop node")

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

    startnode.StartNodeWithoutBlockchain(datadir1)
    address = startnode.InitBockchain(datadir1)
    #this starts on a port 30000
    startnode.StartNode(datadir1, address, '30000', "Server 1")

    #start second node. should fail
    startnode.StartNodeWithoutBlockchain(datadir2)

    address = ImportBockchain(datadir2, "localhost", '30000')
    startnode.StartNode(datadir2, address, '30001', "Server 2")

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

    _lib.RemoveTestFolder(datadir1)
    _lib.RemoveTestFolder(datadir2)
    _lib.EndTestGroupSuccess()
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
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()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
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()
Beispiel #8
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()
    

    
Beispiel #9
0
def test(testfilter):
    global datadir
    
    _lib.StartTestGroup("SQL Consensus rules postponed")

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

    startnode.StartNodeWithoutBlockchain(datadir)
    
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)
    
    _lib.CopyTestConsensusConfig(datadir,"postponedlimits", 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)
    
    _sql.ExecuteSQLOnProxy(datadir, "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    
    blocks = _blocks.WaitBlocks(datadir, 2)
    time.sleep(1)
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row1'")
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row2'")
    
    blocks = _blocks.WaitBlocks(datadir, 3)
    time.sleep(1)
    
    _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.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user1'")
    
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='use2'")
    
    #_sql.ExecuteSQLOnProxy(datadir, "DROP TABLE members")
    
    blocks = _blocks.WaitBlocks(datadir, 4)
    time.sleep(1)
    
    _sql.ExecuteSQLOnProxyFail(datadir, "CREATE TABLE test2 (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    
    _sql.ExecuteSQLOnProxy(datadir, "DROP TABLE members")
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row3'")
    _sql.ExecuteSQLOnProxy(datadir,"UPDATE test SET b='row3+upd1' WHERE a=3")
    _sql.ExecuteSQLOnProxy(datadir,"UPDATE test SET b='row3+upd2' WHERE a=3")
    
    blocks = _blocks.WaitBlocks(datadir, 5)
    time.sleep(1)
    # now this must be paid
    _sql.ExecuteSQLOnProxyFail(datadir,"UPDATE test SET b='row3+upd2' WHERE a=3")
    
    _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
        
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user1'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user2'")
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user3'")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row4'")
    
    blocks = _blocks.WaitBlocks(datadir, 6)
    time.sleep(1)
    
    _sql.ExecuteSQLOnProxyFail(datadir, "INSERT INTO members SET name='user4'")
    _sql.ExecuteSQLOnProxyFail(datadir,"INSERT INTO test SET b='row5'")
    
    # send money to be able to execute this
    _transfers.Send(datadir,address, address3 ,10) # needs this to create table
    _sql.ExecuteSQLOnProxy(datadir, "INSERT INTO members SET name='user4'")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test SET b='row5'")
    _sql.ExecuteSQLOnProxy(datadir, "CREATE TABLE test2 (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test2 SET b='row1'")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test2 SET b='row2'")
    _sql.ExecuteSQLOnProxy(datadir,"INSERT INTO test2 SET b='row3'")
    
    blocks = _blocks.WaitBlocks(datadir, 7)
    time.sleep(1)
    
    startnode.StopNode(datadir)
    datadir = ""
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()