def _commit(schema, oid, action, payload): res = eventstore(schema)(oid=oid, action=action, payload=payload) res['action'] = action res['payload'] = payload if schema in ['petchain', 'vetchain']: try: print('get_chain', schema, oid) _chain_id = eventstore(schema).storage.get_chain_id(schema, oid) print("create entry in blockchain %s" % _chain_id) chain_res = factom.chain_add_entry( chain_id=_chain_id, external_ids=[schema, oid, action], content=json.dumps(res)) print("created entry in blockchain %s" % _chain_id) _payload = json.loads(payload) _payload['blockchain_entry'] = chain_res['entry_hash'] res['payload'] = json.dumps(_payload) print(res) #_payload = json.loads(payload) except: # FIXME this is happening when chain is not initialized print('failed to commit to chain', schema, oid) pass return res
def commit(schema, oid, action, payload): """ append event to eventstore """ res = eventstore(schema)(oid=oid, action=action, payload=payload) res['action'] = action sio.emit('commit', res) return res
def test_commit_unknown_action(self): """ try to append an event to a stream that doesn't exist """ self.assertTrue(rpc.rpc_stream_create(self.schema, self.stream)) count_event = rpc.eventstore(self.schema) res = count_event(oid='foo', action='ACTION_THAT_DOES_NOT_EXIST') self.assertTrue('id' not in res) self.assertEqual(res['__err__'], 'INVALID_INPUT')
def test_commit_invalid_action(self): """ try to trigger an action that results in a negative (invalid) output """ self.assertTrue(rpc.rpc_stream_create(self.schema, self.stream)) count_event = rpc.eventstore(self.schema) res = count_event(oid='foo', action='DEC_0') self.assertTrue('id' not in res) self.assertEqual(res['__err__'], 'INVALID_OUTPUT')
def setUp(self): """ build a sample eventstream """ self.events = [] rpc.rpc_schema_destroy(self.schema) self.assertTrue(rpc.rpc_schema_create(self.machine, self.schema)) self.assertTrue(rpc.rpc_schema_exists(self.schema)) self.assertTrue(rpc.rpc_stream_create(self.schema, self.stream)) self.assertTrue(rpc.rpc_stream_exists(self.schema, self.stream)) self.count_event = rpc.eventstore(self.schema) for _ in range(0, self.num_events): self.events.append( self.count_event(oid='foo', action='INC_0', payload='{"testing": "foo"}'))
def test_valid_commit(self): """ append event to eventstore db with pre-existing stream""" self.assertTrue(rpc.rpc_stream_create(self.schema, self.stream)) count_event = rpc.eventstore(self.schema) res = count_event(oid='foo', action='INC_0') self.assertTrue('__err__' not in res) self.assertTrue('id' in res) self.assertEqual(res['rev'], 1) self.assertEqual(res['oid'], self.stream) res = count_event(oid='foo', action='INC_0') self.assertTrue('__err__' not in res) self.assertTrue('id' in res) self.assertEqual(res['rev'], 2) self.assertEqual(res['oid'], self.stream)
def get(self, schema, stream_oid): res = eventstore(schema).storage.db.events.fetchall(stream_oid) return res, 200, None
def get(self, schema, oid): res = eventstore(schema).storage.db.states.fetch(oid) return res, 200, None
def get(self, schema, eventid): res = eventstore(schema).storage.db.events.fetch(eventid) return res, 200, None
def test_commit_missing_stream(self): """ try to append an event to a stream that doesn't exist """ count_event = rpc.eventstore(self.schema) res = count_event(oid='foo', action='INC_0') self.assertTrue('id' not in res) self.assertEqual(res['__err__'], 'INVALID_INPUT')