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
Esempio n. 2
0
def keygen(args):
    print(f"Starting to generate keypairs for ZIL nodes")
    keys = []
    for i in range(args.nodes):
        key = ZilKey.generate_key_pair()
        keys.append(" ".join(key.keypair_str))

    with open(args.keys, "w") as f:
        f.write("\n".join(keys))

    print(f"{len(keys)} keypairs generated into > {args.keys}")
Esempio n. 3
0
    def test_pow_work(self):
        from zilpool.database.pow import PowWork

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

        drop_all()

        header = rand_hex_str(64, prefix="0x")
        # seed = rand_hex_str(64, prefix="0x")
        block_num = random.randint(0, 1_000_0000)
        boundary = rand_hex_str(64, prefix="0x")
        pub_key = ZilKey.generate_key_pair().keypair_str.public

        work = PowWork.new_work(header, block_num, boundary, pub_key=pub_key)
        work.pow_fee = 2
        work.save()
        check_doc_count(1)
        assert not work.finished

        work = PowWork.get_new_works(1, min_fee=2.01)
        assert not work

        work = PowWork.get_new_works(1, min_fee=2.0)
        assert work
        assert work.dispatched == 0

        work = work.increase_dispatched()
        assert work

        work = PowWork.find_work_by_header_boundary(header=header,
                                                    boundary=boundary)
        assert work
        assert work.dispatched == 1

        work2 = PowWork.get_new_works(1, min_fee=0)
        assert work2.header == work.header, work2.boundary == work.boundary

        drop_all()
    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()