def test_get_validators(self): """Given a state view with multiple validators, and the 'validator_map' entry, verify that get_validators returns the list of just ValidatorInfo instances. """ state_view = MockStateView({ to_address('validator_map'): b'this should be ignored', to_address('my_id'): ValidatorInfo(name='my_validator', id='my_id', signup_info=SignUpInfo(poet_public_key='my_pubkey', proof_data='beleive me', anti_sybil_id='no sybil'), transaction_id="signature").SerializeToString(), to_address('another_id'): ValidatorInfo(name='your_validator', id='another_id', signup_info=SignUpInfo(poet_public_key='your_pubkey', proof_data='you betcha', anti_sybil_id='poor sybil'), transaction_id="signature").SerializeToString() }) validator_registry_view = ValidatorRegistryView(state_view) infos = validator_registry_view.get_validators() self.assertEqual(2, len(infos)) self.assertEqual('my_validator', infos['my_id'].name) self.assertEqual('your_validator', infos['another_id'].name)
def test_get_validator_info(self): """Given a state view that contains a state entry for a given validator info, verify that the validator registry returns a ValidatorInfo when get_validator_info is called with the validator's id.""" state_view = MockStateView({ to_address('my_id'): ValidatorInfo(registered='sure', name='my_validator', id='my_id', signup_info=SignUpInfo(poet_public_key='my_pubkey', proof_data='beleive me', anti_sybil_id='no sybil'), block_num=123).SerializeToString() }) validator_registry_view = ValidatorRegistryView(state_view) info = validator_registry_view.get_validator_info('my_id') self.assertEqual('my_id', info.id) self.assertEqual('my_validator', info.name) self.assertEqual('sure', info.registered) self.assertEqual(123, info.block_num) self.assertEqual('my_pubkey', info.signup_info.poet_public_key) self.assertEqual('beleive me', info.signup_info.proof_data) self.assertEqual('no sybil', info.signup_info.anti_sybil_id)
def test_has_validator_info_not_exists(self): """Given a state view that does not contain a state view for a given validator info, verify that has_validator_info returns False with an unkown id. """ state_view = MockStateView({}) validator_registry_view = ValidatorRegistryView(state_view) self.assertFalse(validator_registry_view.has_validator_info('my_id'))
def test_get_validator_info_not_exists(self): """Given a state view that does not contain a state view for a given validator info, verify that it throws a key error on `get`. """ state_view = MockStateView({}) validator_registry_view = ValidatorRegistryView(state_view) with self.assertRaises(KeyError): validator_registry_view.get_validator_info('my_id')
def test_has_validator_info(self): """Given a state view that contains a state entry for a given validator info, verify that the validator registry returns a true when has_validator_info is called with the validator's id.""" state_view = MockStateView({ to_address('my_id'): ValidatorInfo(name='my_validator', id='my_id', signup_info=SignUpInfo(poet_public_key='my_pubkey', proof_data='beleive me', anti_sybil_id='no sybil'), transaction_id="signature").SerializeToString() }) validator_registry_view = ValidatorRegistryView(state_view) self.assertTrue(validator_registry_view.has_validator_info('my_id'))