def test_create_receipt_update_bad_organization(self): bond = self.store.lookup("bond:isin", "US912828R770") transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Redemption', 'BondID': bond['object-id'], 'PayeeID': "PayeeID" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("No organization") except InvalidTransactionError: pass bond = self.store.lookup("bond:isin", "US912828R770") transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Redemption', 'BondID': bond['object-id'], 'PayeeID': bond['object-id'] }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Not an organization") except InvalidTransactionError: pass
def test_create_coupon(self): date = datetime.datetime(2015, 4, 1) self._set_clock(2015, 4, 1, 1) org = self.store.lookup("organization:name", "Second Bank") bond = self.store.lookup("bond:cusip", "912828R77") coupon = Family._create_coupon(self.store, bond, org, date) self.assertIsNotNone(coupon) transaction = BondTransaction(coupon) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) org_usd_holding = self.store["34d813716009ca1786222a44347ccff" "258a4ab6029d936664fde0d13f23992b5"] self.assertEquals(org_usd_holding["amount"], 25000.0) date = datetime.datetime(2015, 7, 1) self._set_clock(2015, 7, 1, 2) coupon = Family._create_coupon(self.store, bond, org, date) self.assertIsNotNone(coupon) transaction = BondTransaction(coupon) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) org_usd_holding = self.store["34d813716009ca1786222a44347ccff" "258a4ab6029d936664fde0d13f23992b5"] self.assertEquals(org_usd_holding["amount"], 50000.0)
def test_create_receipt_update_bad_bond(self): org = self.store.lookup("organization:name", "Second Bank") transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Redemption', 'BondID': "BondId", 'PayeeID': org['object-id'] }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("No such bond") except InvalidTransactionError: pass transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Redemption', 'BondID': org['object-id'], 'PayeeID': org['object-id'] }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Not a Bond") 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_quote_valid(self): transaction = BondTransaction({ "UpdateType": "CreateQuote", 'Updates': [{ "UpdateType": "CreateQuote", "Firm": "ABCD", "Isin": "US912828R770", "BidPrice": "98-05.875", "BidQty": 25000, "AskPrice": "98-06.875", "AskQty": 25000 }] }) try: transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") transaction = BondTransaction({ "UpdateType": "CreateQuote", 'Updates': [{ "UpdateType": "CreateQuote", "Firm": "ABCD", "Cusip": "912828R77", "BidPrice": "98-05.875", "BidQty": 24000, "AskPrice": "98-06.875", "AskQty": 24000 }] }) try: transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") transaction = BondTransaction({ "UpdateType": "CreateQuote", 'Updates': [{ "UpdateType": "CreateQuote", "Firm": "ABCD", "Cusip": "912828R77", "Isin": "US912828R770", "BidPrice": "98-05.875", "BidQty": 23000, "AskPrice": "98-06.875", "AskQty": 23000 }] }) try: transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid")
def test_create_quote_diff_submitted(self): key = signed_object.generate_signing_key() transaction = BondTransaction({ "UpdateType": "CreateQuote", 'Updates': [{ "UpdateType": "CreateQuote", "Firm": "ABCD", "Isin": "US912828R770", "BidPrice": "98-05.875", "BidQty": 25000, "AskPrice": "98-06.875", "AskQty": 25000 }] }) transaction.sign_object(key) try: transaction.check_valid(self.store) self.fail("Signed by an unauthorized participant") except InvalidTransactionError: pass transaction = BondTransaction({ "UpdateType": "CreateOrganization", 'Updates': [{"UpdateType": "CreateOrganization", "name": "NewBank", "ticker": "F", "pricing_source": "EFGH", "industry": "Test", "authorization": [] }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) key = signed_object.generate_signing_key() transaction = BondTransaction({ "UpdateType": "CreateQuote", 'Updates': [{ "UpdateType": "CreateQuote", "Firm": "EFGH", "Isin": "US912828R770", "BidPrice": "98-05.875", "BidQty": 25000, "AskPrice": "98-06.875", "AskQty": 25000 }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Signed by an unauthorized participant") except InvalidTransactionError: pass
def test_create_holding_valid(self): org = self.store.lookup("organization:name", "Test Bank") transaction = BondTransaction({ "UpdateType": "CreateHolding", 'Updates': [{ "UpdateType": "CreateHolding", "owner_id": org["object-id"], "asset_type": "Currency", "asset_id": "USD", "amount": 10000, "object_id": "34d813716009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b6" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") bond = self.store.lookup("bond:cusip", "912828R77") transaction = BondTransaction({ "UpdateType": "CreateHolding", 'Updates': [{ "UpdateType": "CreateHolding", "owner_id": org["object-id"], "asset_type": "Bond", "asset_id": bond["object-id"], "amount": 10000, "object_id": "34d813716009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b7" }] }) 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_settlement_status(self): org2 = self.store.lookup("organization:name", "Second Bank") transaction = BondTransaction({ "UpdateType": "CreateOrder", 'Updates': [{ "UpdateType": "CreateOrder", "Action": "Buy", "OrderType": "Limit", "FirmId": org2["object-id"], "Isin": "US912828R770", "Quantity": 100000, "LimitPrice": "98-05.875", "LimitYield": 0.015, "object_id": "765432116009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b7" }] }) # quote-id transaction.sign_object(self.key) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") transaction = BondTransaction({ "UpdateType": "CreateSettlement", 'Updates': [{ "UpdateType": "CreateSettlement", "order_id": "765432116009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b7" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Order is not matched") except: pass
def test_create_settlement_ref_count(self): org = self.store.lookup("organization:name", "First Bank")["ref-count"] org2 = self.store.lookup("organization:name", "Second Bank")["ref-count"] transaction = BondTransaction({ "UpdateType": "CreateSettlement", 'Updates': [{ "UpdateType": "CreateSettlement", "order_id": "123453716009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b7" }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") new_org = self.store.lookup("organization:name", "First Bank")["ref-count"] new_org2 = self.store.lookup("organization:name", "Second Bank")["ref-count"] self.assertEquals(org + 1, new_org) self.assertEquals(org2 + 1, new_org)
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_generate_coupons_coupon(self): self._set_clock(2015, 4, 1, 1) signingkey = signed_object.generate_signing_key() ident = signed_object.generate_identifier(signingkey) node = Node(identifier=ident, signingkey=signingkey, address=("localhost", 10021)) node.is_peer = True path = tempfile.mkdtemp() gossip = Gossip(node) journal = Journal(node, gossip, gossip.dispatcher, consensus=DevModeConsensus(), data_directory=path) journal.global_store.TransactionStores['/BondTransaction'] = \ self.store # creates a redemption updates = Family._generate_coupons(journal) self.assertNotEquals(updates, []) transaction = BondTransaction(updates[0]) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store) org_usd_holding = self.store["34d813716009ca1786222a44347ccff" "258a4ab6029d936664fde0d13f23992b5"] self.assertEquals(org_usd_holding["amount"], 25000.0)
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_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_create_holding_refcounts(self): org = self.store.lookup("organization:name", "Test Bank") bond = self.store.lookup("bond:cusip", "912828R77") org_refcount_before = org["ref-count"] bond_refcount_before = bond["ref-count"] transaction = BondTransaction({ "UpdateType": "CreateHolding", 'Updates': [{ "UpdateType": "CreateHolding", "owner_id": org["object-id"], "asset_type": "Bond", "asset_id": bond["object-id"], "amount": 10000 }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") org = self.store.lookup("organization:name", "Test Bank") bond = self.store.lookup("bond:cusip", "912828R77") self.assertEquals(org_refcount_before + 1, org["ref-count"]) self.assertEquals(bond_refcount_before + 1, bond["ref-count"])
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_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_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_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_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_create_holding_owner_id(self): transaction = BondTransaction({ "UpdateType": "CreateHolding", 'Updates': [{ "UpdateType": "CreateHolding", "owner_id": "BadOrganization", "asset_type": "Currency", "asset_id": "USD", "amount": 10000, "object_id": "34d813716009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b6" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Bad Organization") except InvalidTransactionError: pass
def test_coupon_exists(self): org = self.store.lookup("organization:name", "Second Bank") bond = self.store.lookup("bond:cusip", "912828R77") date = datetime.datetime(2015, 4, 1) self._set_clock(2015, 4, 1, 1) self.assertFalse(Family._coupon_exists(self.store, bond, org, date)) transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Coupon', 'BondID': bond['object-id'], 'PayeeID': org['object-id'], 'CouponDate': "04/01/2015" }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") org = self.store.lookup("organization:name", "Second Bank") bond = self.store.lookup("bond:cusip", "912828R77") self.assertTrue(Family._coupon_exists(self.store, bond, org, date))
def test_create_holding_asset_other(self): org = self.store.lookup("organization:name", "Test Bank") transaction = BondTransaction({ "UpdateType": "CreateHolding", 'Updates': [{ "UpdateType": "CreateHolding", "owner_id": org["object-id"], "asset_type": "Cookies", "asset_id": "Coco Chip", "amount": 10000, "object_id": "34d813716009ca1786222a44347ccff258a4ab6029" + "d936664fde0d13f23992b6" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) self.fail("Unknown asset-type") 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_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_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_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 _set_clock(self, year, month, day, num): date = time.mktime(datetime.date(year, month, day).timetuple()) transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'Clock', 'Blocknum': num, 'PreviousBlockId': 0, 'Timestamp': date }] }) transaction.sign_object(self.key) transaction.check_valid(self.store) transaction.apply(self.store)
def test_create_receipt_update_valid(self): self._set_clock(2015, 4, 1, 1) org = self.store.lookup("organization:name", "Second Bank") bond = self.store.lookup("bond:isin", "US912828R770") transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Coupon', 'BondID': bond['object-id'], 'PayeeID': org['object-id'], 'CouponDate': "04/01/2015" }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid") self._set_clock(2016, 1, 2, 2) org = self.store.lookup("organization:name", "Second Bank") bond = self.store.lookup("bond:isin", "US912828R770") transaction = BondTransaction({ 'Updates': [{ 'UpdateType': 'CreateReceipt', 'PaymentType': 'Redemption', 'BondID': bond['object-id'], 'PayeeID': org['object-id'] }] }) transaction.sign_object(self.key) try: transaction.check_valid(self.store) transaction.apply(self.store) except InvalidTransactionError: self.fail("This should be valid")
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)