Skip to content

Commit 8a24ad1

Browse files
Fixed parsing storage with top-level boolean fields (#199)
* Fix booleans in storage * Fix parsing storage with top-level boolean fields
1 parent 83fa816 commit 8a24ad1

File tree

8 files changed

+160
-3
lines changed

8 files changed

+160
-3
lines changed

CHANGELOG.md

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

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

5-
## [unreleased]
5+
## 4.0.2 - 2022-01-06
66

77
### Added
88

@@ -12,6 +12,7 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
1212

1313
* tzkt: Fixed crash due to unprocessed pysignalr exception.
1414
* tzkt: Fixed parsing `OperationData.amount` field.
15+
* tzkt: Fixed parsing storage with top-level boolean fields
1516

1617
## 4.0.1 - 2021-12-30
1718

scripts/init_tests.sh

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

src/dipdup/datasources/tzkt/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _process_storage(
131131
) -> Any:
132132
"""Replace bigmap pointers with actual data from diffs"""
133133
# NOTE: Bigmap pointer, apply diffs
134-
if isinstance(storage, int) and storage_type not in (int, bool):
134+
if isinstance(storage, int) and type(storage) != storage_type:
135135
is_array = _is_array(storage_type)
136136
storage = _apply_bigmap_diffs(storage, bigmap_diffs, is_array)
137137

tests/test_dipdup/hen_subjkt.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
[
2+
{
3+
"type": "transaction",
4+
"id": 51691121,
5+
"level": 1486393,
6+
"timestamp": "2021-05-25T05:49:38Z",
7+
"block": "BL8BSn2wNkGHtrW5h91evEymnGe1f1ZLcXdcP1aoL37Pdx25VC4",
8+
"hash": "ooCJ3MT8azAG6YtGc3iTTsVb13f97utnF4aGbPmeRRRDtBUBxib",
9+
"counter": 11788253,
10+
"sender": {
11+
"address": "tz1Y1j7FK1X9Rrv2VdPz5bXoU7SszF8W1RnK"
12+
},
13+
"gasLimit": 12272,
14+
"gasUsed": 12172,
15+
"storageLimit": 340,
16+
"storageUsed": 340,
17+
"bakerFee": 1608,
18+
"storageFee": 85000,
19+
"allocationFee": 0,
20+
"target": {
21+
"alias": "Hic et Nunc Name Registry",
22+
"address": "KT1My1wDZHDGweCrJnQJi3wcFaS67iksirvj"
23+
},
24+
"amount": 0,
25+
"parameter": {
26+
"entrypoint": "registry",
27+
"value": {
28+
"subjkt": "697066733a2f2f516d61785435644c41586d4e61456271334d39545971384a5070383445313136785775364b43786f5933356b5051",
29+
"metadata": "63727a797061746368776f726b"
30+
}
31+
},
32+
"storage": {
33+
"entries": 3916,
34+
"manager": "tz1Y1j7FK1X9Rrv2VdPz5bXoU7SszF8W1RnK",
35+
"subjkts": 3920,
36+
"invoices": 3917,
37+
"metadata": 3918,
38+
"registries": 3919,
39+
"subjkts_metadata": 3921
40+
},
41+
"diffs": [
42+
{
43+
"bigmap": 3921,
44+
"path": "subjkts_metadata",
45+
"action": "add_key",
46+
"content": {
47+
"hash": "exprvG7n7nqTvEWSAqYs7xtDA1sspVwkNXNckjycav3iCqEGK3551Y",
48+
"key": "697066733a2f2f516d61785435644c41586d4e61456271334d39545971384a5070383445313136785775364b43786f5933356b5051",
49+
"value": "63727a797061746368776f726b"
50+
}
51+
},
52+
{
53+
"bigmap": 3920,
54+
"path": "subjkts",
55+
"action": "add_key",
56+
"content": {
57+
"hash": "exprvG7n7nqTvEWSAqYs7xtDA1sspVwkNXNckjycav3iCqEGK3551Y",
58+
"key": "697066733a2f2f516d61785435644c41586d4e61456271334d39545971384a5070383445313136785775364b43786f5933356b5051",
59+
"value": true
60+
}
61+
},
62+
{
63+
"bigmap": 3919,
64+
"path": "registries",
65+
"action": "add_key",
66+
"content": {
67+
"hash": "exprtjfsLWoz5kkutCAtoRAHr4L9pD41UCmrdi77Lh6h3Msg55Ueuj",
68+
"key": "tz1Y1j7FK1X9Rrv2VdPz5bXoU7SszF8W1RnK",
69+
"value": "697066733a2f2f516d61785435644c41586d4e61456271334d39545971384a5070383445313136785775364b43786f5933356b5051"
70+
}
71+
},
72+
{
73+
"bigmap": 3916,
74+
"path": "entries",
75+
"action": "add_key",
76+
"content": {
77+
"hash": "exprtjfsLWoz5kkutCAtoRAHr4L9pD41UCmrdi77Lh6h3Msg55Ueuj",
78+
"key": "tz1Y1j7FK1X9Rrv2VdPz5bXoU7SszF8W1RnK",
79+
"value": true
80+
}
81+
}
82+
],
83+
"status": "applied",
84+
"hasInternals": false,
85+
"parameters": "{\"entrypoint\":\"registry\",\"value\":{\"prim\":\"Pair\",\"args\":[{\"bytes\":\"63727a797061746368776f726b\"},{\"bytes\":\"697066733a2f2f516d61785435644c41586d4e61456271334d39545971384a5070383445313136785775364b43786f5933356b5051\"}]}}"
86+
}
87+
]

tests/test_dipdup/hen_subjkt.yml

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: hen_subjkt
3+
4+
contracts:
5+
hen_subjkt:
6+
address: KT1My1wDZHDGweCrJnQJi3wcFaS67iksirvj
7+
typename: hen_subjkt
8+
9+
datasources:
10+
tzkt:
11+
kind: tzkt
12+
url: https://api.tzkt.io
13+
14+
indexes:
15+
hen_subjkt:
16+
kind: operation
17+
datasource: tzkt
18+
contracts:
19+
- hen_subjkt
20+
handlers:
21+
- callback: on_registry
22+
pattern:
23+
- destination: hen_subjkt
24+
entrypoint: registry

tests/test_dipdup/test_models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from tests.test_dipdup.types.asdf.storage import AsdfStorage
1717
from tests.test_dipdup.types.bazaar.storage import BazaarMarketPlaceStorage
1818
from tests.test_dipdup.types.ftzfun.storage import FtzFunStorage
19+
from tests.test_dipdup.types.hen_subjkt.storage import HenSubjktStorage
1920
from tests.test_dipdup.types.hjkl.storage import HjklStorage
2021
from tests.test_dipdup.types.listofmaps.storage import ListOfMapsStorage
2122
from tests.test_dipdup.types.qwer.storage import QwerStorage
@@ -320,3 +321,16 @@ def test_rewq(self) -> None:
320321
self.assertEqual(storage_obj.map['try'].L['111'], '222') # type: ignore
321322
self.assertIsInstance(storage_obj.or_.L, dict) # type: ignore
322323
self.assertEqual(storage_obj.or_.L['333'], '444') # type: ignore
324+
325+
def test_hen_subjkt(self) -> None:
326+
with open(join(dirname(__file__), 'hen_subjkt.json')) as f:
327+
operations_json = json.load(f)
328+
329+
# Act
330+
operations = [TzktDatasource.convert_operation(op) for op in operations_json]
331+
storage_obj = deserialize_storage(operations[0], HenSubjktStorage)
332+
333+
# Assert
334+
self.assertIsInstance(storage_obj, HenSubjktStorage)
335+
self.assertIsInstance(storage_obj.entries, dict)
336+
self.assertEqual(storage_obj.entries['tz1Y1j7FK1X9Rrv2VdPz5bXoU7SszF8W1RnK'], True) # type: ignore

tests/test_dipdup/types/hen_subjkt/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# generated by datamodel-codegen:
2+
# filename: storage.json
3+
4+
from __future__ import annotations
5+
6+
from typing import Dict
7+
8+
from pydantic import BaseModel
9+
from pydantic import Extra
10+
11+
12+
class Invoices(BaseModel):
13+
class Config:
14+
extra = Extra.forbid
15+
16+
invoice: str
17+
subjkt: str
18+
19+
20+
class HenSubjktStorage(BaseModel):
21+
class Config:
22+
extra = Extra.forbid
23+
24+
entries: Dict[str, bool]
25+
invoices: Dict[str, Invoices]
26+
manager: str
27+
metadata: Dict[str, str]
28+
registries: Dict[str, str]
29+
subjkts: Dict[str, bool]
30+
subjkts_metadata: Dict[str, str]

0 commit comments

Comments
 (0)