|
10 | 10 | from web3 import Web3 |
11 | 11 |
|
12 | 12 | from ...datasources.abis.gnosis_protocol import cowswap_settlement_v2_abi |
13 | | -from ...datasources.db.database import db_session_context |
| 13 | +from ...datasources.db.database import db_session_context, transactional_session_context |
14 | 14 | from ...datasources.db.models import Abi, AbiSource, Contract |
15 | 15 | from ...main import app |
16 | 16 | from ...services.abis import AbiService |
@@ -120,33 +120,34 @@ async def test_view_data_decoder_with_chain_id_without_to(self): |
120 | 120 | }, |
121 | 121 | ) |
122 | 122 |
|
123 | | - @db_session_context |
124 | 123 | async def test_view_data_decoder_with_chain_id(self): |
125 | | - source = AbiSource(name="local", url="") |
126 | | - await source.create() |
127 | | - |
| 124 | + # No outer context: the endpoint must scope its own session |
128 | 125 | contract_address = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" |
129 | | - abi = Abi(abi_json=example_abi, relevance=101, source_id=source.id) |
130 | | - await abi.create() |
131 | | - contract = Contract( |
132 | | - address=HexBytes(contract_address), |
133 | | - abi=abi, |
134 | | - name="SwappedContract", |
135 | | - chain_id=1, |
136 | | - ) |
137 | | - await contract.create() |
| 126 | + async with transactional_session_context(): |
| 127 | + source = AbiSource(name="local", url="") |
| 128 | + await source.create() |
138 | 129 |
|
139 | | - swapped_abi = Abi( |
140 | | - abi_json=example_swapped_abi, relevance=100, source_id=source.id |
141 | | - ) |
142 | | - await swapped_abi.create() |
143 | | - contract = Contract( |
144 | | - address=HexBytes(contract_address), |
145 | | - abi=swapped_abi, |
146 | | - name="SwappedContract", |
147 | | - chain_id=2, |
148 | | - ) |
149 | | - await contract.create() |
| 130 | + abi = Abi(abi_json=example_abi, relevance=101, source_id=source.id) |
| 131 | + await abi.create() |
| 132 | + contract = Contract( |
| 133 | + address=HexBytes(contract_address), |
| 134 | + abi=abi, |
| 135 | + name="SwappedContract", |
| 136 | + chain_id=1, |
| 137 | + ) |
| 138 | + await contract.create() |
| 139 | + |
| 140 | + swapped_abi = Abi( |
| 141 | + abi_json=example_swapped_abi, relevance=100, source_id=source.id |
| 142 | + ) |
| 143 | + await swapped_abi.create() |
| 144 | + contract = Contract( |
| 145 | + address=HexBytes(contract_address), |
| 146 | + abi=swapped_abi, |
| 147 | + name="SwappedContract", |
| 148 | + chain_id=2, |
| 149 | + ) |
| 150 | + await contract.create() |
150 | 151 |
|
151 | 152 | example_data = ( |
152 | 153 | Web3() |
|
0 commit comments