def test_event_description_different_outcomes(self): oracle = CentralizedOracleFactory() oracle.event_description.outcomes = ['Yes', 'No', 'Third'] oracle.event_description.save() event = CategoricalEventFactory(oracle=oracle) # Categorical Event with different outcomes block = { 'number': event.creation_block, 'timestamp': mktime(event.creation_date_time.timetuple()) } categorical_event = { 'address': event.factory, 'params': [{ 'name': 'creator', 'value': event.creator }, { 'name': 'collateralToken', 'value': event.creator }, { 'name': 'oracle', 'value': oracle.address }, { 'name': 'outcomeCount', 'value': 2 }, { 'name': 'categoricalEvent', 'value': event.address, }] } event.delete() s = CategoricalEventSerializer(data=categorical_event, block=block) self.assertFalse(s.is_valid()) categorical_event['params'][3]['value'] = 3 s2 = CategoricalEventSerializer(data=categorical_event, block=block) self.assertTrue(s2.is_valid(), s.errors) instance = s2.save() self.assertIsNotNone(instance)
def test_create_categorical_event(self): event = CategoricalEventFactory() oracle = CentralizedOracleFactory() block = { 'number': event.creation_block, 'timestamp': mktime(event.creation_date_time.timetuple()) } categorical_event = { 'address': event.factory, 'params': [{ 'name': 'creator', 'value': event.creator }, { 'name': 'collateralToken', 'value': event.collateral_token }, { 'name': 'oracle', 'value': oracle.address }, { 'name': 'outcomeCount', 'value': 2 }] } event.delete() s = CategoricalEventSerializer(data=categorical_event, block=block) self.assertFalse(s.is_valid(), s.errors) categorical_event.get('params').append({ 'name': 'categoricalEvent', 'value': event.address }) s = CategoricalEventSerializer(data=categorical_event, block=block) self.assertTrue(s.is_valid(), s.errors) instance = s.save() self.assertIsNotNone(instance)
def test_categorical_event_receiver(self): event = CategoricalEventFactory() oracle = OracleFactory() event_address = event.address block = { 'number': event.creation_block, 'timestamp': self.to_timestamp(event.creation_date_time) } categorical_event = { 'address': event.factory, 'name': 'CategoricalEventCreation', 'params': [{ 'name': 'creator', 'value': event.creator }, { 'name': 'collateralToken', 'value': event.collateral_token }, { 'name': 'oracle', 'value': oracle.address }, { 'name': 'outcomeCount', 'value': 2 }, { 'name': 'categoricalEvent', 'value': event_address }] } event.delete() EventFactoryReceiver().save(categorical_event, block) event = CategoricalEvent.objects.get(address=event_address) self.assertIsNotNone(event.pk)