Skip to content

Commit ad4d26d

Browse files
Fix empty contract balance in the amount field (#533)
1 parent 700a3ba commit ad4d26d

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
cache: 'poetry'
3838

3939
- name: Set up cache (replays)
40-
uses: actions/cache@v2
40+
uses: actions/cache@v3
4141
id: cache-replays
4242
with:
4343
path: ~/.cache/dipdup/replays

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
2424
- http: Adjusted per-datasource default config values.
2525
- project: Fixed outdated options in DipDup version question.
2626
- tzkt: Fixed deserializing `EventData` model.
27+
- tzkt: Fixed empty contract balance in the `amount` field.
2728

2829
## [6.2.0] - 2022-10-12
2930

src/dipdup/datasources/tzkt/datasource.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ def convert_operation(
877877
parameter_json = operation_json.get('parameter') or {}
878878
originated_contract_json = operation_json.get('originatedContract') or {}
879879

880+
if (amount := operation_json.get('contractBalance')) is None:
881+
amount = operation_json.get('amount')
882+
880883
entrypoint, parameter = parameter_json.get('entrypoint'), parameter_json.get('value')
881884
if target_json.get('address', '').startswith('KT1'):
882885
# NOTE: TzKT returns None for `default` entrypoint
@@ -898,7 +901,7 @@ def convert_operation(
898901
sender_address=sender_json.get('address'),
899902
target_address=target_json.get('address'),
900903
initiator_address=initiator_json.get('address'),
901-
amount=operation_json.get('amount', operation_json.get('contractBalance')),
904+
amount=amount,
902905
status=operation_json['status'],
903906
has_internals=operation_json.get('hasInternals'),
904907
sender_alias=operation_json['sender'].get('alias'),
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"type": "origination",
4+
"id": 71515915681792,
5+
"level": 1414413,
6+
"timestamp": "2022-10-29T13:31:45Z",
7+
"block": "BLtUaExwJnDyVJMAjseVhimNsQ5QCzr3ABDcCC5x9Hi4QyKtaA6",
8+
"hash": "ooFPKF1FGeMBHyP8YDtrhTsWX6dodMYRpBiNSCE5Qgj4JZofJA2",
9+
"counter": 397773,
10+
"sender": {
11+
"address": "tz1bgvq6y5RdjAUzBNNovqoAgBXv77dbkdhT"
12+
},
13+
"gasLimit": 12351,
14+
"gasUsed": 12251,
15+
"storageLimit": 17119,
16+
"storageUsed": 16762,
17+
"bakerFee": 17969,
18+
"storageFee": 4190500,
19+
"allocationFee": 64250,
20+
"contractBalance": 31000000,
21+
"code": [],
22+
"storage": {
23+
"lines": 194290,
24+
"claims": 194287,
25+
"events": 194289,
26+
"entries": 194288,
27+
"manager": "tz1bgvq6y5RdjAUzBNNovqoAgBXv77dbkdhT",
28+
"metadata": 194291,
29+
"maxEvents": "0",
30+
"positions": 194292,
31+
"precision": "1000000",
32+
"nextLineId": "0",
33+
"nextEntryId": "0",
34+
"totalShares": "0",
35+
"withdrawals": 194293,
36+
"activeEvents": {},
37+
"liquidityUnits": "0",
38+
"nextPositionId": "0",
39+
"entryLiquidityF": "0",
40+
"entryLockPeriod": "0",
41+
"isDepositPaused": false,
42+
"proposedManager": "tz1bgvq6y5RdjAUzBNNovqoAgBXv77dbkdhT",
43+
"activeLiquidityF": "0",
44+
"nextWithdrawalId": "0",
45+
"withdrawableLiquidityF": "0"
46+
},
47+
"diffs": [],
48+
"status": "applied",
49+
"originatedContract": {
50+
"kind": "smart_contract",
51+
"address": "KT18yRWV3SxjQXTHAmYMrsVCxapDjAyRc6NX",
52+
"typeHash": 1717450189,
53+
"codeHash": -1823060929
54+
}
55+
}
56+
]

tests/test_dipdup/test_models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,15 @@ def test_yupana(self) -> None:
375375
self.assertIsInstance(storage_obj, YupanaStorage)
376376
self.assertIsInstance(storage_obj.storage.markets, dict)
377377
self.assertEqual(storage_obj.storage.markets['tz1MDhGTfMQjtMYFXeasKzRWzkQKPtXEkSEw'], ['0'])
378+
379+
380+
def _load_response(name: str) -> Any:
381+
path = Path(__file__).parent / 'responses' / name
382+
return json.loads(path.read_bytes())
383+
384+
385+
def test_origination_amount() -> None:
386+
operations_json = _load_response('origination_amount.json')
387+
operation = TzktDatasource.convert_operation(operations_json[0])
388+
389+
assert operation.amount == 31000000

0 commit comments

Comments
 (0)