Beispiel #1
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 #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):

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