Skip to content

Commit 3d7d261

Browse files
Fix parsing parameter with an optional value (#201)
1 parent ccd3ea4 commit 3d7d261

File tree

9 files changed

+149
-5
lines changed

9 files changed

+149
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Please use [this](https://docs.gitlab.com/ee/development/changelog.html) document as guidelines to keep a changelog.
44

5+
## [unreleased]
6+
7+
### Fixed
8+
9+
* tzkt: Fixed parsing parameter with an optional value.
10+
511
## 4.0.2 - 2022-01-06
612

713
### Added
@@ -12,7 +18,7 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
1218

1319
* tzkt: Fixed crash due to unprocessed pysignalr exception.
1420
* tzkt: Fixed parsing `OperationData.amount` field.
15-
* tzkt: Fixed parsing storage with top-level boolean fields
21+
* tzkt: Fixed parsing storage with top-level boolean fields.
1622

1723
## 4.0.1 - 2021-12-30
1824

scripts/init_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#$/bin/bash
22
cd tests/test_dipdup
3-
for name in "asdf" "qwer" "hjkl" "zxcv" "rewq" "hen_subjkt"
3+
for name in "asdf" "qwer" "hjkl" "zxcv" "rewq" "hen_subjkt" "kolibri_ovens"
44
do
55
dipdup -c $name.yml init
66
mkdir -p types/$name/
77
mv $name/types/$name/storage.py types/$name/storage.py
8+
mv $name/types/$name/parameter/set_delegate.py types/$name/set_delegate.py || true
89
rm -r $name
910
done

src/dipdup/datasources/tzkt/datasource.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,10 @@ def convert_operation(cls, operation_json: Dict[str, Any], type_: Optional[str]
703703
# NOTE: TzKT returns None for `default` entrypoint
704704
if entrypoint is None:
705705
entrypoint = 'default'
706-
# NOTE: Empty parameter in this case means `{"prim": "Unit"}`
707-
if parameter is None:
708-
parameter = {}
706+
707+
# NOTE: Empty parameter in this case means `{"prim": "Unit"}`
708+
if parameter is None:
709+
parameter = {}
709710

710711
return OperationData(
711712
type=type_ or operation_json['type'],
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[
2+
{
3+
"type": "transaction",
4+
"id": 44936407,
5+
"level": 1416383,
6+
"timestamp": "2021-04-05T22:44:41Z",
7+
"block": "BLgbUHkPeeegP2jxEYBkY1Zf6erXmWckBNBK7kuZePUdQHSvFp9",
8+
"hash": "oos6a4U5DhAEaSLqxLmuiytwpP6VZTwESWxosWRzAy6e5emhm8r",
9+
"counter": 12504503,
10+
"sender": {
11+
"address": "tz1aD4DmnnGyqxL7neCZ5JMQ6UnpcrKCpajE"
12+
},
13+
"gasLimit": 15600,
14+
"gasUsed": 14500,
15+
"storageLimit": 0,
16+
"storageUsed": 0,
17+
"bakerFee": 1868,
18+
"storageFee": 0,
19+
"allocationFee": 0,
20+
"target": {
21+
"address": "KT1TdV4PMVk2ssQhEw8ch4PNnnVv11JqAzn7"
22+
},
23+
"amount": 0,
24+
"parameter": {
25+
"entrypoint": "setDelegate",
26+
"value": null
27+
},
28+
"storage": {
29+
"owner": "tz1aD4DmnnGyqxL7neCZ5JMQ6UnpcrKCpajE",
30+
"isLiquidated": false,
31+
"interestIndex": "1012163739772748415",
32+
"borrowedTokens": "250000000000000000000",
33+
"stabilityFeeTokens": "0",
34+
"ovenProxyContractAddress": "KT1JdufSdfg3WyxWJcCRNsBFV9V3x9TQBkJ2"
35+
},
36+
"status": "applied",
37+
"hasInternals": true,
38+
"parameters": "{\"entrypoint\":\"setDelegate\",\"value\":{\"prim\":\"None\"}}"
39+
},
40+
{
41+
"type": "delegation",
42+
"id": 44936408,
43+
"level": 1416383,
44+
"timestamp": "2021-04-05T22:44:41Z",
45+
"block": "BLgbUHkPeeegP2jxEYBkY1Zf6erXmWckBNBK7kuZePUdQHSvFp9",
46+
"hash": "oos6a4U5DhAEaSLqxLmuiytwpP6VZTwESWxosWRzAy6e5emhm8r",
47+
"counter": 12504503,
48+
"initiator": {
49+
"address": "tz1aD4DmnnGyqxL7neCZ5JMQ6UnpcrKCpajE"
50+
},
51+
"sender": {
52+
"address": "KT1TdV4PMVk2ssQhEw8ch4PNnnVv11JqAzn7"
53+
},
54+
"nonce": 12,
55+
"gasLimit": 0,
56+
"gasUsed": 1000,
57+
"bakerFee": 0,
58+
"amount": 100000000,
59+
"prevDelegate": {
60+
"alias": "Tessellated Geometry",
61+
"address": "tz1abmz7jiCV2GH2u81LRrGgAFFgvQgiDiaf"
62+
},
63+
"status": "applied"
64+
}
65+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
spec_version: 1.2
2+
package: kolibri_ovens
3+
4+
contracts:
5+
kolibri_ovens:
6+
address: KT1KV31DTzktr8t7edCLUzzgEN54cQtksJou
7+
typename: kolibri_ovens
8+
9+
datasources:
10+
tzkt:
11+
kind: tzkt
12+
url: https://api.tzkt.io
13+
14+
indexes:
15+
kolibri_ovens:
16+
kind: operation
17+
datasource: tzkt
18+
contracts:
19+
- kolibri_ovens
20+
handlers:
21+
- callback: on_set_delegate
22+
pattern:
23+
- destination: kolibri_ovens
24+
entrypoint: setDelegate

tests/test_dipdup/test_models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from tests.test_dipdup.types.ftzfun.storage import FtzFunStorage
1919
from tests.test_dipdup.types.hen_subjkt.storage import HenSubjktStorage
2020
from tests.test_dipdup.types.hjkl.storage import HjklStorage
21+
from tests.test_dipdup.types.kolibri_ovens.set_delegate import SetDelegateParameter
22+
from tests.test_dipdup.types.kolibri_ovens.storage import KolibriOvensStorage
2123
from tests.test_dipdup.types.listofmaps.storage import ListOfMapsStorage
2224
from tests.test_dipdup.types.qwer.storage import QwerStorage
2325
from tests.test_dipdup.types.rewq.storage import RewqStorage
@@ -334,3 +336,17 @@ def test_hen_subjkt(self) -> None:
334336
self.assertIsInstance(storage_obj, HenSubjktStorage)
335337
self.assertIsInstance(storage_obj.entries, dict)
336338
self.assertEqual(storage_obj.entries['tz1Y1j7FK1X9Rrv2VdPz5bXoU7SszF8W1RnK'], True) # type: ignore
339+
340+
def test_kolibri_ovens(self) -> None:
341+
with open(join(dirname(__file__), 'kolibri_ovens.json')) as f:
342+
operations_json = json.load(f)
343+
344+
# Act
345+
operations = [TzktDatasource.convert_operation(op) for op in operations_json]
346+
storage_obj = deserialize_storage(operations[0], KolibriOvensStorage)
347+
parameter_obj = SetDelegateParameter.parse_obj(operations[0].parameter_json)
348+
349+
# Assert
350+
self.assertIsInstance(storage_obj, KolibriOvensStorage)
351+
self.assertIsInstance(parameter_obj, SetDelegateParameter)
352+
self.assertEqual(parameter_obj.__root__, None)

tests/test_dipdup/types/kolibri_ovens/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# generated by datamodel-codegen:
2+
# filename: setDelegate.json
3+
4+
from __future__ import annotations
5+
6+
from typing import Optional
7+
8+
from pydantic import BaseModel
9+
10+
11+
class SetDelegateParameter(BaseModel):
12+
__root__: Optional[str]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# generated by datamodel-codegen:
2+
# filename: storage.json
3+
4+
from __future__ import annotations
5+
6+
from pydantic import BaseModel
7+
from pydantic import Extra
8+
9+
10+
class KolibriOvensStorage(BaseModel):
11+
class Config:
12+
extra = Extra.forbid
13+
14+
borrowedTokens: str
15+
interestIndex: str
16+
isLiquidated: bool
17+
ovenProxyContractAddress: str
18+
owner: str
19+
stabilityFeeTokens: str

0 commit comments

Comments
 (0)