Пример #1
0
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"
Пример #2
0
def test_create_proposal(node, creator_account, receiver_account, wif, subject):
    logger.info("Testing: create_proposal")
    s = Steem(nodes = [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 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)

    ret = s.commit.post("Steempy proposal title", "Steempy proposal body", creator["name"], permlink = "steempy-proposal-title", tags = "proposals")

    ret = s.commit.create_proposal(
      creator["name"], 
      receiver["name"], 
      start_date, 
      end_date,
      "16.000 TBD",
      subject,
      "steempy-proposal-title"
    )

    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"] == "steempy-proposal-title"
Пример #3
0
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)
Пример #4
0
                ['tester001', 1 + 0, 3,
                 '240000.000 TBD'],  # starts 1 day from now and lasts 3 days
                ['tester002', 1 + 0, 3,
                 '24.000 TBD'],  # starts 1 day from now and lasts 3 days
                ['tester003', 1 + 0, 3,
                 '24.000 TBD'],  # starts 1 days from now and lasts 3 day
                ['tester004', 1 + 0, 3,
                 '24.000 TBD']  # starts 1 days from now and lasts 3 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=4,
                                                                 hours=1)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
            now = test_utils.date_from_iso(now)

            proposal_data = [
                ['tester001', 1 + 0, 5, '24.000 TBD'], # starts one day from now and lasts five days
                ['tester002', 1 + 0, 2, '24.000 TBD'], # starts one day from now and lasts two days
                ['tester003', 1 + 2, 1, '24.000 TBD'], # starts three days from now and lasts one day
                ['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")