def test_update_proposal(node, creator, wif): from beembase.operations import Update_proposal from datetime import timedelta import dateutil.parser s = Hive(node=[node], no_broadcast=False, keys=[wif]) logger.info("Testing: update_proposal without updating the end date") proposals = s.rpc.list_proposals([creator], 1000, "by_creator", "ascending", "all") print(proposals[0]) new_subject = "Some new proposal subject" new_daily_pay = "15.000 TBD" op = Update_proposal( **{ 'proposal_id': proposals[0]["proposal_id"], 'creator': proposals[0]["creator"], 'daily_pay': new_daily_pay, 'subject': new_subject, 'permlink': proposals[0]["permlink"] }) try: s.finalizeOp(op, creator, "active") except Exception as ex: logger.exception("Exception: {}".format(ex)) raise ex hive_utils.common.wait_n_blocks(node, 3) proposals = s.rpc.list_proposals([creator], 1000, "by_creator", "ascending", "all") print(proposals[0]) assert proposals[0]["subject"] == new_subject, "Subjects dont match" assert proposals[0]["daily_pay"] == new_daily_pay, "daily pay dont match" logger.info("Testing: update_proposal and updating the end date") end_date = test_utils.date_to_iso( dateutil.parser.parse(proposals[0]['end_date']) - timedelta(days=1)) op = Update_proposal( **{ 'proposal_id': proposals[0]["proposal_id"], 'creator': proposals[0]["creator"], 'daily_pay': "15.000 TBD", 'subject': new_subject, 'prefix': "TST", 'permlink': proposals[0]["permlink"], 'end_date': end_date }) try: s.finalizeOp(op, creator, "active") except Exception as ex: logger.exception("Exception: {}".format(ex)) raise ex hive_utils.common.wait_n_blocks(node, 3) proposals = s.rpc.list_proposals([creator], 1000, "by_creator", "ascending", "all") print(proposals[0]) assert proposals[0]["end_date"] == end_date, "End date doesn't match"
def test_iterate_results_test(node, creator_account, receiver_account, wif, subject, remove): logger.info("Testing: test_iterate_results_test") # test for iterate prosals # 1 we will create n proposals of which k proposal will have the same value in one of the fields # 2 then we will list proposals starting from kth proposal with limit set to m < k # 3 we list proposals again with the same conditiona as in 2, we should get the same set of results # in real life scenatio pagination scheme with limit set to value lower than "k" will be showing # the same results and will hang # 4 then we will use newly introduced last_id field, we should see diferent set of proposals s = Clout(nodes=[node], no_broadcast=False, keys=[wif]) from clout.account import Account try: creator = Account(creator_account) except Exception as ex: logger.error("Account: {} not found. {}".format(creator_account, ex)) sys.exit(1) try: receiver = Account(receiver_account) except Exception as ex: logger.error("Account: {} not found. {}".format(receiver_account, ex)) sys.exit(1) import datetime now = datetime.datetime.now() # 1 we will create n proposals of which k proposal will have the same value in one of the fields # here we have 5 proposals with the same start date start_end_pairs = [[1, 1], [2, 2], [4, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [6, 9]] for start_end_pair in start_end_pairs: start_date, end_date = test_utils.get_start_and_end_date( now, start_end_pair[0], start_end_pair[1]) s.commit.create_proposal(creator["name"], receiver["name"], start_date, end_date, "16.000 TBD", subject, "cloutpy-proposal-title") clout_utils.clout_tools.wait_for_blocks_produced(5, node) start_date = test_utils.date_to_iso(now + datetime.timedelta(days=5)) # 2 then we will list proposals starting from kth proposal with limit set to m < k proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 3, "all") assert len(proposals) == 3, "Expected {} elements got {}".format( 3, len(proposals)) ids = [] for proposal in proposals: assert proposal[ "start_date"] == start_date, "Expected start_date do not match {} != {}".format( start_date, proposals[-1]["start_date"]) ids.append(proposal["id"]) assert len(ids) == 3, "Expected {} elements got {}".format(3, len(ids)) # 3 we list proposals again with the same conditiona as in 2, we should get the same set of results proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 3, "all") assert len(proposals) == 3, "Expected {} elements got {}".format( 3, len(proposals)) oids = [] for proposal in proposals: assert proposal[ "start_date"] == start_date, "Expected start_date do not match {} != {}".format( start_date, proposals[-1]["start_date"]) oids.append(proposal["id"]) assert len(oids) == 3, "Expected {} elements got {}".format(3, len(oids)) # the same set of results check for id in ids: assert id in oids, "Id not found in expected results array {}".format( id) # 4 then we will use newly introduced last_id field, we should see diferent set of proposals proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 3, "all", oids[-1]) start_date, end_date = test_utils.get_start_and_end_date(now, 5, 4) assert proposals[-1][ "start_date"] == start_date, "Expected start_date do not match {} != {}".format( start_date, proposals[-1]["start_date"]) assert proposals[-1][ "end_date"] == end_date, "Expected end_date do not match {} != {}".format( end_date, proposals[-1]["end_date"]) # remove all created proposals if remove: start_date = test_utils.date_to_iso(now + datetime.timedelta(days=6)) for a in range(0, 2): proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 5, "all") ids = [] for proposal in proposals: ids.append(int(proposal['id'])) s.commit.remove_proposal(creator["name"], ids) clout_utils.clout_tools.wait_for_blocks_produced(3, node)
for pd in proposal_data: start_date, end_date = test_utils.get_start_and_end_date( now, pd[1], pd[2]) proposal = { 'creator': pd[0], 'receiver': pd[0], 'start_date': start_date, 'end_date': end_date, 'daily_pay': pd[3] } proposals.append(proposal) import datetime test_start_date = now + datetime.timedelta(days=1) test_start_date_iso = test_utils.date_to_iso(test_start_date) test_end_date = test_start_date + datetime.timedelta(days=4, hours=1) test_end_date_iso = test_utils.date_to_iso(test_end_date) test_utils.create_proposals(node_client, proposals) # list proposals with inactive status, it shoud be list of pairs id:total_votes test_utils.list_proposals(node_client, test_start_date_iso, "inactive") # each account is voting on proposal test_utils.vote_proposals(node_client, accounts) # list proposals with inactive status, it shoud be list of pairs id:total_votes
def test_iterate_results_test(node, creator_account, receiver_account, wif, subject, remove): logger.info("Testing: test_iterate_results_test") # test for iterate prosals # 1 we will create n proposals of which k proposal will have the same value in one of the fields # 2 then we will list proposals starting from kth proposal with limit set to m < k # 3 we list proposals again with the same conditiona as in 2, we should get the same set of results # in real life scenatio pagination scheme with limit set to value lower than "k" will be showing # the same results and will hang # 4 then we will use newly introduced last_id field, we should see diferent set of proposals s = Steem(nodes = [node], no_broadcast = False, keys = [wif]) from steem.account import Account try: creator = Account(creator_account) except Exception as ex: logger.error("Account: {} not found. {}".format(creator_account, ex)) sys.exit(1) try: receiver = Account(receiver_account) except Exception as ex: logger.error("Account: {} not found. {}".format(receiver_account, ex)) sys.exit(1) import datetime now = datetime.datetime.now() # 1 we will create n proposals of which k proposal will have the same value in one of the fields # here we have 5 proposals with the same start date start_end_pairs = [ [1,1], [2,2], [4,3], [5,4], [5,5], [5,6], [5,7], [5,8], [6,9] ] for start_end_pair in start_end_pairs: start_date, end_date = test_utils.get_start_and_end_date(now, start_end_pair[0], start_end_pair[1]) s.commit.create_proposal( creator["name"], receiver["name"], start_date, end_date, "16.000 TBD", subject, "steempy-proposal-title" ) steem_utils.steem_tools.wait_for_blocks_produced(5, node) start_date = test_utils.date_to_iso(now + datetime.timedelta(days = 5)) # 2 then we will list proposals starting from kth proposal with limit set to m < k proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 3, "all") assert len(proposals) == 3, "Expected {} elements got {}".format(3, len(proposals)) ids = [] for proposal in proposals: assert proposal["start_date"] == start_date, "Expected start_date do not match {} != {}".format(start_date, proposals[-1]["start_date"]) ids.append(proposal["id"]) assert len(ids) == 3, "Expected {} elements got {}".format(3, len(ids)) # 3 we list proposals again with the same conditiona as in 2, we should get the same set of results proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 3, "all") assert len(proposals) == 3, "Expected {} elements got {}".format(3, len(proposals)) oids = [] for proposal in proposals: assert proposal["start_date"] == start_date, "Expected start_date do not match {} != {}".format(start_date, proposals[-1]["start_date"]) oids.append(proposal["id"]) assert len(oids) == 3, "Expected {} elements got {}".format(3, len(oids)) # the same set of results check for id in ids: assert id in oids, "Id not found in expected results array {}".format(id) # 4 then we will use newly introduced last_id field, we should see diferent set of proposals proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 3, "all", oids[-1]) start_date, end_date = test_utils.get_start_and_end_date(now, 5, 4) assert proposals[-1]["start_date"] == start_date, "Expected start_date do not match {} != {}".format(start_date, proposals[-1]["start_date"]) assert proposals[-1]["end_date"] == end_date, "Expected end_date do not match {} != {}".format(end_date, proposals[-1]["end_date"]) # remove all created proposals if remove: start_date = test_utils.date_to_iso(now + datetime.timedelta(days = 6)) for a in range(0, 2): proposals = s.list_proposals(start_date, "by_start_date", "direction_descending", 5, "all") ids = [] for proposal in proposals: ids.append(int(proposal['id'])) s.commit.remove_proposal(creator["name"], ids) steem_utils.steem_tools.wait_for_blocks_produced(3, node)
def test_iterate_results_test(node, creator_account, receiver_account, wif, subject, remove): logger.info("Testing: test_iterate_results_test") # test for iterate prosals # 1 we will create n proposals of which k proposal will have the same value in one of the fields # 2 then we will list proposals starting from kth proposal with limit set to m < k # 3 we list proposals again with the same conditiona as in 2, we should get the same set of results # in real life scenatio pagination scheme with limit set to value lower than "k" will be showing # the same results and will hang # 4 then we will use newly introduced last_id field, we should see diferent set of proposals s = Hive(node=[node], no_broadcast=False, keys=[wif]) from beem.account import Account try: creator = Account(creator_account, hive_instance=s) except Exception as ex: logger.error("Account: {} not found. {}".format(creator_account, ex)) raise ex try: receiver = Account(receiver_account, hive_instance=s) except Exception as ex: logger.error("Account: {} not found. {}".format(receiver_account, ex)) raise ex import datetime now = datetime.datetime.now() # 1 we will create n proposals of which k proposal will have the same value in one of the fields # here we have 5 proposals with the same start date start_end_pairs = [[1, 1], [2, 2], [4, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [6, 9]] from beembase.operations import Create_proposal for start_end_pair in start_end_pairs: start_date, end_date = test_utils.get_start_and_end_date( now, start_end_pair[0], start_end_pair[1]) op = Create_proposal( **{ 'creator': creator["name"], 'receiver': receiver["name"], 'start_date': start_date, 'end_date': end_date, 'daily_pay': "16.000 TBD", 'subject': subject, 'permlink': "hivepy-proposal-title" }) try: s.finalizeOp(op, creator["name"], "active") except Exception as ex: logger.exception("Exception: {}".format(ex)) raise ex hive_utils.common.wait_n_blocks(node, 5) start_date = test_utils.date_to_iso(now + datetime.timedelta(days=5)) # 2 then we will list proposals starting from kth proposal with limit set to m < k proposals = s.rpc.list_proposals([start_date], 3, "by_start_date", "descending", "all") assert len(proposals) == 3, "Expected {} elements got {}".format( 3, len(proposals)) ids = [] for proposal in proposals: assert proposal[ "start_date"] == start_date, "Expected start_date do not match {} != {}".format( start_date, proposals[-1]["start_date"]) ids.append(proposal["proposal_id"]) assert len(ids) == 3, "Expected {} elements got {}".format(3, len(ids)) # 3 we list proposals again with the same conditiona as in 2, we should get the same set of results proposals = s.rpc.list_proposals([start_date], 3, "by_start_date", "descending", "all") assert len(proposals) == 3, "Expected {} elements got {}".format( 3, len(proposals)) oids = [] for proposal in proposals: assert proposal[ "start_date"] == start_date, "Expected start_date do not match {} != {}".format( start_date, proposals[-1]["start_date"]) oids.append(proposal["proposal_id"]) assert len(oids) == 3, "Expected {} elements got {}".format(3, len(oids)) # the same set of results check for id in ids: assert id in oids, "Id not found in expected results array {}".format( id) # 4 then we will use newly introduced last_id field, we should see diferent set of proposals proposals = s.rpc.list_proposals([start_date], 3, "by_start_date", "descending", "all", oids[-1]) start_date, end_date = test_utils.get_start_and_end_date(now, 5, 4) assert proposals[-1][ "start_date"] == start_date, "Expected start_date do not match {} != {}".format( start_date, proposals[-1]["start_date"]) assert proposals[-1][ "end_date"] == end_date, "Expected end_date do not match {} != {}".format( end_date, proposals[-1]["end_date"]) # remove all created proposals from beembase.operations import Remove_proposal if not remove: start_date = test_utils.date_to_iso(now + datetime.timedelta(days=6)) for _ in range(0, 2): proposals = s.list_proposals([start_date], 5, "by_start_date", "descending", "all") ids = [] for proposal in proposals: ids.append(int(proposal['proposal_id'])) op = Remove_proposal(**{ "voter": creator["name"], "proposal_ids": ids }) try: s.finalizeOp(op, creator["name"], "active") except Exception as ex: logger.exception("Exception: {}".format(ex)) raise ex hive_utils.common.wait_n_blocks(node, 3)
['tester004', 1 + 4, 1, '24.000 TBD'] # starts four days from now and lasts one day ] proposals = [ # pace proposals here in the format: {'creator' : creator, 'receiver' : receiver, 'start_date' : start-date, 'end_date' : end_date} ] for pd in proposal_data: start_date, end_date = test_utils.get_start_and_end_date(now, pd[1], pd[2]) proposal = {'creator' : pd[0], 'receiver' : pd[0], 'start_date' : start_date, 'end_date' : end_date, 'daily_pay' : pd[3]} proposals.append(proposal) import datetime test_start_date = now + datetime.timedelta(days = 1) test_start_date_iso = test_utils.date_to_iso(test_start_date) test_end_date = test_start_date + datetime.timedelta(days = 6, hours = 1) test_end_date_iso = test_utils.date_to_iso(test_end_date) test_utils.create_proposals(node_client, proposals) # list proposals with inactive status, it shoud be list of pairs id:total_votes test_utils.list_proposals(node_client, test_start_date_iso, "inactive") # each account is voting on proposal test_utils.vote_proposals(node_client, accounts) # list proposals with inactive status, it shoud be list of pairs id:total_votes votes = test_utils.list_proposals(node_client, test_start_date_iso, "inactive") for vote in votes: