Skip to content

Commit

Permalink
fix: finish implementation testing of more operations
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Nov 23, 2023
1 parent a8c3d60 commit c71fe90
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 55 deletions.
5 changes: 4 additions & 1 deletion bitsharesbase/objecttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions bitsharesbase/operationids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
18 changes: 17 additions & 1 deletion bitsharesbase/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down Expand Up @@ -1746,7 +1762,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",
Expand Down
147 changes: 94 additions & 53 deletions tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
**{
Expand All @@ -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(
Expand Down Expand Up @@ -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])

0 comments on commit c71fe90

Please sign in to comment.