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]
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()
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()
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()
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()
def test(testfilter): global datadir _lib.StartTestGroup("SQL Proxy basic") _lib.CleanTestFolders() datadir = _lib.CreateTestFolder() pub_key, pri_key = _lib.MakeWallet() startnode.StartNodeWithoutBlockchain(datadir) address = startnode.InitBockchain(datadir) _complex.AddProxyToConfig(datadir, "localhost:40041") startnode.StartNode(datadir, address, '30000') _lib.StartTestGroup("Do transactions") transactions.GetUnapprovedTransactionsEmpty(datadir) _sql.ExecuteSQLOnProxySign( datadir, "CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))", pub_key, pri_key) # 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) _sql.ExecuteSQLOnProxySign(datadir, "INSERT INTO test SET b='row1'", pub_key, pri_key) _sql.ExecuteSQLOnProxySign(datadir, "INSERT INTO test SET a=2,b='row2'", pub_key, pri_key) time.sleep(1) _sql.ExecuteSQLOnProxySign(datadir, "INSERT INTO test (b) VALUES ('row3')", pub_key, pri_key) 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") for row in rows: if row[0] == "1": _lib.FatalAssert(row[1] == "row1", "Wrong value for row1") if row[0] == "2": _lib.FatalAssert(row[1] == "row2", "Wrong value for row2") if row[0] == "3": _lib.FatalAssert(row[1] == "row3", "Wrong value for row3") # update data _sql.ExecuteSQLOnProxySign( datadir, " update test SET b=\"row3 updated\" where a=3", pub_key, pri_key) _sql.ExecuteSQLOnProxySign( datadir, " update test SET b=\"row2 updated\" where a = '2'", pub_key, pri_key) blocks = _blocks.WaitBlocks(datadir, 4) time.sleep(2) # 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.ExecuteSQLOnProxySignFail(datadir, "INSERT INTO test SET a=2,b='row2'", pub_key, pri_key) _sql.ExecuteSQLOnProxySign(datadir, " DELETE from test where a=3", pub_key, pri_key) rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True) _lib.FatalAssert(len(rows) == 2, "Must be 2 rows in a table") txlist = transactions.GetUnapprovedTransactions(datadir) #cancel transaction. rollback should affect transactions.CancelTransaction(datadir, txlist.keys()[0]) # should be 0 unapproved transactions transactions.GetUnapprovedTransactionsEmpty(datadir) # should be 3 rows again rows = _lib.DBGetRows(datadir, "SELECT * FROM test", True) _lib.FatalAssert(len(rows) == 3, "Must be 3 rows in a table") startnode.StopNode(datadir) datadir = "" #_lib.RemoveTestFolder(datadir) _lib.EndTestGroupSuccess()
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()
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()
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()
def test(testfilter): global datadir _lib.StartTestGroup("Init Blockchain on non empty DB. Add 4000 records") _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))" ) # add 2k records sys.stdout.write("\t\t") for x in range(600): _lib.DBExecute(datadir, "insert into test SET b='row" + str(x) + "'") if x % 20 == 0: sys.stdout.write('.') if x % 200 == 0 and x > 0: sys.stdout.write(str(x)) print("") sys.stdout.write("\t\t") _lib.DBExecute( datadir, "create table members (a int unsigned auto_increment primary key, b varchar(10))" ) for x in range(600): _lib.DBExecute(datadir, "insert into members SET b='row" + str(x) + "'") if x % 20 == 0: sys.stdout.write('.') if x % 200 == 0 and x > 0: sys.stdout.write(str(x)) print("") _lib.StartTestGroup("Data added. Init BC") 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) #print(blocks) #_lib.FatalAssert(len(blocks) == 4,"Should be 4 blocks in blockchain") _lib.FatalAssert(len(blocks) == 3, "Should be 3 blocks in blockchain") startnode.StopNode(datadir) datadir = "" #_lib.RemoveTestFolder(datadir) _lib.EndTestGroupSuccess()