Skip to content

Commit 295a455

Browse files
committed
utxo_by_tx_id ogmios test
1 parent fff7519 commit 295a455

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pycardano/backend/ogmios.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ def utxo_by_tx_id(self, tx_id: str, index: int) -> Optional[UTxO]:
384384
Optional[UTxO]: Return a UTxO if exists at the tx_id and index.
385385
"""
386386
results = self._query_utxos_by_tx_id(tx_id, index)
387+
assert len(results) < 2, f"Query for UTxO {tx_id}#{index} should be unique!"
387388

388389
utxos = []
389390
for result in results:

test/pycardano/backend/test_ogmios.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,17 @@ def override_request(method, args):
8989
elif args["query"] == "genesisConfig":
9090
return GENESIS_RESULT
9191
elif "utxo" in args["query"]:
92-
return UTXOS
92+
query = args["query"]["utxo"][0]
93+
if isinstance(query, dict):
94+
for utxo in UTXOS:
95+
if (
96+
utxo[0]["txId"] == query["txId"]
97+
and utxo[0]["index"] == query["index"]
98+
):
99+
return [utxo]
100+
return []
101+
else:
102+
return UTXOS
93103
else:
94104
return None
95105

@@ -174,3 +184,19 @@ def test_utxo(self):
174184
},
175185
}
176186
)
187+
188+
def test_utxo_by_tx_id(self):
189+
utxo = self.chain_context.utxo_by_tx_id(
190+
"3a42f652bd8dee788577e8c39b6217db3df659c33b10a2814c20fb66089ca167",
191+
1,
192+
)
193+
assert utxo.input == TransactionInput.from_primitive(
194+
["3a42f652bd8dee788577e8c39b6217db3df659c33b10a2814c20fb66089ca167", 1]
195+
)
196+
assert utxo.output.amount == 764295183
197+
198+
not_utxo = self.chain_context.utxo_by_tx_id(
199+
"3a42f652bd8dee788577e8c39b6217db3df659c33b10a2814c20fb66089ca167",
200+
2,
201+
)
202+
assert not_utxo is None

0 commit comments

Comments
 (0)