Skip to content

Commit c53de1b

Browse files
Fixed policy_assets
Added more tests
1 parent 8abcc06 commit c53de1b

File tree

7 files changed

+415
-130
lines changed

7 files changed

+415
-130
lines changed

blockfrost/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def root(self):
6767
asset_history, \
6868
asset_transactions, \
6969
asset_addresses, \
70-
policy_assets
70+
assets_policy
7171
from .cardano.blocks import \
7272
block_latest, \
7373
block_latest_transactions, \

blockfrost/api/cardano/addresses.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ class Amount:
1414
amount: [Amount]
1515
stake_address: str
1616
type: str
17+
script: bool
1718

18-
def __init__(self, address: str, amount: [Amount], stake_address: str, type: str) -> None:
19+
def __init__(self, address: str, amount: [Amount], stake_address: str, type: str, script: bool) -> None:
1920
self.address = address
2021
self.amount = [self.Amount(**o) for o in amount]
2122
self.stake_address = stake_address
2223
self.type = type
24+
self.script = script
2325

2426

2527
@object_request_wrapper(AddressResponse)
@@ -92,12 +94,14 @@ class Amount:
9294
output_index: int
9395
amount: [Amount]
9496
block: str
97+
data_hash: str
9598

96-
def __init__(self, tx_hash: str, output_index: int, amount: [Amount], block: str) -> None:
99+
def __init__(self, tx_hash: str, output_index: int, amount: [Amount], block: str, data_hash: str) -> None:
97100
self.tx_hash = tx_hash
98101
self.output_index = output_index
99102
self.amount = [self.Amount(**o) for o in amount]
100103
self.block = block
104+
self.data_hash = data_hash
101105

102106

103107
@object_list_request_wrapper(AddressesUTXOSResponse)

blockfrost/api/cardano/assets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ def asset_addresses(self, asset: str, **kwargs):
210210

211211

212212
@dataclass
213-
class PolicyAssetResponse:
214-
address: str
213+
class AssetPolicyResponse:
214+
asset: str
215215
quantity: str
216216

217217

218-
@object_request_wrapper(PolicyAssetResponse)
219-
def policy_assets(self, policy_id: str, **kwargs):
218+
@object_list_request_wrapper(AssetPolicyResponse)
219+
def assets_policy(self, policy_id: str, **kwargs):
220220
"""
221221
List of asset minted under a specific policy
222222
@@ -238,7 +238,7 @@ def policy_assets(self, policy_id: str, **kwargs):
238238
:raises Exception: If the API response is somehow malformed.
239239
"""
240240
return requests.get(
241-
url=f"{self.url}/assets/{policy_id}",
241+
url=f"{self.url}/assets/policy/{policy_id}",
242242
params=self.query_parameters(kwargs),
243243
headers=self.default_headers
244244
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
setup(
1818
name='blockfrost-python',
19-
version='0.1.1',
19+
version='0.1.2',
2020
description='The official Python SDK for Blockfrost API v0.1.26',
2121
long_description=long_description,
2222
long_description_content_type='text/markdown',

tests/test_cardano_accounts.py

Lines changed: 125 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
from blockfrost import BlockFrostApi, ApiError
22
from blockfrost.api.cardano.accounts import \
33
AccountResponse, \
4-
AccountRewardResponse
4+
AccountRewardResponse, \
5+
AccountHistoryResponse, \
6+
AccountDelegationResponse, \
7+
AccountRegistrationResponse, \
8+
AccountWithdrawalResponse, \
9+
AccountMIRSResponse, \
10+
AccountAddressResponse, \
11+
AccountAddressesAssetResponse
512

6-
address = 'addr1q9ucyt3s5f4naz3n7fwpnt3a0t75kl3rxdvpe63e2gdes7dzs4s26v4800nwg8jygvrdqh6xhsphct0d4zqsnd3sagxq6kwrts'
713
stake_address = 'stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7'
814

915

@@ -23,7 +29,7 @@ def test_accounts(requests_mock):
2329
}
2430
requests_mock.get(f"{api.url}/accounts/{stake_address}", json=mock_data)
2531
mock_object = AccountResponse(**mock_data)
26-
assert api.accounts(stake_address=stake_address).stake_address == mock_object.stake_address
32+
assert api.accounts(stake_address=stake_address) == mock_object
2733

2834

2935
def test_account_rewards(requests_mock):
@@ -52,68 +58,133 @@ def test_account_rewards(requests_mock):
5258
]
5359
requests_mock.get(f"{api.url}/accounts/{stake_address}/rewards", json=mock_data)
5460
mock_object = [AccountRewardResponse(**data) for data in mock_data]
55-
assert api.account_rewards(stake_address=stake_address)[0].pool_id == mock_object[0].pool_id
61+
assert api.account_rewards(stake_address=stake_address) == mock_object
5662

5763

58-
def test_account_history():
59-
assert True
60-
61-
62-
def test_account_delegations():
63-
assert True
64-
65-
66-
def test_account_registrations():
67-
assert True
68-
69-
70-
def test_account_withdrawals():
71-
assert True
72-
73-
74-
def test_account_mirs():
75-
assert True
76-
77-
78-
def test_account_addresses():
79-
assert True
80-
81-
82-
def test_account_addresses_assets():
83-
assert True
84-
85-
86-
def test_account():
87-
assert True
88-
89-
90-
def test_account_reward():
91-
assert True
92-
93-
94-
def test_account_history():
95-
assert True
64+
def test_account_history(requests_mock):
65+
api = BlockFrostApi()
66+
mock_data = [
67+
{
68+
"active_epoch": 210,
69+
"amount": "12695385",
70+
"pool_id": "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"
71+
},
72+
{
73+
"active_epoch": 211,
74+
"amount": "22695385",
75+
"pool_id": "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"
76+
}
77+
]
78+
requests_mock.get(f"{api.url}/accounts/{stake_address}/history", json=mock_data)
79+
mock_object = [AccountHistoryResponse(**data) for data in mock_data]
80+
assert api.account_history(stake_address=stake_address) == mock_object
9681

