Skip to content

Commit b90d7a4

Browse files
authored
Merge pull request #2 from Python-Cardano/feat/cache_chain_tip
Fix Ogmios test
2 parents ece49de + 64ec926 commit b90d7a4

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

pycardano/backend/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pycardano.address import Address
99
from pycardano.network import Network
1010
from pycardano.plutus import ExecutionUnits
11-
from pycardano.transaction import UTxO, Transaction
11+
from pycardano.transaction import Transaction, UTxO
1212

1313
__all__ = [
1414
"GenesisParameters",

pycardano/backend/ogmios.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
2+
import time
23
from datetime import datetime, timezone
34
from enum import Enum
45
from typing import Any, Dict, List, Optional, Tuple, Union
5-
import time
66

77
import cbor2
88
import requests

test/pycardano/backend/test_ogmios.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest.mock import patch
2+
13
from pycardano.backend.base import GenesisParameters, ProtocolParameters
24
from pycardano.backend.ogmios import OgmiosChainContext
35
from pycardano.network import Network
@@ -80,30 +82,31 @@
8082
]
8183

8284

83-
class TestOgmiosChainContext:
84-
chain_context = OgmiosChainContext("", Network.TESTNET)
85-
86-
def override_request(method, args):
87-
if args["query"] == "currentProtocolParameters":
88-
return PROTOCOL_RESULT
89-
elif args["query"] == "genesisConfig":
90-
return GENESIS_RESULT
91-
elif "utxo" in args["query"]:
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
85+
def override_request(method, args):
86+
if args["query"] == "currentProtocolParameters":
87+
return PROTOCOL_RESULT
88+
elif args["query"] == "genesisConfig":
89+
return GENESIS_RESULT
90+
elif "utxo" in args["query"]:
91+
query = args["query"]["utxo"][0]
92+
if isinstance(query, dict):
93+
for utxo in UTXOS:
94+
if (
95+
utxo[0]["txId"] == query["txId"]
96+
and utxo[0]["index"] == query["index"]
97+
):
98+
return [utxo]
99+
return []
103100
else:
104-
return None
101+
return UTXOS
102+
else:
103+
return None
105104

106-
chain_context._request = override_request
105+
106+
class TestOgmiosChainContext:
107+
def __init__(self):
108+
with patch("OgmiosChainContext._request", return_value=override_request):
109+
self.chain_context = OgmiosChainContext("", Network.TESTNET)
107110

108111
def test_protocol_param(self):
109112
assert (

0 commit comments

Comments
 (0)