From 208df71640ff7e320768263a6b0e3c32292c8d2b Mon Sep 17 00:00:00 2001 From: pi314x <51694688+pi314x@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:16:57 +0100 Subject: [PATCH 1/9] Update test_transactions.py added tests for samet_fund, credit_offer, credit_deal --- tests/test_transactions.py | 195 +++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index bdaf72b..9335b8e 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1077,3 +1077,198 @@ def compareConstructedTX(self): print("ist: %s" % txWire[:-130]) print(txWire[:-130] == self.cm[:-130]) self.assertEqual(self.cm[:-130], txWire[:-130]) + + def test_samet_fund_create(self): + self.op = operations.Samet_fund_create( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "owner_account": "1.2.123", + "asset_type": "1.3.0", + "balance": 10000, + "fee_rate": 1, + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_samet_fund_delete(self): + self.op = operations.Samet_fund_delete( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "owner_account": "1.2.123", + "fund_id": "1.20.1", + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_samet_fund_update(self): + self.op = operations.Samet_fund_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "owner_account": "1.2.123", + "fund_id": "1.20.1", + "delta_amount": 100, + "new_fee_rate": 2, + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_samet_fund_borrow(self): + self.op = operations.Samet_fund_borrow( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "borrower": "1.2.123", + "fund_id": "1.20.1", + "borrow_amount": {"amount": 10, "asset_id": "1.3.0"}, + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_samet_fund_repay(self): + self.op = operations.Samet_fund_repay( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "account": "1.2.123", + "fund_id": "1.20.1", + "repay_amount": {"amount": 10, "asset_id": "1.3.0"}, + "fund_fee": {"amount": 10, "asset_id": "1.3.0"}, + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_credit_offer_create(self): + self.op = operations.Credit_offer_create( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "owner_account": "1.2.123", + "asset_type": "1.3.0", + "balance": 10000, + "fee_rate": 1, + "max_duration_seconds": 10000, + "min_deal_amount": 1000, + "enabled": True, + "auto_disable_time": 1000, + "acceptable_collateral": + [0, + { + "asset": "1.2.1" + } + ], + "acceptable_borrowers": + [0, + { + "account": "1.2.1" + } + ], + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_credit_offer_delete(self): + self.op = operations.Credit_offer_delete( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "owner_account": "1.2.123", + "offer_id": "1.21.1", + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_credit_offer_update(self): + self.op = operations.Credit_offer_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "owner_account": "1.2.123", + "offer_id": "1.21.1", + "delta_amount": {"amount": 1, "asset_id": "1.3.0"}, + "fee_rate": 1, + "max_duration_seconds": 1000, + "min_deal_amount": 10, + "enabled": True, + "auto_disable_time": False, + "acceptable_collateral": + [0, + { + "asset": "1.2.1" + } + ], + "acceptable_borrowers": + [0, + { + "account": "1.2.1" + } + ], + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_credit_offer_accept(self): + self.op = operations.Credit_offer_accept( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "borrower": "1.2.123", + "offer_id": "1.21.1", + "borrow_amount": {"amount": 10, "asset_id": "1.3.0"}, + "collateral": {"amount": 10, "asset_id": "1.3.0"}, + "max_fee_rate": 1, + "min_duration_seconds": 1000, + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_credit_deal_repay(self): + self.op = operations.Credit_deal_repay( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "account": "1.2.123", + "deal_id": "1.22.2356", + "repay_amount": {"amount": 10, "asset_id": "1.3.0"}, + "credit_fee": {"amount": 10, "asset_id": "1.3.0"}, + "extensions": [], + } + ) + self.cm = () + self.doit(1) + + + def test_credit_deal_expired(self): + self.op = operations.Credit_deal_expired( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "deal_id": "1.22.2356", + "offer_id": "1.21.1", + "offer_owner": "1.2.123", + "borrower": "1.2.123", + "unpaid_amount": {"amount": 10, "asset_id": "1.3.0"}, + "collateral": {"amount": 10, "asset_id": "1.3.0"}, + "fee_rate": 1, + } + ) + self.cm = () + self.doit(1) From d58ad3bc7117660362a427c753badf3c3f791e69 Mon Sep 17 00:00:00 2001 From: pi314x <51694688+pi314x@users.noreply.github.com> Date: Tue, 21 Nov 2023 23:04:01 +0100 Subject: [PATCH 2/9] Update test_transactions.py 9/11 tests ok --- tests/test_transactions.py | 153 +++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 75 deletions(-) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 9335b8e..dfce90d 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1045,54 +1045,22 @@ def test_assert_b(self): ) self.doit(0) - def compareConstructedTX(self): - self.maxDiff = None - self.op = operations.Call_order_update( - **{ - "fee": {"amount": 100, "asset_id": "1.3.0"}, - "delta_debt": {"amount": 10000, "asset_id": "1.3.22"}, - "delta_collateral": {"amount": 100000000, "asset_id": "1.3.0"}, - "funding_account": "1.2.29", - "extensions": {"target_collateral_ratio": 12345}, - } - ) - ops = [Operation(self.op)] - tx = Signed_Transaction( - ref_block_num=ref_block_num, - ref_block_prefix=ref_block_prefix, - expiration=expiration, - operations=ops, - ) - tx = tx.sign([wif], chain=prefix) - tx.verify([PrivateKey(wif).pubkey], prefix) - txWire = hexlify(bytes(tx)).decode("ascii") - print("=" * 80) - pprint(tx.json()) - print("=" * 80) - - # Test against Bitshares backened - self.cm = bitshares.rpc.get_transaction_hex(tx.json()) - - print("soll: %s" % self.cm[:-130]) - print("ist: %s" % txWire[:-130]) - print(txWire[:-130] == self.cm[:-130]) - self.assertEqual(self.cm[:-130], txWire[:-130]) - def test_samet_fund_create(self): + def test_samet_fund_create(self): self.op = operations.Samet_fund_create( **{ "fee": {"amount": 0, "asset_id": "1.3.0"}, - "owner_account": "1.2.123", + "owner_account": "1.2.310", "asset_type": "1.3.0", "balance": 10000, "fee_rate": 1, "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c804570140000000000000000000b60200102700000000000001000000000001203431966ca7e7f40e921633cd767eece0ddefc5abb5224965cca6458dfa28572b687c459a2f4189bf1a41e13336fac6db10cc8c90215888948453b5063a8ccb9f') + self.doit() + + def test_samet_fund_delete(self): self.op = operations.Samet_fund_delete( **{ @@ -1102,10 +1070,10 @@ def test_samet_fund_delete(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701410000000000000000007b010000011f4abefaf5a630eace47f6db44d6516c4e459e70cd89ba5988586d04be40646cf3723cf4b5979e5d094b819f94c37d19e4fac5a0aa20ba3ff8dab8d8482b5356d8') + self.doit() + + def test_samet_fund_update(self): self.op = operations.Samet_fund_update( **{ @@ -1117,10 +1085,10 @@ def test_samet_fund_update(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701420000000000000000007b010001020000000000011f08656f260d4e4c6580202ab2520cad06cdc2539f03c3a74bcc3b6a8cdf2da5f84b252f09f15b77e825f5bb3fe7ff70a28d48516160653318beda6e156ba47987') + self.doit() + + def test_samet_fund_borrow(self): self.op = operations.Samet_fund_borrow( **{ @@ -1131,10 +1099,10 @@ def test_samet_fund_borrow(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701430000000000000000007b010a00000000000000000000012007d969d65e15f9bb2c227fdd1baf74fbb0ce3e9ef197b386098188a78c5a1b992a1d7da0d39a91fb862536b53d719f02d88657cb21ae1c2ab55222d4814a893d') + self.doit() + + def test_samet_fund_repay(self): self.op = operations.Samet_fund_repay( **{ @@ -1146,10 +1114,10 @@ def test_samet_fund_repay(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701440000000000000000007b010a00000000000000000a00000000000000000000011f573766a5dfe79df21d82df4a858a032d083e7b5db8f1d10cf6c0f48967965190607170df053d90fdf46f6fe1d10e160d292de03697136f91865588718a272e88') + self.doit() + + def test_credit_offer_create(self): self.op = operations.Credit_offer_create( **{ @@ -1160,12 +1128,12 @@ def test_credit_offer_create(self): "fee_rate": 1, "max_duration_seconds": 10000, "min_deal_amount": 1000, - "enabled": True, + "enabled": False, "auto_disable_time": 1000, "acceptable_collateral": [0, { - "asset": "1.2.1" + "asset": "1.3.0" } ], "acceptable_borrowers": @@ -1179,8 +1147,8 @@ def test_credit_offer_create(self): ) self.cm = () self.doit(1) - - + + def test_credit_offer_delete(self): self.op = operations.Credit_offer_delete( **{ @@ -1190,10 +1158,10 @@ def test_credit_offer_delete(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701460000000000000000007b010000012042aed7548e971617836c55d55c57b5ecd15e2ef8ed1cdf56c380891ce10e2aaa743e3665de606a7833145a1a2dbe5b60870396972e9e5c803040ee4cec8a8772') + self.doit() + + def test_credit_offer_update(self): self.op = operations.Credit_offer_update( **{ @@ -1209,7 +1177,7 @@ def test_credit_offer_update(self): "acceptable_collateral": [0, { - "asset": "1.2.1" + "asset": "1.3.0" } ], "acceptable_borrowers": @@ -1223,8 +1191,8 @@ def test_credit_offer_update(self): ) self.cm = () self.doit(1) - - + + def test_credit_offer_accept(self): self.op = operations.Credit_offer_accept( **{ @@ -1238,10 +1206,10 @@ def test_credit_offer_accept(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701480000000000000000007b0100000000000000000000000000000000000001000000e8030000000001201dda600d9efc172ee7e0ca6a2b1279709184d0bb0960afd93b49f60f8d90caed6b0f84de19ee54d7434ee11ec0af1f45415f4b024adbf0ca59a9e167eab3901b') + self.doit() + + def test_credit_deal_repay(self): self.op = operations.Credit_deal_repay( **{ @@ -1253,10 +1221,10 @@ def test_credit_deal_repay(self): "extensions": [], } ) - self.cm = () - self.doit(1) - - + self.cm = ('f68585abf4dce7c8045701490000000000000000007bb412000000000000000000000000000000000000000001203ba717f69b6ed214ef1a105bda7756149cee25c0c92c48a7f2d59dee88997cec3f9254df2bd2476cf2df16b10ebca0937f8daf2eecccfb8848e4faed9b8c0df7') + self.doit() + + def test_credit_deal_expired(self): self.op = operations.Credit_deal_expired( **{ @@ -1270,5 +1238,40 @@ def test_credit_deal_expired(self): "fee_rate": 1, } ) - self.cm = () - self.doit(1) + self.cm = ('f68585abf4dce7c80457014a000000000000000000b412017b7b000000000000000000000000000000000000010000000001207e5770f0fae74fc78bebbe5267583a824999d6356698ebce0a25e4a468bd3e356ca10920e3c4301537bd02205e63617546a5d8eded230655d170529801838a3f') + self.doit() + + + def compareConstructedTX(self): + self.maxDiff = None + self.op = operations.Call_order_update( + **{ + "fee": {"amount": 100, "asset_id": "1.3.0"}, + "delta_debt": {"amount": 10000, "asset_id": "1.3.22"}, + "delta_collateral": {"amount": 100000000, "asset_id": "1.3.0"}, + "funding_account": "1.2.29", + "extensions": {"target_collateral_ratio": 12345}, + } + ) + ops = [Operation(self.op)] + tx = Signed_Transaction( + ref_block_num=ref_block_num, + ref_block_prefix=ref_block_prefix, + expiration=expiration, + operations=ops, + ) + tx = tx.sign([wif], chain=prefix) + tx.verify([PrivateKey(wif).pubkey], prefix) + txWire = hexlify(bytes(tx)).decode("ascii") + print("=" * 80) + pprint(tx.json()) + print("=" * 80) + + # Test against Bitshares backened + self.cm = bitshares.rpc.get_transaction_hex(tx.json()) + + print("soll: %s" % self.cm[:-130]) + print("ist: %s" % txWire[:-130]) + print(txWire[:-130] == self.cm[:-130]) + self.assertEqual(self.cm[:-130], txWire[:-130]) + From 3b6e1e7af664a8de1bada0f613b7b43b883759c2 Mon Sep 17 00:00:00 2001 From: pi314x <51694688+pi314x@users.noreply.github.com> Date: Wed, 22 Nov 2023 00:35:22 +0100 Subject: [PATCH 3/9] Update test_transactions.py --- tests/test_transactions.py | 40 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index dfce90d..c25491c 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1131,17 +1131,21 @@ def test_credit_offer_create(self): "enabled": False, "auto_disable_time": 1000, "acceptable_collateral": - [0, + [[ + "1.3.0", { - "asset": "1.3.0" + "base": { + "amount": 1, "asset_id": "1.3.2512" + }, + "quote": { + "amount": 250000, "asset_id": "1.3.0" + } } - ], + ]], "acceptable_borrowers": - [0, - { - "account": "1.2.1" - } - ], + [[ + "1.2.1",1000 + ]], "extensions": [], } ) @@ -1175,17 +1179,21 @@ def test_credit_offer_update(self): "enabled": True, "auto_disable_time": False, "acceptable_collateral": - [0, + [[ + "1.3.0", { - "asset": "1.3.0" + "base": { + "amount": 1, "asset_id": "1.3.2512" + }, + "quote": { + "amount": 250000, "asset_id": "1.3.0" + } } - ], + ]], "acceptable_borrowers": - [0, - { - "account": "1.2.1" - } - ], + [[ + "1.2.1",1000 + ]], "extensions": [], } ) From eb5a74254eba4b2df0691c2d35bcf10239756ec5 Mon Sep 17 00:00:00 2001 From: pi314x <51694688+pi314x@users.noreply.github.com> Date: Wed, 22 Nov 2023 07:53:12 +0100 Subject: [PATCH 4/9] Update test_transactions.py --- tests/test_transactions.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index c25491c..701839d 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1132,20 +1132,20 @@ def test_credit_offer_create(self): "auto_disable_time": 1000, "acceptable_collateral": [[ - "1.3.0", + "1.3.5589", { "base": { - "amount": 1, "asset_id": "1.3.2512" + "amount": 1, "asset_id": "1.3.0" }, "quote": { - "amount": 250000, "asset_id": "1.3.0" + "amount": 250000, "asset_id": "1.3.5589" } } ]], "acceptable_borrowers": - [[ - "1.2.1",1000 - ]], + [ + ["1.2.100", 1000] + ], "extensions": [], } ) @@ -1180,20 +1180,20 @@ def test_credit_offer_update(self): "auto_disable_time": False, "acceptable_collateral": [[ - "1.3.0", + "1.3.5589", { "base": { - "amount": 1, "asset_id": "1.3.2512" + "amount": 1, "asset_id": "1.3.0" }, "quote": { - "amount": 250000, "asset_id": "1.3.0" + "amount": 250000, "asset_id": "1.3.5589" } } ]], "acceptable_borrowers": - [[ - "1.2.1",1000 - ]], + [ + ["1.2.100", 1000] + ], "extensions": [], } ) From 1d9a063bfb5caee060c3f3de67cc7936a3cad67b Mon Sep 17 00:00:00 2001 From: pi314x <51694688+pi314x@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:43:26 +0100 Subject: [PATCH 5/9] Update test_transactions.py auto_disable_time --- tests/test_transactions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 701839d..978b67b 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1126,10 +1126,10 @@ def test_credit_offer_create(self): "asset_type": "1.3.0", "balance": 10000, "fee_rate": 1, - "max_duration_seconds": 10000, + "max_duration_seconds": 43200, "min_deal_amount": 1000, "enabled": False, - "auto_disable_time": 1000, + "auto_disable_time": "2024-01-01T00:00:00", "acceptable_collateral": [[ "1.3.5589", @@ -1177,7 +1177,7 @@ def test_credit_offer_update(self): "max_duration_seconds": 1000, "min_deal_amount": 10, "enabled": True, - "auto_disable_time": False, + "auto_disable_time": "2024-01-01T00:00:00", "acceptable_collateral": [[ "1.3.5589", From 00985e7e65af1602ce105178c3b1a589da9af0a7 Mon Sep 17 00:00:00 2001 From: litepresence Date: Fri, 16 Dec 2022 20:04:56 -0500 Subject: [PATCH 6/9] add samet fund and credit deal to operations.py --- bitsharesbase/operations.py | 290 ++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) diff --git a/bitsharesbase/operations.py b/bitsharesbase/operations.py index b437748..56dd55a 100644 --- a/bitsharesbase/operations.py +++ b/bitsharesbase/operations.py @@ -1226,4 +1226,294 @@ def __init__(self, *args, **kwargs): ) +class Samet_fund_create(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("owner_account", ObjectId(kwargs["owner_account"], "account")), + ("asset_type", ObjectId(kwargs["asset_type"], "asset")), + ("balance", Int64(kwargs["balance"])), + ("fee_rate", Uint32(kwargs["fee_rate"])), + ("extensions", Set([])), + ] + ) + ) + + +class Samet_fund_delete(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("owner_account", ObjectId(kwargs["owner_account"], "account")), + ("fund_id", ObjectId(kwargs["fund_id"], "samet_fund")), + ("extensions", Set([])), + ] + ) + ) + + +class Samet_fund_update(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("owner_account", ObjectId(kwargs["owner_account"], "account")), + ("fund_id", ObjectId(kwargs["fund_id"], "samet_fund")), + ("delta_amount", Optional(Asset(kwargs["delta_amount"]))), + ("new_fee_rate", Optional(Uint32(kwargs["new_fee_rate"]))), + ("extensions", Set([])), + ] + ) + ) + + +class Samet_fund_borrow(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("borrower", ObjectId(kwargs["borrower"], "account")), + ("fund_id", ObjectId(kwargs["fund_id"], "samet_fund")), + ("borrow_amount", Asset(kwargs["borrow_amount"])), + ("extensions", Set([])), + ] + ) + ) + + +class Samet_fund_repay(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("account", ObjectId(kwargs["account"], "account")), + ("fund_id", ObjectId(kwargs["fund_id"], "samet_fund")), + ("repay_amount", Asset(kwargs["repay_amount"])), + ("fund_fee", Asset(kwargs["fund_fee"])), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_offer_create(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("owner_account", ObjectId(kwargs["owner_account"], "account")), + ("asset_type", ObjectId(kwargs["asset_type"], "asset")), + ("balance", Int64(kwargs["balance"])), + ("fee_rate", Uint32(kwargs["fee_rate"])), + ( + "max_duration_seconds", + Uint32(kwargs["max_duration_seconds"]), + ), + ("min_deal_amount", Int64(kwargs["min_deal_amount"])), + ("enabled", Bool(kwargs["enabled"])(kwargs["enabled"])), + ("auto_disable_time", PointInTime(kwargs["auto_disable_time"])), + ( + "acceptable_collateral", + Map( + [ + [ObjectId(k[0], "asset"), Price(k[1])] + for k in kwargs["acceptable_collateral"] + ] + ), + ), + ( + "acceptable_borrowers", + Map( + [ + [ObjectId(k[0], "account"), Int64(k[1])] + for k in kwargs["acceptable_borrowers"] + ] + ), + ), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_offer_delete(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("owner_account", ObjectId(kwargs["owner_account"], "account")), + ("offer_id", ObjectId(kwargs["offer_id"], "credit_offer")), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_offer_update(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("owner_account", ObjectId(kwargs["owner_account"], "account")), + ("offer_id", ObjectId(kwargs["offer_id"], "credit_offer")), + ("delta_amount", Optional(Asset(kwargs["fee"]))), + ("fee_rate", Optional(Uint32(kwargs["fee_rate"]))), + ( + "max_duration_seconds", + Optional(Uint32(kwargs["max_duration_seconds"])), + ), + ("min_deal_amount", Optional(Int64(kwargs["min_deal_amount"]))), + ("enabled", Optional(Bool(kwargs["enabled"]))), + ( + "auto_disable_time", + Optional(PointInTime(kwargs["auto_disable_time"])), + ), + ( + "acceptable_collateral", + Optional( + Map( + [ + [ObjectId(k[0], "asset"), Price(k[1])] + for k in kwargs["acceptable_collateral"] + ] + ) + ), + ), + ( + "acceptable_borrowers", + Optional( + Map( + [ + [ObjectId(k[0], "account"), Int64(k[1])] + for k in kwargs["acceptable_borrowers"] + ] + ) + ), + ), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_offer_accept(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("borrower", ObjectId(kwargs["borrower"], "account")), + ("offer_id", ObjectId(kwargs["offer_id"], "credit_offer")), + ("borrow_amount", Asset(kwargs["fee"])), + ("collateral", Asset(kwargs["fee"])), + ("max_fee_rate", Uint32(kwargs["max_fee_rate"])), + ( + "min_duration_seconds", + Uint32(kwargs["min_duration_seconds"]), + ), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_deal_repay(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("account", ObjectId(kwargs["account"], "account")), + ("deal_id", ObjectId(kwargs["deal_id"], "credit_deal")), + ("repay_amount", Asset(kwargs["fee"])), + ("credit_fee", Asset(kwargs["fee"])), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_deal_expired(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("deal_id", ObjectId(kwargs["deal_id"], "credit_deal")), + ("offer_id", ObjectId(kwargs["offer_id"], "credit_offer")), + ("offer_owner", ObjectId(kwargs["offer_owner"], "account")), + ("borrower", ObjectId(kwargs["borrower"], "account")), + ("unpaid_amount", Asset(kwargs["fee"])), + ("collateral", Asset(kwargs["fee"])), + ("fee_rate", Uint32(kwargs["fee_rate"])), + ] + ) + ) + + fill_classmaps() From 20a41e90443f6c029d13f26c571f1113963342a1 Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Thu, 23 Nov 2023 20:43:39 +0100 Subject: [PATCH 7/9] fix: finish implementation testing of more operations --- bitsharesbase/objecttypes.py | 5 +- bitsharesbase/operationids.py | 14 ++++ bitsharesbase/operations.py | 18 ++++- tests/test_transactions.py | 147 ++++++++++++++++++++++------------ 4 files changed, 129 insertions(+), 55 deletions(-) diff --git a/bitsharesbase/objecttypes.py b/bitsharesbase/objecttypes.py index eadeedd..a271b49 100644 --- a/bitsharesbase/objecttypes.py +++ b/bitsharesbase/objecttypes.py @@ -21,4 +21,7 @@ object_type["custom_authority"] = 17 object_type["ticket"] = 18 object_type["liquidity_pool"] = 19 -object_type["OBJECT_TYPE_COUNT"] = 19 +object_type["samet_fund"] = 20 +object_type["credit_offer"] = 21 +object_type["credit_deal"] = 22 +object_type["OBJECT_TYPE_COUNT"] = 22 diff --git a/bitsharesbase/operationids.py b/bitsharesbase/operationids.py index 208ad16..0d72e80 100644 --- a/bitsharesbase/operationids.py +++ b/bitsharesbase/operationids.py @@ -65,6 +65,20 @@ "liquidity_pool_deposit", "liquidity_pool_withdraw", "liquidity_pool_exchange", + "samet_fund_create", + "samet_fund_delete", + "samet_fund_update", + "samet_fund_borrow", + "samet_fund_repay", + "credit_offer_create", + "credit_offer_delete", + "credit_offer_update", + "credit_offer_accept", + "credit_deal_repay", + "credit_deal_expired", + "liquidity_pool_update", + "credit_deal_update", + "limit_order_update", ] operations = {o: ops.index(o) for o in ops} diff --git a/bitsharesbase/operations.py b/bitsharesbase/operations.py index 56dd55a..8548536 100644 --- a/bitsharesbase/operations.py +++ b/bitsharesbase/operations.py @@ -54,6 +54,22 @@ class_namemap = {} +class VirtualOperationException(Exception): + pass + + +class ChainParameters(NotImplementedError): + pass + + +class CustomRestriction(NotImplementedError): + pass + + +class VestingPolicy(NotImplementedError): + pass + + def fill_classmaps(): for name, ind in operations.items(): classname = name[0:1].upper() + name[1:] @@ -1348,7 +1364,7 @@ def __init__(self, *args, **kwargs): Uint32(kwargs["max_duration_seconds"]), ), ("min_deal_amount", Int64(kwargs["min_deal_amount"])), - ("enabled", Bool(kwargs["enabled"])(kwargs["enabled"])), + ("enabled", Bool(kwargs["enabled"])), ("auto_disable_time", PointInTime(kwargs["auto_disable_time"])), ( "acceptable_collateral", diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 978b67b..46fb5ea 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1045,8 +1045,7 @@ def test_assert_b(self): ) self.doit(0) - - def test_samet_fund_create(self): + def test_samet_fund_create(self): self.op = operations.Samet_fund_create( **{ "fee": {"amount": 0, "asset_id": "1.3.0"}, @@ -1057,10 +1056,15 @@ def test_samet_fund_create(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c804570140000000000000000000b60200102700000000000001000000000001203431966ca7e7f40e921633cd767eece0ddefc5abb5224965cca6458dfa28572b687c459a2f4189bf1a41e13336fac6db10cc8c90215888948453b5063a8ccb9f') + self.cm = ( + "f68585abf4dce7c804570140000000000000000000b60200102" + "700000000000001000000000001203431966ca7e7f40e921633" + "cd767eece0ddefc5abb5224965cca6458dfa28572b687c459a2" + "f4189bf1a41e13336fac6db10cc8c90215888948453b5063a8c" + "cb9f" + ) self.doit() - def test_samet_fund_delete(self): self.op = operations.Samet_fund_delete( **{ @@ -1070,10 +1074,14 @@ def test_samet_fund_delete(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701410000000000000000007b010000011f4abefaf5a630eace47f6db44d6516c4e459e70cd89ba5988586d04be40646cf3723cf4b5979e5d094b819f94c37d19e4fac5a0aa20ba3ff8dab8d8482b5356d8') + self.cm = ( + "f68585abf4dce7c8045701410000000000000000007b0100000" + "11f4abefaf5a630eace47f6db44d6516c4e459e70cd89ba5988" + "586d04be40646cf3723cf4b5979e5d094b819f94c37d19e4fac" + "5a0aa20ba3ff8dab8d8482b5356d8" + ) self.doit() - def test_samet_fund_update(self): self.op = operations.Samet_fund_update( **{ @@ -1085,10 +1093,14 @@ def test_samet_fund_update(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701420000000000000000007b010001020000000000011f08656f260d4e4c6580202ab2520cad06cdc2539f03c3a74bcc3b6a8cdf2da5f84b252f09f15b77e825f5bb3fe7ff70a28d48516160653318beda6e156ba47987') + self.cm = ( + "f68585abf4dce7c8045701420000000000000000007b0100010" + "20000000000011f08656f260d4e4c6580202ab2520cad06cdc2" + "539f03c3a74bcc3b6a8cdf2da5f84b252f09f15b77e825f5bb3" + "fe7ff70a28d48516160653318beda6e156ba47987" + ) self.doit() - def test_samet_fund_borrow(self): self.op = operations.Samet_fund_borrow( **{ @@ -1099,10 +1111,14 @@ def test_samet_fund_borrow(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701430000000000000000007b010a00000000000000000000012007d969d65e15f9bb2c227fdd1baf74fbb0ce3e9ef197b386098188a78c5a1b992a1d7da0d39a91fb862536b53d719f02d88657cb21ae1c2ab55222d4814a893d') + self.cm = ( + "f68585abf4dce7c8045701430000000000000000007b010a000" + "00000000000000000012007d969d65e15f9bb2c227fdd1baf74" + "fbb0ce3e9ef197b386098188a78c5a1b992a1d7da0d39a91fb8" + "62536b53d719f02d88657cb21ae1c2ab55222d4814a893d" + ) self.doit() - def test_samet_fund_repay(self): self.op = operations.Samet_fund_repay( **{ @@ -1114,10 +1130,15 @@ def test_samet_fund_repay(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701440000000000000000007b010a00000000000000000a00000000000000000000011f573766a5dfe79df21d82df4a858a032d083e7b5db8f1d10cf6c0f48967965190607170df053d90fdf46f6fe1d10e160d292de03697136f91865588718a272e88') + self.cm = ( + "f68585abf4dce7c8045701440000000000000000007b010a000" + "00000000000000a00000000000000000000011f573766a5dfe7" + "9df21d82df4a858a032d083e7b5db8f1d10cf6c0f4896796519" + "0607170df053d90fdf46f6fe1d10e160d292de03697136f9186" + "5588718a272e88" + ) self.doit() - def test_credit_offer_create(self): self.op = operations.Credit_offer_create( **{ @@ -1130,29 +1151,30 @@ def test_credit_offer_create(self): "min_deal_amount": 1000, "enabled": False, "auto_disable_time": "2024-01-01T00:00:00", - "acceptable_collateral": - [[ - "1.3.5589", - { - "base": { - "amount": 1, "asset_id": "1.3.0" + "acceptable_collateral": [ + [ + "1.3.5589", + { + "base": {"amount": 1, "asset_id": "1.3.0"}, + "quote": {"amount": 250000, "asset_id": "1.3.5589"}, }, - "quote": { - "amount": 250000, "asset_id": "1.3.5589" - } - } - ]], - "acceptable_borrowers": - [ - ["1.2.100", 1000] + ] ], + "acceptable_borrowers": [["1.2.100", 1000]], "extensions": [], } ) - self.cm = () + self.cm = ( + "f68585abf4dce7c8045701450000000000000000007b001027" + "00000000000001000000c0a80000e803000000000000008000" + "926501d52b01000000000000000090d0030000000000d52b01" + "64e80300000000000000000120107ea7f48037771b8243c5c9" + "a83ac3534128dbd1c47c4cf8bf8108e9a1bacede2d4e5f4254" + "2d298ece03008c3d5be75716338165e9adc8c1ebc245d70429" + "6df3" + ) self.doit(1) - def test_credit_offer_delete(self): self.op = operations.Credit_offer_delete( **{ @@ -1162,10 +1184,14 @@ def test_credit_offer_delete(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701460000000000000000007b010000012042aed7548e971617836c55d55c57b5ecd15e2ef8ed1cdf56c380891ce10e2aaa743e3665de606a7833145a1a2dbe5b60870396972e9e5c803040ee4cec8a8772') + self.cm = ( + "f68585abf4dce7c8045701460000000000000000007b0100000" + "12042aed7548e971617836c55d55c57b5ecd15e2ef8ed1cdf56" + "c380891ce10e2aaa743e3665de606a7833145a1a2dbe5b60870" + "396972e9e5c803040ee4cec8a8772" + ) self.doit() - def test_credit_offer_update(self): self.op = operations.Credit_offer_update( **{ @@ -1178,29 +1204,30 @@ def test_credit_offer_update(self): "min_deal_amount": 10, "enabled": True, "auto_disable_time": "2024-01-01T00:00:00", - "acceptable_collateral": - [[ - "1.3.5589", - { - "base": { - "amount": 1, "asset_id": "1.3.0" + "acceptable_collateral": [ + [ + "1.3.5589", + { + "base": {"amount": 1, "asset_id": "1.3.0"}, + "quote": {"amount": 250000, "asset_id": "1.3.5589"}, }, - "quote": { - "amount": 250000, "asset_id": "1.3.5589" - } - } - ]], - "acceptable_borrowers": - [ - ["1.2.100", 1000] + ] ], + "acceptable_borrowers": [["1.2.100", 1000]], "extensions": [], } ) - self.cm = () + self.cm = ( + "f68585abf4dce7c8045701470000000000000000007b010100" + "0000000000000000010100000001e8030000010a0000000000" + "0000010101800092650101d52b01000000000000000090d003" + "0000000000d52b010164e8030000000000000000012064575b" + "5fd2347411a643c54a2aaf2550c0c5653334ec81ca28a1e68f" + "fd7e7fd07748121135e01947ae317e3b7ae9263149b96e9630" + "1b16571984b94f7c72ebd9" + ) self.doit(1) - def test_credit_offer_accept(self): self.op = operations.Credit_offer_accept( **{ @@ -1214,10 +1241,15 @@ def test_credit_offer_accept(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701480000000000000000007b0100000000000000000000000000000000000001000000e8030000000001201dda600d9efc172ee7e0ca6a2b1279709184d0bb0960afd93b49f60f8d90caed6b0f84de19ee54d7434ee11ec0af1f45415f4b024adbf0ca59a9e167eab3901b') + self.cm = ( + "f68585abf4dce7c8045701480000000000000000007b0100000" + "000000000000000000000000000000001000000e80300000000" + "01201dda600d9efc172ee7e0ca6a2b1279709184d0bb0960afd" + "93b49f60f8d90caed6b0f84de19ee54d7434ee11ec0af1f4541" + "5f4b024adbf0ca59a9e167eab3901b" + ) self.doit() - def test_credit_deal_repay(self): self.op = operations.Credit_deal_repay( **{ @@ -1229,10 +1261,15 @@ def test_credit_deal_repay(self): "extensions": [], } ) - self.cm = ('f68585abf4dce7c8045701490000000000000000007bb412000000000000000000000000000000000000000001203ba717f69b6ed214ef1a105bda7756149cee25c0c92c48a7f2d59dee88997cec3f9254df2bd2476cf2df16b10ebca0937f8daf2eecccfb8848e4faed9b8c0df7') + self.cm = ( + "f68585abf4dce7c8045701490000000000000000007bb412000" + "000000000000000000000000000000000000001203ba717f69b" + "6ed214ef1a105bda7756149cee25c0c92c48a7f2d59dee88997" + "cec3f9254df2bd2476cf2df16b10ebca0937f8daf2eecccfb88" + "48e4faed9b8c0df7" + ) self.doit() - def test_credit_deal_expired(self): self.op = operations.Credit_deal_expired( **{ @@ -1246,10 +1283,15 @@ def test_credit_deal_expired(self): "fee_rate": 1, } ) - self.cm = ('f68585abf4dce7c80457014a000000000000000000b412017b7b000000000000000000000000000000000000010000000001207e5770f0fae74fc78bebbe5267583a824999d6356698ebce0a25e4a468bd3e356ca10920e3c4301537bd02205e63617546a5d8eded230655d170529801838a3f') + self.cm = ( + "f68585abf4dce7c80457014a000000000000000000b412017b7" + "b00000000000000000000000000000000000001000000000120" + "7e5770f0fae74fc78bebbe5267583a824999d6356698ebce0a2" + "5e4a468bd3e356ca10920e3c4301537bd02205e63617546a5d8" + "eded230655d170529801838a3f" + ) self.doit() - def compareConstructedTX(self): self.maxDiff = None self.op = operations.Call_order_update( @@ -1282,4 +1324,3 @@ def compareConstructedTX(self): print("ist: %s" % txWire[:-130]) print(txWire[:-130] == self.cm[:-130]) self.assertEqual(self.cm[:-130], txWire[:-130]) - From a651abe594d13f14f488b014c0893ef8c8aad25b Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Thu, 23 Nov 2023 21:19:03 +0100 Subject: [PATCH 8/9] bump: requires graphene 1.6.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c8aa88d..93adabf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -graphenelib>=1.5.0,<2.0.0 +graphenelib>=1.6.1,<2.0.0 Events==0.3 From e640dc35ffe86f04aee763cfe2891a7acaf29386 Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Thu, 23 Nov 2023 22:21:09 +0100 Subject: [PATCH 9/9] fix: proper way of dealing with Optional --- bitsharesbase/operations.py | 102 +++++++++++++++++++++++------------- tests/test_transactions.py | 10 ++-- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/bitsharesbase/operations.py b/bitsharesbase/operations.py index f18552d..89a62dd 100644 --- a/bitsharesbase/operations.py +++ b/bitsharesbase/operations.py @@ -1278,14 +1278,22 @@ def __init__(self, *args, **kwargs): else: if len(args) == 1 and len(kwargs) == 0: kwargs = args[0] + if "new_fee_rate" in kwargs: + new_fee_rate = Optional(Uint32(kwargs["new_fee_rate"])) + else: + new_fee_rate = Optional(None) + if "delta_amount" in kwargs: + delta_amount = Optional(Asset(kwargs["delta_amount"])) + else: + delta_amount = Optional(None) super().__init__( OrderedDict( [ ("fee", Asset(kwargs["fee"])), ("owner_account", ObjectId(kwargs["owner_account"], "account")), ("fund_id", ObjectId(kwargs["fund_id"], "samet_fund")), - ("delta_amount", Optional(Asset(kwargs["delta_amount"]))), - ("new_fee_rate", Optional(Uint32(kwargs["new_fee_rate"]))), + ("delta_amount", delta_amount), + ("new_fee_rate", new_fee_rate), ("extensions", Set([])), ] ) @@ -1405,46 +1413,68 @@ def __init__(self, *args, **kwargs): else: if len(args) == 1 and len(kwargs) == 0: kwargs = args[0] + if kwargs.get("min_deal_amount"): + min_deal_amount = Optional(Int64(kwargs["min_deal_amount"])) + else: + min_deal_amount = Optional(None) + if kwargs.get("enabled"): + enabled = Optional(Bool(kwargs["enabled"])) + else: + enabled = Optional(None) + if kwargs.get("auto_disable_time"): + auto_disable_time = Optional(PointInTime(kwargs["auto_disable_time"])) + else: + auto_disable_time = Optional(None) + if kwargs.get("acceptable_collateral"): + acceptable_collateral = Optional( + Map( + [ + [ObjectId(k[0], "asset"), Price(k[1])] + for k in kwargs["acceptable_collateral"] + ] + ) + ) + else: + acceptable_collateral = Optional(None) + if kwargs.get("acceptable_borrowers"): + acceptable_borrowers = Optional( + Map( + [ + [ObjectId(k[0], "account"), Int64(k[1])] + for k in kwargs["acceptable_borrowers"] + ] + ) + ) + else: + acceptable_borrowers = Optional(None) + if kwargs.get("max_duration_seconds"): + max_duration_seconds = Optional( + Uint32(kwargs.get("max_duration_seconds")) + ) + else: + max_duration_seconds = Optional(None) + if kwargs.get("fee_rate"): + fee_rate = Optional(Uint32(kwargs.get("fee_rate"))) + else: + fee_rate = Optional(None) + if kwargs.get("delta_amount"): + delta_amount = Optional(Asset(kwargs.get("delta_amount"))) + else: + delta_amount = Optional(None) super().__init__( OrderedDict( [ ("fee", Asset(kwargs["fee"])), ("owner_account", ObjectId(kwargs["owner_account"], "account")), ("offer_id", ObjectId(kwargs["offer_id"], "credit_offer")), - ("delta_amount", Optional(Asset(kwargs["fee"]))), - ("fee_rate", Optional(Uint32(kwargs["fee_rate"]))), - ( - "max_duration_seconds", - Optional(Uint32(kwargs["max_duration_seconds"])), - ), - ("min_deal_amount", Optional(Int64(kwargs["min_deal_amount"]))), - ("enabled", Optional(Bool(kwargs["enabled"]))), - ( - "auto_disable_time", - Optional(PointInTime(kwargs["auto_disable_time"])), - ), - ( - "acceptable_collateral", - Optional( - Map( - [ - [ObjectId(k[0], "asset"), Price(k[1])] - for k in kwargs["acceptable_collateral"] - ] - ) - ), - ), - ( - "acceptable_borrowers", - Optional( - Map( - [ - [ObjectId(k[0], "account"), Int64(k[1])] - for k in kwargs["acceptable_borrowers"] - ] - ) - ), - ), + ("delta_amount", delta_amount), + ("fee_rate", fee_rate), + ("max_duration_seconds", max_duration_seconds), + ("min_deal_amount", min_deal_amount), + ("enabled", enabled), + ("auto_disable_time", auto_disable_time), + ("acceptable_collateral", acceptable_collateral), + ("acceptable_borrowers", acceptable_borrowers), ("extensions", Set([])), ] ) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 6820f93..028ec4f 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -1232,13 +1232,13 @@ def test_credit_offer_update(self): } ) self.cm = ( - "f68585abf4dce7c8045701470000000000000000007b010100" + "f68585abf4dce7c8045701470000000000000000007b010101" "0000000000000000010100000001e8030000010a0000000000" "0000010101800092650101d52b01000000000000000090d003" - "0000000000d52b010164e8030000000000000000012064575b" - "5fd2347411a643c54a2aaf2550c0c5653334ec81ca28a1e68f" - "fd7e7fd07748121135e01947ae317e3b7ae9263149b96e9630" - "1b16571984b94f7c72ebd9" + "0000000000d52b010164e8030000000000000000011f08187d" + "ea87e4306cb8e6fc9ddeeb38053499a86f5c01d8bfa8b72257" + "564bd3250bd4868d5db692077526b901a019cb8e2049e5daf7" + "95a7ba17e6122fdb0fb20a" ) self.doit(1)