|
| 1 | +from unittest.mock import patch |
| 2 | + |
1 | 3 | from pycardano.backend.base import GenesisParameters, ProtocolParameters
|
2 | 4 | from pycardano.backend.ogmios import OgmiosChainContext
|
3 | 5 | from pycardano.network import Network
|
|
80 | 82 | ]
|
81 | 83 |
|
82 | 84 |
|
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 [] |
103 | 100 | else:
|
104 |
| - return None |
| 101 | + return UTXOS |
| 102 | + else: |
| 103 | + return None |
105 | 104 |
|
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) |
107 | 110 |
|
108 | 111 | def test_protocol_param(self):
|
109 | 112 | assert (
|
|
0 commit comments