Skip to content

Commit 9da33c9

Browse files
test(db-sync config): Add db-sync test for governance option
1 parent 034d740 commit 9da33c9

File tree

7 files changed

+117
-12
lines changed

7 files changed

+117
-12
lines changed

cardano_node_tests/tests/test_dbsync_config.py

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from cardano_node_tests.tests import common
1414
from cardano_node_tests.utils import cluster_nodes
1515
from cardano_node_tests.utils import configuration
16+
from cardano_node_tests.utils import dbsync_queries
1617
from cardano_node_tests.utils import dbsync_service_manager as db_sync
1718
from cardano_node_tests.utils import dbsync_utils
1819
from cardano_node_tests.utils import helpers
@@ -145,7 +146,6 @@ def basic_tx_out(
145146
"""Test `tx_out` option."""
146147
db_config = db_sync_manager.get_config_builder()
147148

148-
# Test tx_out : enable
149149
db_sync_manager.restart_with_config(
150150
custom_config=db_config.with_tx_out(
151151
value=db_sync.TxOutMode.ENABLE, force_tx_in=False, use_address_table=False
@@ -160,7 +160,6 @@ def basic_tx_out(
160160
}
161161
)
162162

163-
# Test tx_out : disable
164163
db_sync_manager.restart_with_config(
165164
custom_config=db_config.with_tx_out(
166165
value=db_sync.TxOutMode.DISABLE, force_tx_in=True, use_address_table=True
@@ -179,6 +178,106 @@ def basic_tx_out(
179178

180179
yield basic_tx_out
181180

181+
def governance(
182+
db_sync_manager: db_sync.DBSyncManager,
183+
):
184+
"""Test `governance` option."""
185+
db_config = db_sync_manager.get_config_builder()
186+
187+
db_sync_manager.restart_with_config(
188+
custom_config=db_config.with_governance(value=db_sync.SettingState.ENABLE)
189+
)
190+
191+
# Off-chain data is inserted into the DB a few minutes after the restart of db-sync
192+
def _query_func():
193+
tables_to_check = [
194+
db_sync.Table.COMMITTEE_DE_REGISTRATION,
195+
db_sync.Table.COMMITTEE_MEMBER,
196+
db_sync.Table.COMMITTEE_REGISTRATION,
197+
db_sync.Table.COMMITTEE,
198+
db_sync.Table.CONSTITUTION,
199+
db_sync.Table.DELEGATION_VOTE,
200+
db_sync.Table.DREP_DISTR,
201+
db_sync.Table.DREP_REGISTRATION,
202+
db_sync.Table.EPOCH_STATE,
203+
db_sync.Table.GOV_ACTION_PROPOSAL,
204+
db_sync.Table.OFF_CHAIN_VOTE_DATA,
205+
db_sync.Table.OFF_CHAIN_VOTE_DREP_DATA,
206+
db_sync.Table.OFF_CHAIN_VOTE_EXTERNAL_UPDATE,
207+
db_sync.Table.OFF_CHAIN_VOTE_FETCH_ERROR,
208+
db_sync.Table.OFF_CHAIN_VOTE_GOV_ACTION_DATA,
209+
db_sync.Table.OFF_CHAIN_VOTE_REFERENCE,
210+
db_sync.Table.VOTING_ANCHOR,
211+
db_sync.Table.VOTING_PROCEDURE,
212+
db_sync.Table.TREASURY_WITHDRAWAL,
213+
]
214+
215+
empty_tables = [
216+
table for table in tables_to_check
217+
if dbsync_utils.table_empty(table)
218+
]
219+
220+
if empty_tables:
221+
msg = f"Following tables are still empty: {empty_tables}"
222+
raise dbsync_utils.DbSyncNoResponseError(msg)
223+
224+
return True
225+
226+
dbsync_utils.retry_query(query_func=_query_func, timeout=600)
227+
228+
check_dbsync_state(
229+
expected_state={
230+
db_sync.Table.COMMITTEE_DE_REGISTRATION: TableCondition.NOT_EMPTY,
231+
db_sync.Table.COMMITTEE_MEMBER: TableCondition.NOT_EMPTY,
232+
db_sync.Table.COMMITTEE_REGISTRATION: TableCondition.NOT_EMPTY,
233+
db_sync.Table.COMMITTEE: TableCondition.NOT_EMPTY,
234+
db_sync.Table.CONSTITUTION: TableCondition.NOT_EMPTY,
235+
db_sync.Table.DELEGATION_VOTE: TableCondition.NOT_EMPTY,
236+
db_sync.Table.DREP_DISTR: TableCondition.NOT_EMPTY,
237+
db_sync.Table.DREP_REGISTRATION: TableCondition.NOT_EMPTY,
238+
db_sync.Table.EPOCH_STATE: TableCondition.NOT_EMPTY,
239+
db_sync.Table.GOV_ACTION_PROPOSAL: TableCondition.NOT_EMPTY,
240+
db_sync.Table.OFF_CHAIN_VOTE_DATA: TableCondition.NOT_EMPTY,
241+
db_sync.Table.OFF_CHAIN_VOTE_DREP_DATA: TableCondition.NOT_EMPTY,
242+
db_sync.Table.OFF_CHAIN_VOTE_EXTERNAL_UPDATE: TableCondition.NOT_EMPTY,
243+
db_sync.Table.OFF_CHAIN_VOTE_FETCH_ERROR: TableCondition.NOT_EMPTY,
244+
db_sync.Table.OFF_CHAIN_VOTE_GOV_ACTION_DATA: TableCondition.NOT_EMPTY,
245+
db_sync.Table.OFF_CHAIN_VOTE_REFERENCE: TableCondition.NOT_EMPTY,
246+
db_sync.Table.VOTING_ANCHOR: TableCondition.NOT_EMPTY,
247+
db_sync.Table.VOTING_PROCEDURE: TableCondition.NOT_EMPTY,
248+
db_sync.Table.TREASURY_WITHDRAWAL: TableCondition.NOT_EMPTY,
249+
}
250+
)
251+
252+
db_sync_manager.restart_with_config(
253+
custom_config=db_config.with_governance(value=db_sync.SettingState.DISABLE)
254+
)
255+
check_dbsync_state(
256+
expected_state={
257+
db_sync.Table.COMMITTEE_DE_REGISTRATION: TableCondition.EMPTY,
258+
db_sync.Table.COMMITTEE_MEMBER: TableCondition.EMPTY,
259+
db_sync.Table.COMMITTEE_REGISTRATION: TableCondition.EMPTY,
260+
db_sync.Table.COMMITTEE: TableCondition.EMPTY,
261+
db_sync.Table.CONSTITUTION: TableCondition.EMPTY,
262+
db_sync.Table.DELEGATION_VOTE: TableCondition.EMPTY,
263+
db_sync.Table.DREP_DISTR: TableCondition.EMPTY,
264+
db_sync.Table.DREP_REGISTRATION: TableCondition.EMPTY,
265+
db_sync.Table.EPOCH_STATE: TableCondition.EMPTY,
266+
db_sync.Table.GOV_ACTION_PROPOSAL: TableCondition.EMPTY,
267+
db_sync.Table.OFF_CHAIN_VOTE_DATA: TableCondition.EMPTY,
268+
db_sync.Table.OFF_CHAIN_VOTE_DREP_DATA: TableCondition.EMPTY,
269+
db_sync.Table.OFF_CHAIN_VOTE_EXTERNAL_UPDATE: TableCondition.EMPTY,
270+
db_sync.Table.OFF_CHAIN_VOTE_FETCH_ERROR: TableCondition.EMPTY,
271+
db_sync.Table.OFF_CHAIN_VOTE_GOV_ACTION_DATA: TableCondition.EMPTY,
272+
db_sync.Table.OFF_CHAIN_VOTE_REFERENCE: TableCondition.EMPTY,
273+
db_sync.Table.VOTING_ANCHOR: TableCondition.EMPTY,
274+
db_sync.Table.VOTING_PROCEDURE: TableCondition.EMPTY,
275+
db_sync.Table.TREASURY_WITHDRAWAL: TableCondition.EMPTY,
276+
}
277+
)
278+
279+
yield governance
280+
182281
def tx_cbor_value_enable(
183282
db_sync_manager: db_sync.DBSyncManager,
184283
):

cardano_node_tests/tests/tests_conway/test_committee.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ def test_update_committee_action(
550550
@allure.link(helpers.get_vcs_link())
551551
@pytest.mark.long
552552
@pytest.mark.dbsync
553+
@pytest.mark.dbsync_config
553554
def test_add_rm_committee_members( # noqa: C901
554555
self,
555556
cluster_lock_governance: governance_utils.GovClusterT,

cardano_node_tests/tests/tests_conway/test_drep.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def test_drep_id_is_blake2b_224_of_drep_vkey(
318318
@submit_utils.PARAM_SUBMIT_METHOD
319319
@common.PARAM_BUILD_METHOD_NO_EST
320320
@pytest.mark.dbsync
321+
@pytest.mark.dbsync_config
321322
@pytest.mark.testnets
322323
@pytest.mark.smoke
323324
@pytest.mark.parametrize(

cardano_node_tests/tests/tests_conway/test_info.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
LOGGER = logging.getLogger(__name__)
2323
DATA_DIR = pl.Path(__file__).parent.parent / "data"
2424

25-
pytestmark = pytest.mark.skipif(
26-
VERSIONS.transaction_era < VERSIONS.CONWAY,
27-
reason="runs only with Tx era >= Conway",
28-
)
25+
pytestmark = [
26+
pytest.mark.skipif(
27+
VERSIONS.transaction_era < VERSIONS.CONWAY,
28+
reason="runs only with Tx era >= Conway",
29+
),
30+
pytest.mark.dbsync_config,
31+
]
2932

3033

3134
@pytest.fixture

cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class TestTreasuryWithdrawals:
9393

9494
@allure.link(helpers.get_vcs_link())
9595
@pytest.mark.dbsync
96+
@pytest.mark.dbsync_config
9697
@pytest.mark.long
9798
@pytest.mark.upgrade_step3
9899
def test_enact_treasury_withdrawals(

cardano_node_tests/utils/dbsync_service_manager.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,12 @@ def recreate_database(self) -> None:
359359
This is a DESTRUCTIVE operation!
360360
It will delete existing data and recreate the database from scratch.
361361
"""
362-
scripts_dir = cluster_scripts.get_testnet_variant_scriptdir(
363-
testnet_variant=configuration.TESTNET_VARIANT
364-
)
365-
if not scripts_dir:
366-
err = f"Testnet variant '{configuration.TESTNET_VARIANT}' scripts directory not found."
362+
common_scripts_dir = cluster_scripts.COMMON_DIR
363+
if not common_scripts_dir:
364+
err = f"Common scripts directory '{common_scripts_dir}' not found."
367365
raise RuntimeError(err)
368366

369-
db_script_template = scripts_dir / "postgres-setup.sh"
367+
db_script_template = common_scripts_dir / "postgres-setup.sh"
370368
if not db_script_template.exists() and configuration.BOOTSTRAP_DIR:
371369
db_script_template = pl.Path(configuration.BOOTSTRAP_DIR) / "postgres-setup.sh"
372370

cardano_node_tests/utils/logfiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"OffChainPoolFetchError",
5151
# DB-Sync table name
5252
"OffChainVoteFetchError",
53+
# DB-Sync table name (lowercase)
54+
"off_chain_vote_fetch_error",
5355
# TODO: p2p failures on testnet
5456
"PeerStatusChangeFailure",
5557
# TODO: p2p failures on testnet - PeerMonitoringError

0 commit comments

Comments
 (0)