9782

98-
def test_account_delegation():
99-
assert True
83+
def test_account_delegations(requests_mock):
84+
api = BlockFrostApi()
85+
mock_data = [
86+
{
87+
"active_epoch": 210,
88+
"tx_hash": "2dd15e0ef6e6a17841cb9541c27724072ce4d4b79b91e58432fbaa32d9572531",
89+
"amount": "12695385",
90+
"pool_id": "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy"
91+
},
92+
{
93+
"active_epoch": 242,
94+
"tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dde628516157f0",
95+
"amount": "12691385",
96+
"pool_id": "pool1kchver88u3kygsak8wgll7htr8uxn5v35lfrsyy842nkscrzyvj"
97+
}
98+
]
99+
requests_mock.get(f"{api.url}/accounts/{stake_address}/delegations", json=mock_data)
100+
mock_object = [AccountDelegationResponse(**data) for data in mock_data]
101+
assert api.account_delegations(stake_address=stake_address) == mock_object
100102

101103

102-
def test_account_registration():
103-
assert True
104+
def test_account_registrations(requests_mock):
105+
api = BlockFrostApi()
106+
mock_data = [
107+
{
108+
"tx_hash": "2dd15e0ef6e6a17841cb9541c27724072ce4d4b79b91e58432fbaa32d9572531",
109+
"action": "registered"
110+
},
111+
{
112+
"tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dde628516157f0",
113+
"action": "deregistered"
114+
}
115+
]
116+
requests_mock.get(f"{api.url}/accounts/{stake_address}/registrations", json=mock_data)
117+
mock_object = [AccountRegistrationResponse(**data) for data in mock_data]
118+
assert api.account_registrations(stake_address=stake_address) == mock_object
104119

105120

106-
def test_account_withdrawals():
107-
assert True
121+
def test_account_withdrawals(requests_mock):
122+
api = BlockFrostApi()
123+
mock_data = [
124+
{
125+
"tx_hash": "48a9625c841eea0dd2bb6cf551eabe6523b7290c9ce34be74eedef2dd8f7ecc5",
126+
"amount": "454541212442"
127+
},
128+
{
129+
"tx_hash": "4230b0cbccf6f449f0847d8ad1d634a7a49df60d8c142bb8cc2dbc8ca03d9e34",
130+
"amount": "97846969"
131+
}
132+
]
133+
requests_mock.get(f"{api.url}/accounts/{stake_address}/withdrawals", json=mock_data)
134+
mock_object = [AccountWithdrawalResponse(**data) for data in mock_data]
135+
assert api.account_withdrawals(stake_address=stake_address) == mock_object
108136

109137

110-
def test_account_mirs():
111-
assert True
138+
def test_account_mirs(requests_mock):
139+
api = BlockFrostApi()
140+
mock_data = [
141+
{
142+
"tx_hash": "69705bba1d687a816ff5a04ec0c358a1f1ef075ab7f9c6cc2763e792581cec6d",
143+
"amount": "2193707473"
144+
},
145+
{
146+
"tx_hash": "baaa77b63d4d7d2bb3ab02c9b85978c2092c336dede7f59e31ad65452d510c13",
147+
"amount": "14520198574"
148+
}
149+
]
150+
requests_mock.get(f"{api.url}/accounts/{stake_address}/mirs", json=mock_data)
151+
mock_object = [AccountMIRSResponse(**data) for data in mock_data]
152+
assert api.account_mirs(stake_address=stake_address) == mock_object
112153

113154

114-
def test_account_address():
115-
assert True
155+
def test_account_addresses(requests_mock):
156+
api = BlockFrostApi()
157+
mock_data = [
158+
{
159+
"address": "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"
160+
},
161+
{
162+
"address": "addr1qys3czp8s9thc6u2fqed9yq3h24nyw28uk0m6mkgn9dkckjf79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9suth4w4"
163+
},
164+
{
165+
"address": "addr1q8j55h253zcvl326sk5qdt2n8z7eghzspe0ekxgncr796s2f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sjmd35m"
166+
},
167+
{
168+
"address": "addr1q8f7gxrprank3drhx8k5grlux7ene0nlwun8y9thu8mc3yjf79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sls6vnt"
169+
}
170+
]
171+
requests_mock.get(f"{api.url}/accounts/{stake_address}/addresses", json=mock_data)
172+
mock_object = [AccountAddressResponse(**data) for data in mock_data]
173+
assert api.account_addresses(stake_address=stake_address) == mock_object
116174

117175

118-
def test_account_addresses_asset():
119-
assert True
176+
def test_account_addresses_assets(requests_mock):
177+
api = BlockFrostApi()
178+
mock_data = [
179+
{
180+
"unit": "d5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc537061636542756433343132",
181+
"quantity": "1"
182+
},
183+
{
184+
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
185+
"quantity": "125"
186+
}
187+
]
188+
requests_mock.get(f"{api.url}/accounts/{stake_address}/addresses/assets", json=mock_data)
189+
mock_object = [AccountAddressesAssetResponse(**data) for data in mock_data]
190+
assert api.account_addresses_assets(stake_address=stake_address) == mock_object

0 commit comments

Comments
 (0)