Exemplo n.º 1
0
    def test_register_validator_re_register(self):
        key = signed_object.generate_signing_key()
        validator_id = signed_object.generate_identifier(key)
        name = 'DasValidator'
        signup_info = \
            SignupInfo.create_signup_info(
                originator_public_key=pybitcointools.privtopub(key),
                validator_network_basename='Intel Validator Network',
                most_recent_wait_certificate_id='0' * 16)

        store = KeyValueStore()
        transaction = \
            ValidatorRegistryTransaction.register_validator(
                name,
                validator_id,
                signup_info)
        transaction.sign_object(key)
        try:
            transaction.check_valid(store)
            transaction.apply(store)
        except InvalidTransactionError as e:
            self.fail('Failed valid transaction: {}'.format(e))
        try:  # check if valid to register again
            transaction.check_valid(store)
        except InvalidTransactionError as e:
            self.fail('Failure: Double registered validator: {}'.format(e))
Exemplo n.º 2
0
    def test_web_api_store(self):
        # Test _handlestorerequest
        local_node = self._create_node(8800)
        gossip = Gossip(local_node)
        path = tempfile.mkdtemp()
        ledger = Journal(gossip, data_directory=path, genesis_ledger=True)
        validator = TestValidator(ledger)
        store_page = StorePage(validator)
        request = self._create_get_request("/store", {})
        try:
            # Test no GlobalStore
            ledger.GlobalStore = None
            store_page.do_get(request)
            self.fail("This should throw an error.")
        except:
            self.assertIsNotNone(ledger.GlobalStore)
        kv = KeyValueStore()
        ledger.GlobalStore.TransactionStores["/TestTransaction"] = kv
        ledger.GlobalStore.TransactionStores["/TestTransaction"].set("TestKey",
                                                                     0)
        # GET /store
        self.assertEquals(store_page.do_get(request), '["/TestTransaction"]')

        # GET /store/TestTransaction
        request = self._create_get_request("/store/TestTransaction", {})
        self.assertEquals(store_page.do_get(request), '["TestKey"]')
        # GET /store/TestTransaction/*
        request = self._create_get_request("/store/TestTransaction/*", {})
        self.assertEquals(store_page.do_get(request), '{"TestKey": 0}')
        # GET /store/TestTransaction/*?delta=1
        request = self._create_get_request("/store/TestTransaction/*",
                                           {"delta": ['1']})
        self.assertEquals(store_page.do_get(request),
                          '{"DeletedKeys": [], "Store": {"TestKey": 0}}')
        # GET /store/TestTransaction/TestKey
        request = self._create_get_request("/store/TestTransaction/TestKey",
                                           {})
        self.assertEquals(store_page.do_get(request), "0")

        try:
            blockstore = BlockStore()
            ledger.GlobalStoreMap.commit_block_store("123", blockstore)
            request = self._create_get_request("/store/TestTransaction/*",
                                               {"blockid": ["123"]})
            store_page.do_get(request)
            self.fail("This should throw an error")
        except:
            blockstore = BlockStore()
            blockstore.add_transaction_store("/TestTransaction", kv)
            ledger.GlobalStoreMap.commit_block_store("123", blockstore)

        # GET /store/TestTransaction/*?blockid=123
        request = self._create_get_request("/store/TestTransaction/*",
                                           {"blockid": ["123"]})
        self.assertEquals(store_page.do_get(request), '{"TestKey": 0}')
