def test_raise_key_error_on_missing_receipt(self): """Tests that we correctly raise key error on a missing receipt """ receipt_store = TransactionReceiptStore(DictDatabase()) with self.assertRaises(KeyError): receipt_store.get('unknown')
def test_receipt_store_get_and_set(self): """Tests that we correctly get and set state changes to a ReceiptStore. This test sets a list of receipts and then gets them back, ensuring that the data is the same. """ receipt_store = TransactionReceiptStore(DictDatabase()) receipts = [] for i in range(10): state_changes = [] events = [] data = [] for j in range(10): string = str(j) byte = string.encode() state_changes.append( StateChange(address='a100000' + string, value=byte, type=StateChange.SET)) events.append( Event( event_type="test", data=byte, attributes=[Event.Attribute(key=string, value=string)])) data.append( TransactionReceipt.Data(data_type="test", data=byte)) receipts.append( TransactionReceipt(state_changes=state_changes, events=events, data=data)) for i in range(len(receipts)): receipt_store.put(str(i), receipts[i]) for i in range(len(receipts)): stored_receipt = receipt_store.get(str(i)) self.assertEqual(stored_receipt.state_changes, receipts[i].state_changes) self.assertEqual(stored_receipt.events, receipts[i].events) self.assertEqual(stored_receipt.data, receipts[i].data)
def test_receipt_store_get_and_set(self): """Tests that we correctly get and set state changes to a ReceiptStore. This test sets a list of receipts and then gets them back, ensuring that the data is the same. """ receipt_store = TransactionReceiptStore(DictDatabase()) receipts = [] for i in range(10): state_changes = [] events = [] data = [] for j in range(10): string = str(j) byte = string.encode() state_changes.append( StateChange( address='a100000' + string, value=byte, type=StateChange.SET)) events.append( Event( event_type="test", data=byte, attributes=[Event.Attribute(key=string, value=string)])) data.append(byte) receipts.append( TransactionReceipt( state_changes=state_changes, events=events, data=data)) for i, receipt in enumerate(receipts): receipt_store.put(str(i), receipt) for i, receipt in enumerate(receipts): stored_receipt = receipt_store.get(str(i)) self.assertEqual(stored_receipt.state_changes, receipt.state_changes) self.assertEqual(stored_receipt.events, receipt.events) self.assertEqual(stored_receipt.data, receipt.data)
def do_receipt_store_get_and_set(): receipt_store = TransactionReceiptStore(DictDatabase()) receipts = [] for i in range(10): state_changes = [] events = [] data = [] for j in range(10): string = str(j) byte = string.encode() state_changes.append( StateChange( address='a100000' + string, value=byte, type=StateChange.SET)) events.append( Event( event_type="test", data=byte, attributes=[Event.Attribute(key=string, value=string)])) data.append(byte) receipts.append( TransactionReceipt( state_changes=state_changes, events=events, data=data)) for i, receipt in enumerate(receipts): receipt_store.put(str(i), receipt) for i, receipt in enumerate(receipts): stored_receipt = receipt_store.get(str(i)) assert stored_receipt.state_changes == receipt.state_changes
def do_raise_key_error_on_missing_receipt(): receipt_store = TransactionReceiptStore(DictDatabase()) with pytest.raises(KeyError): receipt_store.get('unknown')