コード例 #1
0
def test_list_proposals(node, account, wif, subject):
    logger.info("Testing: list_proposals")
    s = Clout(nodes=[node], no_broadcast=False, keys=[wif])
    # list inactive proposals, our proposal shoud be here
    proposals = s.list_proposals(account, "by_creator", "direction_ascending",
                                 1000, "inactive")
    found = None
    for proposal in proposals:
        if proposal["subject"] == subject:
            found = proposal

    assert found is not None

    # list active proposals, our proposal shouldnt be here
    proposals = s.list_proposals(account, "by_creator", "direction_ascending",
                                 1000, "active")
    found = None
    for proposal in proposals:
        if proposal["subject"] == subject:
            found = proposal

    assert found is None

    # list all proposals, our proposal should be here
    proposals = s.list_proposals(account, "by_creator", "direction_ascending",
                                 1000, "all")

    found = None
    for proposal in proposals:
        if proposal["subject"] == subject:
            found = proposal

    assert found is not None
コード例 #2
0
def test_remove_proposal(node, account, wif, subject):
    logger.info("Testing: remove_proposal")
    s = Clout(nodes=[node], no_broadcast=False, keys=[wif])
    # first we will find our special proposal and get its id
    proposals = s.list_proposals(account, "by_creator", "direction_ascending",
                                 1000, "inactive")

    found = None
    for proposal in proposals:
        if proposal["subject"] == subject:
            found = proposal

    assert found is not None
    proposal_id = int(found["id"])

    # remove proposal
    s.commit.remove_proposal(account, [proposal_id])

    # try to find our special proposal
    proposals = s.list_proposals(account, "by_creator", "direction_ascending",
                                 1000, "inactive")

    found = None
    for proposal in proposals:
        if proposal["subject"] == subject:
            found = proposal

    assert found is None
コード例 #3
0
def list_proposals_by_node(creator, private_key, nodes, subjects):
    for idx in range(0, len(nodes)):
        node = nodes[idx]
        logger.info("Listing proposals using node at {}".format(node))
        s = Clout(nodes=[node], keys=[private_key])
        proposals = s.list_proposals(creator, "by_creator",
                                     "direction_ascending", 1000, "all")
        for subject in subjects:
            msg = "Looking for id of proposal with subject {}".format(subject)
            for proposal in proposals:
                if proposal['subject'] == subject:
                    msg = msg + " - FOUND ID = {}".format(proposal['id'])
                    #assert proposal['id'] == results[subject], "ID do not match expected {} got {}".format(results[subject], proposal['id'])
                    break
            logger.info(msg)
コード例 #4
0
def test_vote_proposal(node, account, wif, subject):
    logger.info("Testing: vote_proposal")
    s = Clout(nodes=[node], no_broadcast=False, keys=[wif])
    # first we will find our special proposal and get its id
    proposals = s.list_proposals(account, "by_creator", "direction_ascending",
                                 1000, "inactive")

    found = None
    for proposal in proposals:
        if proposal["subject"] == subject:
            found = proposal

    assert found is not None
    proposal_id = int(found["id"])

    # now lets vote
    ret = s.commit.update_proposal_votes(account, [proposal_id], True)
    assert ret["operations"][0][1]["voter"] == account
    assert ret["operations"][0][1]["proposal_ids"][0] == proposal_id
    assert ret["operations"][0][1]["approve"] == True
    clout_utils.clout_tools.wait_for_blocks_produced(2, node)
コード例 #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 = 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)
コード例 #6
0
    logger.info("Starting workers...")
    for worker in workers:
        worker.start()

    logger.info("Waiting for workers to join...")
    for worker in workers:
        worker.join()

    logger.info("===== QUERY PROPOSALS =====")
    logger.info(
        "Gathering proposals ID from the nodes where we send the transactions")
    results = {}
    for idx in range(0, len(node_subjects)):
        node = args.nodes_url[idx]
        s = Clout(nodes=[node], keys=[args.wif])
        proposals = s.list_proposals(args.creator, "by_creator",
                                     "direction_ascending", 1000, "all")
        for subject in node_subjects[idx]:
            for proposal in proposals:
                msg = "Looking for id of proposal sent to {} with subject {}".format(
                    node, subject)
                if proposal['subject'] == subject:
                    msg = msg + " - FOUND ID = {}".format(proposal['id'])
                    results[subject] = proposal['id']
                    break
            logger.info(msg)

    logger.info(
        "Checking for all transaction IDs by querying all nodes, IDs should match those gathered from nodes where we send the transactions"
    )
    list_proposals_by_node(args.creator, args.wif, args.nodes_url,
                           only_subjects)