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): _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()
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()
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]
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 Make5BlocksBC(): datadir = _lib.CreateTestFolder() _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") # 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' _lib.StartTestGroup("Send 1 transaction") # one TX in first block txid1 = _transfers.Send(datadir,address,address2,amount1) txlist = transactions.GetUnapprovedTransactions(datadir) _lib.FatalAssert(len(txlist) == 1,"Should be 1 unapproved transaction") blockchash = _blocks.MintBlock(datadir,address) blockshashes = _blocks.GetBlocks(datadir) _lib.FatalAssert(len(blockshashes) == 2,"Should be 2 blocks in blockchain") _lib.StartTestGroup("Send 2 transactions") # 2 TX in second block 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) txlist = transactions.GetUnapprovedTransactions(datadir) _lib.FatalAssert(len(txlist) == 2,"Should be 2 unapproved transaction") blockchash = _blocks.MintBlock(datadir,address) blockshashes = _blocks.GetBlocks(datadir) _lib.FatalAssert(len(blockshashes) == 3,"Should be 3 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") blockchash = _blocks.MintBlock(datadir,address) transactions.GetUnapprovedTransactionsEmpty(datadir) blockshashes = _blocks.GetBlocks(datadir) _lib.FatalAssert(len(blockshashes) == 4,"Should be 4 blocks in blockchain") _lib.StartTestGroup("Send 4 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) a4 = 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) txid3 = _transfers.Send(datadir,address3,address,a4) 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 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 = _blocks.MintBlock(datadir,address) transactions.GetUnapprovedTransactionsEmpty(datadir) blockshashes = _blocks.GetBlocks(datadir) _lib.FatalAssert(len(blockshashes) == 5,"Should be 5 blocks in blockchain") _lib.StartTestGroup("Send 5 transactions. Random value") txid1 = _transfers.Send(datadir,address,address2,a4) txid2 = _transfers.Send(datadir,address2,address3,a3) txid3 = _transfers.Send(datadir,address3,address,a2) txid3 = _transfers.Send(datadir,address3,address,a1) txid1 = _transfers.Send(datadir,address,address2,a1) blockchash = _blocks.MintBlock(datadir,address) transactions.GetUnapprovedTransactionsEmpty(datadir) blockshashes = _blocks.GetBlocks(datadir) _lib.FatalAssert(len(blockshashes) == 6,"Should be 6 blocks in blockchain") dstdir = _lib.getCurrentDir()+"/datafortests/bcwith4blocks/" copyfile(datadir+"/wallet.dat", dstdir+"wallet.t") DumpBCDB(datadir, dstdir+"db.sql") #copyfile(datadir+"/nodeslist.db", dstdir+"nodeslist.t") #copyfile(datadir+"/blockchain.db", dstdir+"blockchain.t") return [datadir, address, address2, address3]
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()