def test_node_owner(self):
        import time
        from datetime import datetime
        from zilpool.database.zilnode import ZilNode, ZilNodeOwner

        drop_all()

        email = "*****@*****.**"
        owner = ZilNodeOwner.create(email)
        assert owner is not None
        assert owner.email_verified is False
        assert owner.pow_fee == 0.0
        assert owner.balance == 0.0
        assert owner.join_date <= datetime.utcnow()

        key = ZilKey.generate_key_pair()
        pub_key = key.keypair_str.public

        node = owner.register_node(pub_key)
        assert pub_key in owner.pending_nodes

        node = ZilNode.get_by_pub_key(pub_key=pub_key, authorized=False)
        assert node is not None
        assert node.authorized is False

        assert node.pow_fee == owner.pow_fee
예제 #2
0
 async def admin_list_nodes(request, visa: str, page=0, per_page=50):
     admin = get_admin_from_visa(request, visa)
     return [{
         "email": node.email,
         "authorized": node.authorized,
         "pow_fee": node.pow_fee,
         "pub_key": node.pub_key,
         "works": node.works_stats()
     } for node in ZilNode.paginate(page=page, per_page=per_page)]
예제 #3
0
    def test_paginate(self):
        from zilpool.database.miner import Miner
        from zilpool.database.zilnode import ZilNode

        config = get_database_debug_config()
        drop_all()
        init_db(config)

        for i in range(149):
            node = ZilNode(pub_key=f"pub_key_{i}",
                           pow_fee=i,
                           email=f"email_{i}")
            node.save()

        page = ZilNode.paginate(page=0, per_page=50)
        assert len(page) == 50
        assert page[0]["pub_key"] == ZilNode.get_one().pub_key
        page = ZilNode.paginate(page=2, per_page=50)
        assert len(page) == 49

        all_nodes = ZilNode.get_all()
        for i in range(49):
            node = page[i]
            assert node["pub_key"] == all_nodes[100 + i].pub_key

        for i in range(201):
            m = Miner(wallet_address=f"wallet_address_{i}")
            m.save()

        all_miners = Miner.get_all()
        total = len(all_miners)

        page = Miner.paginate(page=0, per_page=50)
        assert len(page) == 50
        assert page[0]["wallet_address"] == Miner.get_one().wallet_address
        page = Miner.paginate(page=4, per_page=50)
        assert len(page) == 1
        assert page[0]["wallet_address"] == all_miners[total -
                                                       1].wallet_address

        page = Miner.paginate(page=1, per_page=50)
        assert len(page) == 50
        for i in range(50):
            miner = page[i]
            assert miner["wallet_address"] == all_miners[50 + i].wallet_address
예제 #4
0
    async def admin_list_nodes(request, visa: str, page=0, per_page=50,
                               order_by=None, filters=None):
        admin = get_admin_from_visa(request, visa)
        if order_by is None:
            order_by = ["authorized", "email"]
        if filters is None:
            filters = {}

        return [
            {
                "email": node.email,
                "authorized": node.authorized,
                "pow_fee": node.pow_fee,
                "pub_key": node.pub_key,
                "works": node.works_stats()
            }
            for node in ZilNode.paginate(page=page, per_page=per_page,
                                         order_by=order_by, **filters)
        ]
예제 #5
0
def admin_auth_node(pub_key, approve):
    from zilpool.web import tools

    node = ZilNode.get_by_pub_key(pub_key, authorized=None)
    assert node, "Node not found"

    if approve != node.authorized:
        node = node.update(authorized=approve)
        assert node, "failed to update database"

        action = "Approved" if approve else "Revoked"
        messages = f"Node Register {action}: {node.pub_key}"

        logging.info(messages)

        if node.email:
            tools.send_auth_notification_email(node.email, messages=messages)

    return node
    def test_zil_nodes(self):
        from zilpool.database.zilnode import ZilNode

        drop_all()

        def check_doc_count(i):
            assert ZilNode._collection.count_documents({}) == i

        key = ZilKey.generate_key_pair()
        pub_key = key.keypair_str.public
        node = ZilNode(pub_key=pub_key, pow_fee=0, authorized=False)
        node.save()
        check_doc_count(1)
        node.update(set__pow_fee=1.2)
        check_doc_count(1)
        node2 = ZilNode.get_by_pub_key(pub_key, authorized=False)
        assert node2.pow_fee == node.pow_fee == 1.2

        node = ZilNode.get_by_pub_key("")
        assert node is None
        node = ZilNode(pub_key=pub_key)
        success = node.save()
        assert not success
        check_doc_count(1)

        fail_pub_key = rand_hex_str(9)
        node2 = ZilNode(pub_key=fail_pub_key, pow_fee=6, authorized=True)
        check_doc_count(1)
        success = node2.save()
        assert success is node2
        check_doc_count(2)
        success = node2.save()
        assert success is node2
        check_doc_count(2)

        drop_all()