Onionr/tests/default-plugin-tests/wot/test_process_announce_identity.py

52 lines
1.3 KiB
Python
Raw Normal View History

2022-09-17 05:02:49 +00:00
import os, uuid
from random import randint
from time import sleep
from enum import IntEnum, auto
from nacl.signing import SigningKey, VerifyKey
import nacl
import secrets
import onionrblocks
TEST_DIR = 'testdata/%s-%s' % (str(uuid.uuid4())[:6], os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
import unittest
import sys
sys.path.append(".")
2022-09-26 20:06:05 +00:00
sys.path.append('static-data/official-plugins/wot/')
2022-09-17 05:02:49 +00:00
sys.path.append("src/")
from wot.identityprocessing import process_identity_announce
from wot import identity
from wot.identity.identityset import identities
2022-09-17 05:02:49 +00:00
class WotCommand(IntEnum):
TRUST = 1
REVOKE_TRUST = auto()
ANNOUNCE = auto()
REVOKE = auto()
class TestAnnounceIdentityPayload(unittest.TestCase):
def test_announce_identity_payload(self):
# reset identity set
identities.clear()
signing_key = SigningKey.generate()
main_iden = identity.Identity(signing_key, "test")
2022-09-17 05:02:49 +00:00
wot_cmd = int(WotCommand.ANNOUNCE).to_bytes(1, 'big')
serialized_iden = wot_cmd + main_iden.serialize()
2022-09-17 05:02:49 +00:00
process_identity_announce(serialized_iden)
2022-09-17 05:02:49 +00:00
self.assertEqual(bytes(main_iden.key), bytes(list(identities)[0].key))
2022-09-17 05:02:49 +00:00
self.assertEqual(len(identities), 1)
self.assertEqual(len(main_iden.trusted), 0)
unittest.main()