def test_get_with_previous_store(self): obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2']) self._test_set_and_lookup(obj_store) new_obj_store = ObjectStore(prevstore=obj_store) self.assertEqual(new_obj_store.get(self.names[765]), self.values[765], "Get from previous store")
def test_will_update_on_index(self): obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2']) self._test_set_and_lookup(obj_store) obj = self.values[277] obj['index1'] = '123456789' # Can change an indexed value if it is unique obj_store.set(self.names[277], obj) self.assertEqual(obj_store.lookup('type1:index1', '123456789'), obj, "Can lookup on indexed value that has" " been updated.")
def test_update(self): obj1 = {'object-type': 'type1', 'index1': self.index1s[126], 'index2': self.index2s[126], 'count': 5} obj2 = {'object-type': 'type1', 'index1': self.index1s[126], 'index2': self.index2s[126], 'count': 8} obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2']) obj_store.set('obj1', obj1) obj_store.set('obj1', obj2) self.assertEqual(obj_store.lookup('type1:index1', self.index1s[126]), obj2, "Lookup on index of updated value will find" "updated value") self.assertEqual(obj_store.get('obj1'), obj2, ".get will also get us the updated value")
def test_heterogeneous_delete(self): objectstore = ObjectStore() self._test_lookup_by_all(objectstore) objectstore.delete(self.obj_type2_names[255]) for i2, val in zip(self.index2s, self.obj_type1_values): self.assertEqual( objectstore.lookup('type1:index2', i2), val, "After type2 deletion, " "can still lookup by type1:index2") for i1, val in zip(self.index1s, self.obj_type1_values): self.assertEqual( objectstore.lookup('type1:index1', i1), val, "After type2 deletion, " "can still lookup by type1:index1") def lookup_by_index1_from_deleted(*args): store = args[0] store.lookup('type2:index1', self.index1s[255]) self.assertRaises(KeyError, lookup_by_index1_from_deleted, objectstore, "Lookup by type2:index1 on deleted raises an error") del self.obj_type2_values[255] del self.index2s[255] del self.index1s[255] for i, val in zip(self.index1s, self.obj_type2_values): self.assertEqual(objectstore.lookup('type2:index1', i), val, "Can look up any other type2:index1") for c, val in zip(self.index2s, self.obj_type2_values): self.assertEqual(objectstore.lookup('type2:index2', c), val, "Can look up any other type2:index2")
def test_delete(self): obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2']) self._test_set_and_lookup(obj_store) def lookup_key_that_is_missing(*args, **kwargs): store = args[0] store.lookup('type1:index2', self.index2s[544]) for n in self.names: obj_store.delete(n) self.assertRaises(KeyError, lookup_key_that_is_missing, obj_store, "Lookup of attribute from key that has " "been deleted throws an error")
def test_late_indexing_update(self): obj1 = {'object-type': 'type1', 'index1': self.index1s[126], 'index2': self.index2s[126], 'name': 'obj1'} obj2 = {'object-type': 'type1', 'index1': self.index1s[126], 'index2': self.index2s[126], 'name': 'obj1'} obj_store = ObjectStore() obj_store.set('obj1', obj1) obj_store.set('obj1', obj2) self.assertEqual(obj_store.lookup('type1:index2', self.index2s[126]), obj2, "Late indexing will provide us with the " "updated value") self.assertEqual(obj_store.get('obj1'), obj2, ".get will also get us the updated value")
def test_libor_update_invalid_value_two_month(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 'invalid rate', 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='HCi5tDerqxHZ8han4SmTqMsbKN1JscETRCqYDU3gNQSofp' 't8fm25i5xyo7EwBXDlxpcOyU5em8DVQOGsdyx8jXk=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_invalid_value_one_month(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 'invalid rate', 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='G+eKJzXQBJCEgIj3ZZ46mfp73WqECskUBh4JPjFIMy9D2EAW0' '2ry7VN1NA6r4ZPf2dGtRY50yHSLrRwf/3Yn0gs=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_invalid_value_overnight(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 'invalid rate', 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='HLwpLLCM0TdAOdyj/zpR4LUNp7QQosVTBBTqEq71zZkjKZ3a5y' 'SqRqFAC8Wgv9VQHyRbScLXJxFOG7xH83SxLYc=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_duplicate_date(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='G38pbExUmKqKzdC07QJS1OJSglnpLKGr+PMu4muigey37CdT2P' '7d0PBQxmaWNjtsADdPxQAS5FhtHOQbtD41fkU=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) except InvalidTransactionError: self.fail('This transaction should be valid') transaction.apply(store) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_invalid_value_one_year(self): key = signed_object.generate_signing_key() store = ObjectStore() libor_key = TestCreateLIBORUpdate.libor_key libor_public_key = signing.generate_pubkey(libor_key) update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 'invalid rate' }, libor_public_key=libor_public_key) update.sign_update_object(libor_key) transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_register_validator_re_register(self): key = signed_object.generate_signing_key() public_key_hash = \ hashlib.sha256( signing.encode_pubkey( signing.generate_pubkey(key), 'hex')).hexdigest() validator_id = signed_object.generate_identifier(key) name = 'DasValidator' signup_info = \ SignupInfo.create_signup_info( originator_public_key_hash=public_key_hash, most_recent_wait_certificate_id='0' * 16) store = ObjectStore() transaction = \ ValidatorRegistryTransaction.register_validator( name, validator_id, signup_info) transaction.sign_object(key) try: transaction.check_valid(store) transaction.apply(store) except InvalidTransactionError as e: self.fail('Failed valid transaction: {}'.format(e)) try: # check if valid to register again transaction.check_valid(store) except InvalidTransactionError as e: self.fail('Failure: Double registered validator: {}'.format(e))
def test_libor_update_not_signed(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': '0.1', 'OneWeek': '0.1', 'OneMonth': '0.1', 'TwoMonth': '0.1', 'ThreeMonth': '0.1', 'SixMonth': '0.1', 'OneYear': '0.1' }, signature=None) transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_missing_date(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date=None, rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature="G78QicusrNO9l8Yxt/qJGX0TxkVh0ftSiW9dYkQPL5qYctd" "pb4Cq3GR15gT6DeHj0ujFcf4CK+Pu0Sqe77Zi92Y=") transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_invalid_value_three_month(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 'invalid rate', 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='HO+xNW91CfhWVrvBKyk2P0rak82TPG8ZSsBucI3QhSXT7SegQd' 'y/Sq0dTZC+31rGQgMVdylbXLSO++aIb9OP0y8=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_register_permissioned_validator_invalid(self): signing_key = signed_object.generate_signing_key() unpermissiond_private_key = signed_object.generate_signing_key() pub_key = pybitcointools.encode_pubkey( pybitcointools.privtopub(unpermissiond_private_key), 'hex') permissioned_public_keys = [pub_key] addr = signed_object.generate_identifier(unpermissiond_private_key) permissioned_addrs = [addr] update = { 'whitelist_name': "hyperledger.sawtooth-core.genesis-whitelist", 'verb': 'reg', 'permissioned_public_keys': permissioned_public_keys, 'permissioned_addrs': permissioned_addrs } minfo = {'Update': update} transaction = PermissionedValidatorRegistryTransaction(minfo) transaction.sign_object(signing_key) store = ObjectStore() with self.assertRaises(InvalidTransactionError): transaction.check_valid(store) self.fail("Failure: Verified an invalid transaction")
def test_libor_update_invalid_value_one_year(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 'invalid rate' }, signature='HDRqSWSJN8wCPMGITZLx0pW/ccqsMDYnnG9mbRUL3x1O8bz' 'tfGmgkD9n+6OQgb/glO52zuJdFIFV5ehCdr4L0Ug=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_date_in_the_future(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2100-01-01', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='G/gl8XhptfXUGih7X4g4s8EeXNXpX+qz7yEHd6ah1xXyrica2p' 'pdePFikWb9wbR5rOnvKC8FDAIg8CadhAaizt0=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_register_validator_key_mismatch(self): key = signed_object.generate_signing_key() public_key_hash = \ hashlib.sha256( signing.encode_pubkey( signing.generate_pubkey(key), 'hex')).hexdigest() key2 = signed_object.generate_signing_key() validator_id = signed_object.generate_identifier(key) name = 'DasValidator' signup_info = \ SignupInfo.create_signup_info( originator_public_key_hash=public_key_hash, most_recent_wait_certificate_id='0' * 16) store = ObjectStore() transaction = \ ValidatorRegistryTransaction.register_validator( name, validator_id, signup_info) transaction.sign_object(key2) with self.assertRaises(InvalidTransactionError): transaction.check_valid(store) self.fail("Failure: Verified an invalid transaction")
def test_libor_update_signature_does_not_match(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': '0.1', 'OneWeek': '0.1', 'OneMonth': '0.1', 'TwoMonth': '0.1', 'ThreeMonth': '0.1', 'SixMonth': '0.1', 'OneYear': '0.1', }, signature='hjoq7knkzlxo4qubsjslfarl1ej/qso0ar4zsucd5xguniuvqjv' 'zj5lrqhayi5tqvniqxai0lkt31zqsztgojxw=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_invalid_value_one_week(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 'invalid rate', 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 0.1, 'OneYear': 0.1 }, signature='HBYQ8UxaSl6tTv2Ab3Hctki7kl+G8qBthr+4vVXRvJhMrppcEA3' 'CMtm3OitDoYsqmB6MC0WiFqqgSzOEiqJmPUg=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_libor_update_invalid_value_six_month(self): key = signed_object.generate_signing_key() store = ObjectStore() update = \ CreateLIBORUpdate( update_type='CreateLIBOR', date='2016-05-24', rates={ 'Overnight': 0.1, 'OneWeek': 0.1, 'OneMonth': 0.1, 'TwoMonth': 0.1, 'ThreeMonth': 0.1, 'SixMonth': 'invalid rate', 'OneYear': 0.1 }, signature='HHlwEyzhFYP53vg2tE44snVyAD4UUIzElBiaiNUPZLKrkGmO' '5TLHHmRJ8RvTAkxL5elIicRiNwOKc7JI0Zjkn5o=') transaction = BondTransaction() transaction._updates = [update] transaction.sign_object(key) try: transaction.check_valid(store) self.fail('This transaction should be invalid') except InvalidTransactionError: pass
def test_heterogeneous_delete(self): objectstore = ObjectStore() self._test_lookup_by_all(objectstore) objectstore.delete(self.obj_type2_names[255]) for i2, val in zip(self.index2s, self.obj_type1_values): self.assertEqual(objectstore.lookup('type1:index2', i2), val, "After type2 deletion, " "can still lookup by type1:index2") for i1, val in zip(self.index1s, self.obj_type1_values): self.assertEqual(objectstore.lookup('type1:index1', i1), val, "After type2 deletion, " "can still lookup by type1:index1") def lookup_by_index1_from_deleted(*args): store = args[0] store.lookup('type2:index1', self.index1s[255]) self.assertRaises(KeyError, lookup_by_index1_from_deleted, objectstore, "Lookup by type2:index1 on deleted raises an error") del self.obj_type2_values[255] del self.index2s[255] del self.index1s[255] for i, val in zip(self.index1s, self.obj_type2_values): self.assertEqual(objectstore.lookup('type2:index1', i), val, "Can look up any other type2:index1") for c, val in zip(self.index2s, self.obj_type2_values): self.assertEqual(objectstore.lookup('type2:index2', c), val, "Can look up any other type2:index2")
def test_unique_constraint(self): obj1 = {'index1': '12345', 'index2': self.index2s[114], 'object-type': 'type1'} obj2 = {'index1': '12345', 'index2': self.index2s[125], 'object-type': 'type1'} obj_store = ObjectStore(indexes=['type1:index1', 'type1:index2']) obj_store.set('obj1', obj1) def set_a_value_with_not_unique_key(*args, **kwargs): store = args[0] store.set('obj2', obj2) self.assertRaises(UniqueConstraintError, set_a_value_with_not_unique_key, obj_store, "Setting a value with nonunique indexed " "key raises an error")
def setUp(self): self.key = signed_object.generate_signing_key() participant = CreateParticipantUpdate("CreateParticipant", "testuser") object_id = participant._object_id transaction = BondTransaction({}) transaction._updates = [participant] self.store = ObjectStore() transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) sub = self.store.lookup("participant:username", "testuser")["object-id"] transaction = BondTransaction({ "UpdateType": "CreateOrganization", 'Updates': [{ "UpdateType": "CreateOrganization", "name": "Test Bank", "ticker": "T", "pricing_source": "ABCD", "industry": "Test", "authorization": [{ "ParticipantId": sub, "Role": "marketmaker" }] }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store)
def test_erroring_on_update(self): obj2 = {'object-type': 'type1', 'index1': self.index1s[126], 'index2': self.index2s[266], 'name': self.names[126]} obj_store = ObjectStore() self._test_set_and_lookup(obj_store) def changed_an_index_value_to_another_stores_field(*args): store = args[0] store.set(self.names[126], obj2) self.assertRaises(UniqueConstraintError, changed_an_index_value_to_another_stores_field, obj_store, "If you update a value and one of the fields " "belongs to another object the " "Store will error")
def test_dup_key_late_indexing(self): """ ._build_index will index the first set value with that key """ obj1 = {'index1': '12345', 'index2': self.index2s[114], 'object-type': 'type1'} obj_store = ObjectStore() obj_store.set('obj1', obj1) for val in self.values: val['index1'] = '12345' obj_store.set('obj2', val) self.assertEqual(obj_store.lookup('type1:index1', '12345'), obj1, "Lookup by non-unique late-indexed" "value will get the first one set")
def test_index_error_handling(self): malformed_index = 'index1' def lookup_by_malformed_index(*args, **kwargs): store = args[0] store.lookup(malformed_index, self.index1s[225]) obj_store = ObjectStore() self._test_set_and_lookup(obj_store) self.assertRaises(MalformedIndexError, lookup_by_malformed_index, obj_store, "Lookup by malformed index throws an exception") def malformed_index_in_init(*args, **kwargs): objectstore = ObjectStore(indexes=[malformed_index]) self.assertRaises(MalformedIndexError, malformed_index_in_init, msg="The constructor checks for malformed indexes")
def test_register_permissioned_validator_valid(self): signing_key = signed_object.generate_signing_key() try: priv_key1 = pybitcointools.decode_privkey( open('./tests/unit/keys/pv1.wif', "r").read().strip(), 'wif') priv_key2 = pybitcointools.decode_privkey( open('./tests/unit/keys/pv2.wif', "r").read().strip(), 'wif') except IOError as ex: raise Exception('IOError: {}'.format(str(ex))) pub_key1 = pybitcointools.encode_pubkey( pybitcointools.privtopub(priv_key1), 'hex') pub_key2 = pybitcointools.encode_pubkey( pybitcointools.privtopub(priv_key2), 'hex') permissioned_public_keys = [pub_key1, pub_key2] addr1 = signed_object.generate_identifier(priv_key1) addr2 = signed_object.generate_identifier(priv_key2) permissioned_addrs = [addr1, addr2] update = { 'whitelist_name': "hyperledger.sawtooth-core.genesis-whitelist", 'verb': 'reg', 'permissioned_public_keys': permissioned_public_keys, 'permissioned_addrs': permissioned_addrs } minfo = {'Update': update} transaction = PermissionedValidatorRegistryTransaction(minfo) transaction.sign_object(signing_key) store = ObjectStore() try: transaction.check_valid(store) transaction.apply(store) except InvalidTransactionError as e: self.fail('Failed valid transaction: {}'.format(e))
class TestCreateBondUpdate(unittest.TestCase): def setUp(self): self.key = signed_object.generate_signing_key() participant = CreateParticipantUpdate("CreateParticipant", "testuser") object_id = participant._object_id transaction = BondTransaction({}) transaction._updates = [participant] self.store = ObjectStore() transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) sub = self.store.lookup("participant:username", "testuser")["object-id"] transaction = BondTransaction({ "UpdateType": "CreateOrganization", 'Updates': [{ "UpdateType": "CreateOrganization", "name": "Test Bank", "ticker": "T", "pricing_source": "ABCD", "industry": "Test", "authorization": [{ "ParticipantId": sub, "Role": "marketmaker" }] }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) def test_create_bond_valid(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "isin": "US912828R770", "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") def test_create_bond_ticker(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "isin": "US912828R770", "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "AB" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Ticker doesnt exist") except InvalidTransactionError: pass def test_create_bond_isin_cusip(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Need either Isin and Cusip") except InvalidTransactionError: pass def test_create_bond_isin(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "isin": "US912828R770", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) except InvalidTransactionError: self.fail("This should be valid") def test_create_bond_cusp(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) except InvalidTransactionError: self.fail("This should be valid") def test_create_bond_libor(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Floating", "coupon_benchmark": 'Overnight', "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) try: transaction.check_valid(self.store) except InvalidTransactionError: self.fail("This should be valid") transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Floating", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("No Coupon Benchmark") except InvalidTransactionError: pass transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Floating", "coupon_benchmark": "OneMinute", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Incorrect Coupon Benchmark") except InvalidTransactionError: pass def test_create_bond_maturity_date(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "isin": "US912828R770", "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01112022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Inncorect Maturity date format") except InvalidTransactionError: pass transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "isin": "US912828R770", "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "20221101", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Inncorect Maturity date format") except InvalidTransactionError: pass def test_create_bond_creator(self): key = signed_object.generate_signing_key() transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Fixed", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "isin": "US912828R770", "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(key) try: transaction.check_valid(self.store) self.fail("Bad creator") except InvalidTransactionError: pass def test_create_bond_coupon_type(self): transaction = BondTransaction({ "UpdateType": "CreateBond", 'Updates': [{ "UpdateType": "CreateBond", "amount_outstanding": 42671000000, 'corporate_debt_ratings': { "Fitch": "AAA", "Moodys": "AAA", "S&P": "AA+" }, "coupon_rate": 1.375, "coupon_type": "Free", "coupon_frequency": "Quarterly", "cusip": "912828R77", "face_value": 1000, "first_settlement_date": "01/11/2012", "first_coupon_date": "03/01/2012", "maturity_date": "01/11/2022", "issuer": "T" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Incorrect Coupon type") except InvalidTransactionError: pass
def test_store_with_partial_indexes(self): obj_store = ObjectStore(indexes=['type1:index1']) self._test_set_and_lookup(obj_store)