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