def test_record_task_to_list(self): task_list = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(task_list) self.assertEqual(len(task_list), 0) @crosstown_traffic() def add_to_task_list(): pass self.assertEqual(len(task_list), 1)
def test_record_task_to_list(): task_list = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(task_list) assert len(task_list) == 0 @crosstown_traffic() def add_to_task_list(): pass assert len(task_list) == 1
def test_record_task_to_list(self): task_list = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(task_list) self.assertEqual(len(task_list), 0) @crosstown_traffic() def add_to_task_list(): pass self.assertEqual(len(task_list), 1)
def test_record_task_to_list(): task_list = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(task_list) assert len(task_list) == 0 @crosstown_traffic() def add_to_task_list(): pass assert len(task_list) == 1
def test_learning_from_node_with_no_known_nodes(ursula_federated_test_config): lonely_ursula_maker = partial(make_federated_ursulas, ursula_config=ursula_federated_test_config, quantity=1, know_each_other=False) lonely_teacher = lonely_ursula_maker().pop() lonely_learner = lonely_ursula_maker(known_nodes=[lonely_teacher]).pop() learning_callers = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory(learning_callers) result = lonely_learner.learn_from_teacher_node() assert result is NO_KNOWN_NODES
def test_vladimir_illegal_interface_key_does_not_propagate(blockchain_ursulas): """ Although Ursulas propagate each other's interface information, as demonstrated above, they do not propagate interface information for Vladimir. Specifically, if Vladimir tries to perform the most obvious imitation attack - propagating his own wallet address along with Ursula's information - the validity check will catch it and Ursula will refuse to propagate it and also record Vladimir's details. """ ursulas = list(blockchain_ursulas) ursula_whom_vladimir_will_imitate, other_ursula = ursulas[0], ursulas[1] # Vladimir sees Ursula on the network and tries to use her public information. vladimir = Vladimir.from_target_ursula(ursula_whom_vladimir_will_imitate) # This Ursula is totally legit... ursula_whom_vladimir_will_imitate.verify_node(MockRestMiddleware(), accept_federated_only=True) learning_callers = [] crosstown_traffic.decorator = crosstownTaskListDecoratorFactory( learning_callers) vladimir.network_middleware.propagate_shitty_interface_id( other_ursula, bytes(vladimir)) # So far, Ursula hasn't noticed any Vladimirs. assert other_ursula.suspicious_activities_witnessed['vladimirs'] == [] # ...but now, Ursula will now try to learn about Vladimir on a different thread. # We only passed one node (Vladimir)... learn_about_vladimir = learning_callers.pop() # ...so there was only one learning caller in the queue (now none since we popped it just now). assert len(learning_callers) == 0 # OK, so cool, let's see what happens when Ursula tries to learn about Vlad. learn_about_vladimir() # And indeed, Ursula noticed the situation. # She didn't record Vladimir's address. assert vladimir not in other_ursula.known_nodes # But she *did* record the actual Ursula's address. assert ursula_whom_vladimir_will_imitate in other_ursula.known_nodes # Furthermore, she properly marked Vladimir as suspicious. assert vladimir in other_ursula.suspicious_activities_witnessed[ 'vladimirs']