def create_proposals(node, proposals, wif=None): logger.info("Creating proposals...") from beembase.operations import Create_proposal for proposal in proposals: logger.info("New proposal ==> ({},{},{},{},{},{},{})".format( proposal['creator'], proposal['receiver'], proposal['start_date'], proposal['end_date'], proposal['daily_pay'], "Proposal from account {}".format(proposal['creator']), get_permlink(proposal['creator']) )) op = Create_proposal( **{ 'creator' : proposal['creator'], 'receiver' : proposal['receiver'], 'start_date' : proposal['start_date'], 'end_date' : proposal['end_date'], 'daily_pay' : proposal['daily_pay'], 'subject' : "Proposal from account {}".format(proposal['creator']), 'permlink' : get_permlink(proposal['creator']) } ) node.finalizeOp(op, proposal['creator'], "active") if wif is not None: hive_utils.debug_generate_blocks(node.rpc.url, wif, 5) else: hive_utils.common.wait_n_blocks(node.rpc.url, 5)
def create_proposals(node, account, start_date, end_date, proposal_count): logger.info("Creating proposals...") from beembase.operations import Create_proposal from test_utils import get_permlink for idx in range(0, proposal_count): logger.info("New proposal ==> ({},{},{},{},{},{},{})".format( account['name'], account['name'], start_date, end_date, "24.000 TBD", "Proposal from account {} {}/{}".format(account['name'], idx, proposal_count), get_permlink(account['name']))) op = Create_proposal( **{ 'creator': account['name'], 'receiver': account['name'], 'start_date': start_date, 'end_date': end_date, 'daily_pay': "24.000 TBD", 'subject': "Proposal from account {}".format(account['name']), 'permlink': get_permlink(account['name']) }) try: node.finalizeOp(op, account['name'], "active") except Exception as ex: logger.error("Exception: {}".format(ex)) raise ex hive_utils.common.wait_n_blocks(node.rpc.url, 1) hive_utils.common.wait_n_blocks(node.rpc.url, 5)
def create_proposals(node, accounts, start_date, end_date, wif=None): logger.info("Creating proposals...") from beembase.operations import Create_proposal for acnt in accounts: logger.info("New proposal ==> ({},{},{},{},{},{},{})".format( acnt['name'], acnt['name'], start_date, end_date, "24.000 TBD", "Proposal from account {}".format(acnt['name']), test_utils.get_permlink(acnt['name']) )) op = Create_proposal( **{ 'creator' : acnt['name'], 'receiver' : acnt['name'], 'start_date' : start_date, 'end_date' : end_date, 'daily_pay' : "24.000 TBD", 'subject' : "Proposal from account {}".format(acnt['name']), 'permlink' : test_utils.get_permlink(acnt['name']) } ) node.finalizeOp(op, acnt['name'], "active") if wif is not None: hive_utils.debug_generate_blocks(node.rpc.url, wif, 5) else: hive_utils.common.wait_n_blocks(node.rpc.url, 5)
def test_create_proposal(node, creator_account, receiver_account, wif, subject): logger.info("Testing: create_proposal") s = Hive(node=[node], no_broadcast=False, keys=[wif]) import datetime now = datetime.datetime.now() start_date, end_date = test_utils.get_start_and_end_date(now, 10, 2) 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 ret = s.post("Hivepy proposal title", "Hivepy proposal body", creator["name"], permlink="hivepy-proposal-title", tags="proposals") from beembase.operations import Create_proposal 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" }) ret = None try: ret = s.finalizeOp(op, creator["name"], "active") except Exception as ex: logger.exception("Exception: {}".format(ex)) raise ex assert ret["operations"][0][1]["creator"] == creator["name"] assert ret["operations"][0][1]["receiver"] == receiver["name"] assert ret["operations"][0][1]["start_date"] == start_date assert ret["operations"][0][1]["end_date"] == end_date assert ret["operations"][0][1]["daily_pay"] == "16.000 TBD" assert ret["operations"][0][1]["subject"] == subject assert ret["operations"][0][1]["permlink"] == "hivepy-proposal-title"
def create_proposals(node_client, creator_account, receiver_account): import datetime now = datetime.datetime.now() start_date, end_date = hive_utils.common.get_isostr_start_end_date( now, 10, 2) from beem.account import Account try: creator = Account(creator_account, hive_instance=node_client) except Exception as ex: logger.error("Account: {} not found. {}".format(creator_account, ex)) raise ex try: receiver = Account(receiver_account, hive_instance=node_client) except Exception as ex: logger.error("Account: {} not found. {}".format(receiver_account, ex)) raise ex logger.info("Creating initial post...") node_client.post("Hivepy proposal title", "Hivepy proposal body", creator["name"], permlink="hivepy-proposal-title", tags="proposals") logger.info("Creating proposals...") from beembase.operations import Create_proposal for start_end_subject in START_END_SUBJECTS: start_date, end_date = hive_utils.common.get_isostr_start_end_date( now, start_end_subject[0], start_end_subject[1]) op = Create_proposal( **{ 'creator': creator["name"], 'receiver': receiver["name"], 'start_date': start_date, 'end_date': end_date, 'daily_pay': "16.000 TBD", 'subject': start_end_subject[2], 'permlink': "hivepy-proposal-title" }) try: node_client.finalizeOp(op, creator["name"], "active") except Exception as ex: logger.exception("Exception: {}".format(ex)) raise ex hive_utils.common.wait_n_blocks(node_client.rpc.url, 1) hive_utils.common.wait_n_blocks(node_client.rpc.url, 2)
def run(self): self.log.info("Sending proposals to node at: {} with delay {}".format( self.node_url, self.delay)) sleep(self.delay) from beembase.operations import Create_proposal for proposal in self.proposals: self.log.info("New proposal ==> ({},{},{},{},{},{},{})".format( proposal['creator'], proposal['receiver'], proposal['start_date'], proposal['end_date'], proposal['daily_pay'], proposal['subject'], proposal['permlink'])) op = Create_proposal( **{ 'creator': proposal['creator'], 'receiver': proposal['receiver'], 'start_date': proposal['start_date'], 'end_date': proposal['end_date'], 'daily_pay': proposal['daily_pay'], 'subject': proposal['subject'], 'permlink': proposal['permlink'] }) self.node_client.finalizeOp(op, proposal['creator'], "active")
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)