Skip to content

Commit db98c22

Browse files
committed
fix(tests): add tests for limit_order_update and others, add extension to limit_order_create
1 parent 424f222 commit db98c22

File tree

3 files changed

+143
-11
lines changed

3 files changed

+143
-11
lines changed

bitsharesbase/objects.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ def __init__(self, *args, **kwargs):
469469
("fee_asset_id", ObjectId(kwargs["fee_asset_id"], "asset")),
470470
("spread_percent", Uint16(kwargs["spread_percent"])),
471471
("size_percent", Uint16(kwargs["size_percent"])),
472-
("expiration_seconds", Uint32(kwargs["expiration_seconds"])),
472+
(
473+
"expiration_seconds",
474+
Uint32(kwargs["expiration_seconds"]),
475+
),
473476
("repeat", Bool(kwargs["repeat"])),
474477
("extensions", Set([])),
475478
]
@@ -482,3 +485,15 @@ def __init__(self, *args, **kwargs):
482485
else:
483486
raise ValueError("Unknown {}".format(self.__class__.__name__))
484487
super().__init__(data, id)
488+
489+
490+
class LimitOrderCreateExtensions(Extension):
491+
def NestedLimitOrderAutoAction(value):
492+
if value:
493+
return Array([LimitOrderAutoAction(o) for o in value])
494+
else:
495+
return None
496+
497+
sorted_options = [
498+
("on_fill", NestedLimitOrderAutoAction),
499+
]

bitsharesbase/operations.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
isArgsThisClass,
4747
AssertPredicate,
4848
LimitOrderAutoAction,
49+
LimitOrderCreateExtensions,
4950
)
5051
from .operationids import operations
5152

@@ -387,7 +388,10 @@ def __init__(self, *args, **kwargs):
387388
("min_to_receive", Asset(kwargs["min_to_receive"])),
388389
("expiration", PointInTime(kwargs["expiration"])),
389390
("fill_or_kill", Bool(kwargs["fill_or_kill"])),
390-
("extensions", Set([])),
391+
(
392+
"extensions",
393+
LimitOrderCreateExtensions(kwargs["extensions"]),
394+
),
391395
]
392396
)
393397
)
@@ -1226,6 +1230,7 @@ def __init__(self, *args, **kwargs):
12261230
)
12271231
)
12281232

1233+
12291234
class Liquidity_pool_update(GrapheneObject):
12301235
def __init__(self, *args, **kwargs):
12311236
if isArgsThisClass(self, args):
@@ -1240,7 +1245,9 @@ def __init__(self, *args, **kwargs):
12401245
taker_fee_percent = Optional(None)
12411246

12421247
if kwargs.get("withdrawal_fee_percent"):
1243-
withdrawal_fee_percent = Optional(Uint16(kwargs["withdrawal_fee_percent"]))
1248+
withdrawal_fee_percent = Optional(
1249+
Uint16(kwargs["withdrawal_fee_percent"])
1250+
)
12441251
else:
12451252
withdrawal_fee_percent = Optional(None)
12461253

@@ -1257,6 +1264,7 @@ def __init__(self, *args, **kwargs):
12571264
)
12581265
)
12591266

1267+
12601268
class Credit_deal_update(GrapheneObject):
12611269
def __init__(self, *args, **kwargs):
12621270
if isArgsThisClass(self, args):
@@ -1275,7 +1283,8 @@ def __init__(self, *args, **kwargs):
12751283
]
12761284
)
12771285
)
1278-
1286+
1287+
12791288
class Limit_order_update(GrapheneObject):
12801289
def __init__(self, *args, **kwargs):
12811290
if isArgsThisClass(self, args):
@@ -1300,7 +1309,9 @@ def __init__(self, *args, **kwargs):
13001309
new_expiration = Optional(None)
13011310

13021311
if kwargs.get("on_fill"):
1303-
on_fill = Optional(Array([LimitOrderAutoAction(o) for o in kwargs["on_fill"]]))
1312+
on_fill = Optional(
1313+
Array([LimitOrderAutoAction(o) for o in kwargs["on_fill"]])
1314+
)
13041315
else:
13051316
on_fill = Optional(None)
13061317

@@ -1319,4 +1330,5 @@ def __init__(self, *args, **kwargs):
13191330
)
13201331
)
13211332

1333+
13221334
fill_classmaps()