Exemplo n.º 3
0
    def test_web_api_store(self):
        # Test _handlestorerequest
        validator = self._create_validator()
        journal = validator.journal
        store_page = StorePage(validator)
        request = self._create_get_request("/store", {})
        try:
            # Test no GlobalStore
            journal.global_store = None
            store_page.do_get(request)
            self.fail("This should throw an error.")
        except:
            self.assertIsNotNone(journal.global_store)
        kv = KeyValueStore()
        journal.global_store.TransactionStores["/TestTransaction"] = kv
        journal.global_store.TransactionStores["/TestTransaction"].set(
            "TestKey", 0)
        # GET /store
        self.assertEquals(store_page.do_get(request), '["/TestTransaction"]')

        # GET /store/TestTransaction
        request = self._create_get_request("/store/TestTransaction", {})
        self.assertEquals(store_page.do_get(request), '["TestKey"]')
        # GET /store/TestTransaction/*
        request = self._create_get_request("/store/TestTransaction/*", {})
        self.assertEquals(store_page.do_get(request), '{"TestKey": 0}')
        # GET /store/TestTransaction/*?delta=1
        request = self._create_get_request("/store/TestTransaction/*",
                                           {"delta": ['1']})
        self.assertEquals(store_page.do_get(request),
                          '{"DeletedKeys": [], "Store": {"TestKey": 0}}')
        # GET /store/TestTransaction/TestKey
        request = self._create_get_request("/store/TestTransaction/TestKey",
                                           {})
        self.assertEquals(store_page.do_get(request), "0")

        try:
            blockstore = BlockStore()
            journal.global_store_map.commit_block_store("123", blockstore)
            request = self._create_get_request("/store/TestTransaction/*",
                                               {"blockid": ["123"]})
            store_page.do_get(request)
            self.fail("This should throw an error")
        except:
            blockstore = BlockStore()
            blockstore.add_transaction_store("/TestTransaction", kv)
            journal.global_store_map.commit_block_store("123", blockstore)

        # GET /store/TestTransaction/*?blockid=123
        request = self._create_get_request("/store/TestTransaction/*",
                                           {"blockid": ["123"]})
        self.assertEquals(store_page.do_get(request), '{"TestKey": 0}')
Exemplo n.º 4
0
 def test_register_validator_key_mismatch(self):
     key = signed_object.generate_signing_key()
     key2 = signed_object.generate_signing_key()
     validator_id = signed_object.generate_identifier(key)
     name = 'DasValidator'
     signup_info = dict2json({'poet_public_key': 'fake_key',
                              'anti_sybil_id': 'some_token',
                              'proof_data': 'proof'})
     store = KeyValueStore()
     transaction = ValidatorRegistryTransaction.register_validator(
         name, validator_id, signup_info)
     transaction.sign_object(key2)
     with self.assertRaises(InvalidTransactionError):
         transaction.check_valid(store)
         transaction.apply(store)
         self.fail("Failure: Verified an invalid transaction")
Exemplo n.º 5
0
 def test_register_validator_valid(self):
     key = signed_object.generate_signing_key()
     validator_id = signed_object.generate_identifier(key)
     name = 'DasValidator'
     signup_info = dict2json({'poet_public_key': 'fake_key',
                              'anti_sybil_id': 'some_token',
                              'proof_data': 'proof'})
     store = KeyValueStore()
     transaction = ValidatorRegistryTransaction.register_validator(
         name, validator_id, signup_info)
     transaction.sign_object(key)
     try:
         transaction.check_valid(store)
         transaction.apply(store)
     except InvalidTransactionError:
         self.fail("Bad: Failed valid transaction")
Exemplo n.º 6
0
    def test_register_validator_key_mismatch(self):
        key = signed_object.generate_signing_key()
        key2 = signed_object.generate_signing_key()
        validator_id = signed_object.generate_identifier(key)
        name = 'DasValidator'
        signup_info = \
            SignupInfo.create_signup_info(
                originator_public_key=pybitcointools.privtopub(key),
                validator_network_basename='Intel Validator Network',
                most_recent_wait_certificate_id='0' * 16)

        store = KeyValueStore()
        transaction = \
            ValidatorRegistryTransaction.register_validator(
                name,
                validator_id,
                signup_info)
        transaction.sign_object(key2)
        with self.assertRaises(InvalidTransactionError):
            transaction.check_valid(store)
            self.fail("Failure: Verified an invalid transaction")