Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
def test_list_voter_proposals(node, account, wif, subject):
    logger.info("Testing: list_voter_proposals")
    s = Clout(nodes=[node], no_broadcast=False, keys=[wif])
    voter_proposals = s.list_voter_proposals(account, "by_creator",
                                             "direction_ascending", 1000,
                                             "inactive")

    found = None
    for voter, proposals in voter_proposals.items():
        for proposal in proposals:
            if proposal["subject"] == subject:
                found = proposal

    assert found is not None
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)
 def __init__(self, node_url, proposals, private_key, delay):
     threading.Thread.__init__(self)
     self.node_url = node_url
     self.proposals = proposals
     self.private_key = private_key
     self.delay = delay
     self.log = logging.getLogger(MODULE_NAME + ".ProposalsCreatorThread." +
                                  self.node_url)
     self.node_client = Clout(nodes=[self.node_url],
                              keys=[self.private_key])
Exemplo n.º 6
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)
Exemplo n.º 7
0
def test_create_proposal(node, creator_account, receiver_account, wif,
                         subject):
    logger.info("Testing: create_proposal")
    s = Clout(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 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)

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

    ret = s.commit.create_proposal(creator["name"], receiver["name"],
                                   start_date, end_date, "16.000 TBD", subject,
                                   "cloutpy-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"] == "cloutpy-proposal-title"
Exemplo n.º 8
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)
Exemplo n.º 9
0
    if not accounts:
        logger.error(
            "Accounts array is empty, please add accounts in a form {\"name\" : name, \"private_key\" : private_key, \"public_key\" : public_key}"
        )
        sys.exit(1)

    keys = [wif]
    for account in accounts:
        keys.append(account["private_key"])

    if node is not None:
        node.run_clout_node(["--enable-stale-production"])
    try:
        if node is None or node.is_running():
            node_client = Clout(nodes=[node_url],
                                no_broadcast=False,
                                keys=keys)

            # create accounts
            test_utils.create_accounts(node_client, args.creator, accounts)
            # tranfer to vesting
            test_utils.transfer_to_vesting(node_client, args.creator, accounts,
                                           "300.000", "TESTS")
            # transfer assets to accounts
            test_utils.transfer_assets_to_accounts(node_client, args.creator,
                                                   accounts, "400.000",
                                                   "TESTS")

            test_utils.transfer_assets_to_accounts(node_client, args.creator,
                                                   accounts, "400.000", "TBD")
                        nargs="+",
                        help="Delays for each worker/node (default 0)")
    parser.add_argument("--proposal-count",
                        dest="proposal_count",
                        type=int,
                        default=1,
                        help="Number of proposals each worker will create.")

    args = parser.parse_args()

    logger.info("Performing ID collision test with nodes {}".format(
        args.nodes_url))

    import clout_utils.clout_tools

    node_client = Clout(nodes=args.nodes_url, keys=[args.wif])
    logger.info("New post ==> ({},{},{},{},{})".format(
        "Cloutpy proposal title [{}]".format(args.creator),
        "Cloutpy proposal body [{}]".format(args.creator), args.creator,
        get_permlink(args.creator), "proposals"))

    node_client.commit.post("Cloutpy proposal title [{}]".format(args.creator),
                            "Cloutpy proposal body [{}]".format(args.creator),
                            args.creator,
                            permlink=get_permlink(args.creator),
                            tags="proposals")

    clout_utils.clout_tools.wait_for_blocks_produced(5, args.nodes_url[0])

    workers = []
Exemplo n.º 11
0
    account = {"name": "tester001", "private_key": "", "public_key": ""}

    assert len(account["private_key"]) != 0, "Private key is empty"

    keys = [wif]
    keys.append(account["private_key"])

    logger.info(keys)

    if node is not None:
        node.run_clout_node(["--enable-stale-production"])
    try:
        if node is None or node.is_running():
            node_client = Clout(nodes=[node_url],
                                no_broadcast=False,
                                keys=keys)

            # create accounts
            create_accounts(node_client, args.creator, account)
            # tranfer to vesting
            transfer_to_vesting(node_client, args.creator, account, "300.000",
                                "TESTS")
            # transfer assets to accounts
            transfer_assets_to_accounts(node_client, args.creator, account,
                                        "400.000", "TESTS")

            transfer_assets_to_accounts(node_client, args.creator, account,
                                        "400.000", "TBD")

            # create post for valid permlinks
Exemplo n.º 12
0
            "private_key":
            "5JBuekd1sVXXK3wBu6nvPB1LWypZ83BYdu7tGcUNYVd42xQGGh1",
            "public_key":
            "TST5kSj1yTzBz3PDoJ5QUyVVagdgYfs8Y4vVsZG3dqKJU8hg7WmQN"
        })
        accounts[len(accounts) - 1]["name"] = "tester" + str(i)

    keys = [wif]
    #for account in accounts:
    keys.append(accounts[0]["private_key"])

    node.run_clout_node(["--enable-stale-production"])
    try:
        if node.is_running():
            node_client = Clout(nodes=[node_url],
                                no_broadcast=False,
                                keys=keys)

            create_accounts(node_client, args.creator, accounts)
            transfer_to_vesting(node_client, args.creator, accounts,
                                args.vests)
            transfer_assets_to_accounts(node_client, args.creator, accounts,
                                        args.clouts, args.cbds)
            create_posts(node_client, accounts)

            #total proposals: nr_proposals * accounts
            start_date, end_date, end_date_delay = generate_dates(node_client)
            create_proposals(node_client, accounts, start_date, end_date,
                             args.nr_proposals)

            total_proposals = args.nr_proposals * len(accounts)