tests/test_transactions.py

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,29 @@ def test_limit_order_create(self):
8383
"min_to_receive": {"amount": 10000, "asset_id": "1.3.105"},
8484
"expiration": "2016-05-18T09:22:05",
8585
"fill_or_kill": False,
86-
"extensions": [],
86+
"extensions": {
87+
"on_fill": [
88+
[
89+
0,
90+
{
91+
"fee_asset_id": "1.3.0",
92+
"spread_percent": 100,
93+
"size_percent": 1000,
94+
"expiration_seconds": 3600,
95+
"repeat": True,
96+
"extensions": [],
97+
},
98+
]
99+
]
100+
},
87101
}
88102
)
89103
self.cm = (
90-
"f68585abf4dce7c8045701016400000000000000001da08601000"
91-
"0000000001027000000000000693d343c57000000011f75cbfd49"
92-
"ae8d9b04af76cc0a7de8b6e30b71167db7fe8e2197ef9d858df18"
93-
"77043493bc24ffdaaffe592357831c978fd8a296b913979f106de"
94-
"be940d60d77b50"
104+
"f68585abf4dce7c8045701016400000000000000001da0860100000"
105+
"00000001027000000000000693d343c570001000100006400e80310"
106+
"0e0000010000011f5ddffd232fd713e106aec3068646f5a74ae145e"
107+
"08e1e13f7464885a507e808e365594f5e7c14049d9432bcf1ca2330"
108+
"a65d1b7ab88aa08b355970ca6f23e06aa0"
95109
)
96110
self.doit()
97111

@@ -1045,6 +1059,97 @@ def test_assert_b(self):
10451059
)
10461060
self.doit(0)
10471061

1062+
def test_limit_order_update(self):
1063+
self.op = operations.Limit_order_update(
1064+
**{
1065+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1066+
"seller": "1.2.4",
1067+
"order": "1.7.12535",
1068+
"extensions": [],
1069+
}
1070+
)
1071+
self.cm = (
1072+
"f68585abf4dce7c80457014d00000000000000000004f76100"
1073+
"0000000000011f06d0b4467a5916ffb3d8ef4261c0719b1fb0"
1074+
"964aa5d3fbecbfbcbc9fe1117bc20e8a2c3f87e7817b83446c"
1075+
"45deb2a0d3d5b8b0d3b22fc8076ffc8eeb1a95e928"
1076+
)
1077+
self.doit(0)
1078+
1079+
self.op = operations.Limit_order_update(
1080+
**{
1081+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1082+
"seller": "1.2.4",
1083+
"order": "1.7.12535",
1084+
"new_price": {
1085+
"base": {"amount": 1123456, "asset_id": "1.3.0"},
1086+
"quote": {"amount": 78901122, "asset_id": "1.3.0"},
1087+
},
1088+
"delta_amount_to_sell": {"amount": 12562, "asset_id": "1.3.0"},
1089+
"new_expiration": "2023-12-18T09:22:05",
1090+
"on_fill": [
1091+
[
1092+
0,
1093+
{
1094+
"fee_asset_id": "1.3.0",
1095+
"spread_percent": 100,
1096+
"size_percent": 1000,
1097+
"expiration_seconds": 3600,
1098+
"repeat": True,
1099+
"extensions": [],
1100+
},
1101+
]
1102+
],
1103+
"extensions": [],
1104+
}
1105+
)
1106+
self.cm = (
1107+
"f68585abf4dce7c80457014d00000000000000000004f76101"
1108+
"80241100000000000082efb304000000000001123100000000"
1109+
"000000013d0f8065010100006400e803100e00000100000001"
1110+
"2051a24fb550e4a8ec890ad404ea0e3cf6ea449d6ba397d280"
1111+
"64f7129153dd013e27846eb6567a88d8eea7557f32ddc02cdc"
1112+
"a614c5a30130c83141c4050ffc50e2"
1113+
)
1114+
self.doit()
1115+
1116+
def test_liquidity_pool_update(self):
1117+
self.op = operations.Liquidity_pool_update(
1118+
**{
1119+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1120+
"account": "1.2.4",
1121+
"pool": "1.19.13356",
1122+
"taker_fee_percent": 124,
1123+
"withdrawal_fee_percent": 125,
1124+
"extensions": [],
1125+
}
1126+
)
1127+
self.cm = (
1128+
"f68585abf4dce7c80457014b00000000000000000004ac6801"
1129+
"7c00017d00000001202e3f140515ce936020348f845a4c034b"
1130+
"164441049dfe0a59a6c0fe27cbef740c10fa0d315e14e77e62"
1131+
"d8dae4f45d95fef358ff79f5304a420d6fc13abfd9374b"
1132+
)
1133+
self.doit(0)
1134+
1135+
def test_credit_deal_update(self):
1136+
self.op = operations.Credit_deal_update(
1137+
**{
1138+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1139+
"account": "1.2.4",
1140+
"deal_id": "1.22.2356",
1141+
"auto_repay": 24,
1142+
"extensions": [],
1143+
}
1144+
)
1145+
self.cm = (
1146+
"f68585abf4dce7c80457014c00000000000000000004b41218"
1147+
"0000012026b59b7796cb9ca40d92b1d339558a94aa9f70d2f6"
1148+
"d8a7b8b0155c943b89bd602a1ecc9df3143664f801f401a728"
1149+
"78cce9f064dbcfc1af65826ce68a2177a38d"
1150+
)
1151+
self.doit()
1152+
10481153
def compareConstructedTX(self):
10491154
self.maxDiff = None
10501155
self.op = operations.Call_order_update(

0 commit comments

Comments
 (0)