def test(testfilter): global datadir1 global datadir2 _lib.StartTestGroup("Run node with 30 blocks and test import from second node") _lib.CleanTestFolders() inf = blocksnodes.MakeBlockchainWithBlocks('30000') datadir = inf[0] address1 = inf[1] address1_2 = inf[2] address1_3 = inf[3] for x in range(5, 31): _lib.StartTestGroup("Create block #"+str(x)) for y in range(0, x-1): tx=_transfers.Send(datadir,address1,address1_2,0.001) txlist = transactions.GetUnapprovedTransactions(datadir) _lib.FatalAssert(len(txlist) == x-1,"Should be "+str(x-1)+" unapproved transaction") blockchash = _blocks.MintBlock(datadir,address1) blocks = _blocks.WaitBlocks(datadir, x) _lib.FatalAssert(len(blocks) == x,"Should be "+str(x)+" blocks on server 1") #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1") startnode.StartNode(datadir, address1,'30000', "Server 1") datadir1 = datadir managenodes.RemoveAllNodes(datadir1) d = pullsync.StartNodeAndImport('30001', '30000', "Server 2", 0, "_2_", "xxx.com" ) datadir2 = d[0] address2 = d[1] blocks = _blocks.GetBlocks(datadir2) # wait when all 30 bocks are on node 2 blocks = _blocks.WaitBlocks(datadir2, 30, 100)# 100 sec _lib.FatalAssert(len(blocks) == 30,"Should be 17 blocks on server 2") startnode.StopNode(datadir1,"Server 1") datadir1 = "" time.sleep(4)# allow to complete blocks adding startnode.StopNode(datadir2,"Server 2") datadir2 = "" #_lib.RemoveTestFolder(datadir) _lib.EndTestGroupSuccess()
def test(testfilter): global datadir1 global datadir2 global datadir3 _lib.StartTestGroup("Test data exahcnge with non-public address node") _lib.CleanTestFolders() inf = blocksnodes.MakeBlockchainWithBlocks('30000') datadir = inf[0] address1 = inf[1] address1_2 = inf[2] address1_3 = inf[3] #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1") startnode.StartNode(datadir, address1, '30000', "Server 1") datadir1 = datadir managenodes.RemoveAllNodes(datadir1) d = StartNodeAndImport('30001', '30000', "Server 2", 0, "_2_", "xxx.com") datadir2 = d[0] address2 = d[1] d = StartNodeAndImport('30002', '30000', "Server 3", 0, "_3_") datadir3 = d[0] address3 = d[1] time.sleep(2) 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") # make transaction on first node tx = _transfers.Send(datadir, address1, address2, 0.1) time.sleep(5) # this TX should appear on second node too txlist = transactions.GetUnapprovedTransactions(datadir2) _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction") tx = _transfers.Send(datadir2, address2, address1, 0.01) txlist = transactions.GetUnapprovedTransactions(datadir2) _lib.FatalAssert( len(txlist) == 2, "Should be 2 unapproved transactions on second node") time.sleep(1) txlist = transactions.GetUnapprovedTransactions(datadir) _lib.FatalAssert( len(txlist) == 2, "Should be 2 unapproved transactions on first node") # make block on a secod node tx = _transfers.Send(datadir2, address2, address1, 0.01) tx = _transfers.Send(datadir2, address2, address1, 0.01) blocks = _blocks.WaitBlocks(datadir2, 5) _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 2") time.sleep(1) blocks = _blocks.WaitBlocks(datadir1, 5) _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 1") blocks = _blocks.WaitBlocks(datadir3, 5) _lib.FatalAssert(len(blocks) == 5, "Should be 5 blocks on server 3") time.sleep(1) # create block on the first node and check it appears on first for x in range(5): tx = _transfers.Send(datadir, address1, address2, 0.1) blocks = _blocks.WaitBlocks(datadir1, 6) _lib.FatalAssert(len(blocks) == 6, "Should be 5 blocks on server 1") # extra transaction to pull tx = _transfers.Send(datadir, address1, address2, 0.1) time.sleep(7) # new block should be pulled blocks = _blocks.WaitBlocks(datadir2, 6) _lib.FatalAssert(len(blocks) == 6, "Should be 6 blocks on server 2") txlist = transactions.GetUnapprovedTransactions(datadir1) time.sleep(2) txlist = transactions.GetUnapprovedTransactions(datadir2) _lib.FatalAssert( len(txlist) == 1, "Should be 1 unapproved transactions on second node") 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 nodeport = '30000' _lib.StartTestGroup("Wallet Balance") _lib.CleanTestFolders() inf = blocksnodes.MakeBlockchainWithBlocks(nodeport) datadir_tmp = inf[0] address1 = inf[1] address1_2 = inf[2] address1_3 = inf[3] balances = _transfers.GetGroupBalance(datadir_tmp) #get balance when a node is not run bal1 = _transfers.GetBalance(datadir_tmp, address1) bal1_2 = _transfers.GetBalance(datadir_tmp, address1_2) bal1_3 = _transfers.GetBalance(datadir_tmp, address1_3) _lib.FatalAssert(bal1 == balances[address1], "Balance is different from group rec for 1") _lib.FatalAssert(bal1_2 == balances[address1_2], "Balance is different from group rec for 2") _lib.FatalAssert(bal1_3 == balances[address1_3], "Balance is different from group rec for 3") s1 = bal1 + bal1_2 + bal1_3 startnode.StartNode(datadir_tmp, address1, nodeport) datadir = datadir_tmp #get balaces on nodes wallets bal1 = _transfers.GetBalance(datadir, address1) bal1_2 = _transfers.GetBalance(datadir, address1_2) bal1_3 = _transfers.GetBalance(datadir, address1_3) s2 = bal1 + bal1_2 + bal1_3 _lib.FatalAssert(s1 == s2, "Balances shoul be equal when a node is On and Off") #get group balance on a node balances = _transfers.GetGroupBalance(datadir) _lib.FatalAssert(bal1 == balances[address1], "Balance is different from group rec for 1") _lib.FatalAssert(bal1_2 == balances[address1_2], "Balance is different from group rec for 2") _lib.FatalAssert(bal1_3 == balances[address1_3], "Balance is different from group rec for 3") #create 2 wallet locations and 2 wallets in each of them walletdatadir1 = _lib.CreateTestFolder("wallet") walletdatadir2 = _lib.CreateTestFolder("wallet") waddress1_1 = _wallet.CreateWallet(walletdatadir1) waddress1_2 = _wallet.CreateWallet(walletdatadir1) waddress1_3 = _wallet.CreateWallet(walletdatadir1) waddress2_1 = _wallet.CreateWallet(walletdatadir2) waddress2_2 = _wallet.CreateWallet(walletdatadir2) #send some funds to all that wallets amounttosend = "%.8f" % round(bal1[0] / 5, 8) amounttosend3 = "%.8f" % round(bal1_3[0] / 5, 8) _transfers.Send(datadir, address1, waddress1_1, amounttosend) _transfers.Send(datadir, address1, waddress1_2, amounttosend) _transfers.Send(datadir, address1, waddress2_1, amounttosend) _transfers.Send(datadir, address1_3, waddress1_3, amounttosend3) # we control how blocks are created. here we wait on a block started and then send another 3 TX # we will get 2 more blocks here time.sleep(1) _transfers.Send(datadir, address1, waddress2_2, amounttosend) amounttosend2 = "%.8f" % round(bal1_2[0] / 5, 8) _transfers.Send(datadir, address1_2, waddress1_1, amounttosend2) _transfers.Send(datadir, address1_2, waddress1_2, amounttosend2) _transfers.Send(datadir, address1_3, waddress1_3, amounttosend3) _transfers.Send(datadir, address1_3, waddress1_3, amounttosend3) # wait to complete blocks blocks = _blocks.WaitBlocks(datadir, 6) time.sleep(2) _lib.FatalAssert(len(blocks) == 6, "Expected 6 blocks") #get balances on wallets am1 = _wallet.GetBalanceWallet(walletdatadir1, waddress1_1, "localhost", nodeport) am2 = _wallet.GetBalanceWallet(walletdatadir1, waddress1_2, "localhost", nodeport) am3 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_1, "localhost", nodeport) am4 = _wallet.GetBalanceWallet(walletdatadir2, waddress2_2, "localhost", nodeport) _lib.FatalAssert( am1[1] == round(float(amounttosend) + float(amounttosend2), 8), "Expected balance is different for wallet 1_1") _lib.FatalAssert( am2[1] == round(float(amounttosend) + float(amounttosend2), 8), "Expected balance is different for wallet 1_2") _lib.FatalAssert(am3[1] == float(amounttosend), "Expected balance is different for wallet 2_1") _lib.FatalAssert(am4[1] == float(amounttosend), "Expected balance is different for wallet 2_2") #get group blances on a wallet loc balances = _transfers.GetGroupBalance(datadir) #get balances on node wallets balances1 = _wallet.GetGroupBalanceWallet(walletdatadir1, "localhost", nodeport) balances2 = _wallet.GetGroupBalanceWallet(walletdatadir2, "localhost", nodeport) _lib.FatalAssert( am1[1] == balances1[waddress1_1][1], "Expected balance is different from group listing for 1_1") _lib.FatalAssert( am2[1] == balances1[waddress1_2][1], "Expected balance is different from group listing for 1_2") _lib.FatalAssert( am3[1] == balances2[waddress2_1][1], "Expected balance is different from group listing for 2_1") _lib.FatalAssert( am4[1] == balances2[waddress2_2][1], "Expected balance is different from group listing for 2_2") startnode.StopNode(datadir) datadir = "" #_lib.RemoveTestFolder(datadir) _lib.EndTestGroupSuccess()