Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 61 additions & 3 deletions cardano_node_tests/tests/test_dbsync_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,31 @@ class ColumnCondition(str, enum.Enum):
IS_NULL = "column_condition:IS NULL"


GOVERNANCE_TABLES = (
db_sync.Table.COMMITTEE_DE_REGISTRATION,
db_sync.Table.COMMITTEE_MEMBER,
db_sync.Table.COMMITTEE_REGISTRATION,
db_sync.Table.COMMITTEE,
db_sync.Table.CONSTITUTION,
db_sync.Table.DELEGATION_VOTE,
db_sync.Table.DREP_DISTR,
db_sync.Table.DREP_REGISTRATION,
db_sync.Table.EPOCH_STATE,
db_sync.Table.GOV_ACTION_PROPOSAL,
db_sync.Table.OFF_CHAIN_VOTE_DATA,
db_sync.Table.OFF_CHAIN_VOTE_DREP_DATA,
db_sync.Table.OFF_CHAIN_VOTE_EXTERNAL_UPDATE,
db_sync.Table.OFF_CHAIN_VOTE_FETCH_ERROR,
db_sync.Table.OFF_CHAIN_VOTE_GOV_ACTION_DATA,
db_sync.Table.OFF_CHAIN_VOTE_REFERENCE,
db_sync.Table.VOTING_ANCHOR,
db_sync.Table.VOTING_PROCEDURE,
db_sync.Table.TREASURY_WITHDRAWAL,
)


def check_dbsync_state(
expected_state: dict[tp.Union[str, db_sync.Table], TableCondition | ColumnCondition],
expected_state: dict[str | db_sync.Table, TableCondition | ColumnCondition],
) -> None:
"""Check the state of db-sync tables and columns against expected conditions.

Expand Down Expand Up @@ -145,7 +168,6 @@ def basic_tx_out(
"""Test `tx_out` option."""
db_config = db_sync_manager.get_config_builder()

# Test tx_out : enable
db_sync_manager.restart_with_config(
custom_config=db_config.with_tx_out(
value=db_sync.TxOutMode.ENABLE, force_tx_in=False, use_address_table=False
Expand All @@ -160,7 +182,6 @@ def basic_tx_out(
}
)

# Test tx_out : disable
db_sync_manager.restart_with_config(
custom_config=db_config.with_tx_out(
value=db_sync.TxOutMode.DISABLE, force_tx_in=True, use_address_table=True
Expand All @@ -179,6 +200,43 @@ def basic_tx_out(

yield basic_tx_out

def governance(
db_sync_manager: db_sync.DBSyncManager,
):
"""Test `governance` option."""
db_config = db_sync_manager.get_config_builder()

db_sync_manager.restart_with_config(
custom_config=db_config.with_governance(value=db_sync.SettingState.ENABLE)
)

# Off-chain data is inserted into the DB a few minutes after the restart of db-sync
def _query_func():
empty_tables = [
table for table in GOVERNANCE_TABLES if dbsync_utils.table_empty(table=table)
]

if empty_tables:
msg = f"Following tables are still empty: {empty_tables}"
raise dbsync_utils.DbSyncNoResponseError(msg)

return True

dbsync_utils.retry_query(query_func=_query_func, timeout=600)

check_dbsync_state(
expected_state={t: TableCondition.NOT_EMPTY for t in GOVERNANCE_TABLES} # noqa: C420
)

db_sync_manager.restart_with_config(
custom_config=db_config.with_governance(value=db_sync.SettingState.DISABLE)
)
check_dbsync_state(
expected_state={t: TableCondition.EMPTY for t in GOVERNANCE_TABLES} # noqa: C420
Comment on lines +228 to +235
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The # noqa: C420 comment suggests suppressing a flake8-comprehensions warning about unnecessary dict comprehension. However, this is a legitimate use case where a dict comprehension is needed to create the expected_state dictionary. Consider removing the noqa comment if the linter rule is overly strict, or ensure the team agrees this suppression is necessary.

Suggested change
expected_state={t: TableCondition.NOT_EMPTY for t in GOVERNANCE_TABLES} # noqa: C420
)
db_sync_manager.restart_with_config(
custom_config=db_config.with_governance(value=db_sync.SettingState.DISABLE)
)
check_dbsync_state(
expected_state={t: TableCondition.EMPTY for t in GOVERNANCE_TABLES} # noqa: C420
expected_state={t: TableCondition.NOT_EMPTY for t in GOVERNANCE_TABLES}
)
db_sync_manager.restart_with_config(
custom_config=db_config.with_governance(value=db_sync.SettingState.DISABLE)
)
check_dbsync_state(
expected_state={t: TableCondition.EMPTY for t in GOVERNANCE_TABLES}

Copilot uses AI. Check for mistakes.
)

yield governance

def tx_cbor_value_enable(
db_sync_manager: db_sync.DBSyncManager,
):
Expand Down
1 change: 1 addition & 0 deletions cardano_node_tests/tests/tests_conway/test_committee.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def test_update_committee_action(
@allure.link(helpers.get_vcs_link())
@pytest.mark.long
@pytest.mark.dbsync
@pytest.mark.dbsync_config
def test_add_rm_committee_members( # noqa: C901
self,
cluster_lock_governance: governance_utils.GovClusterT,
Expand Down
1 change: 1 addition & 0 deletions cardano_node_tests/tests/tests_conway/test_drep.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def test_drep_id_is_blake2b_224_of_drep_vkey(
@submit_utils.PARAM_SUBMIT_METHOD
@common.PARAM_BUILD_METHOD_NO_EST
@pytest.mark.dbsync
@pytest.mark.dbsync_config
@pytest.mark.testnets
@pytest.mark.smoke
@pytest.mark.parametrize(
Expand Down
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
LOGGER = logging.getLogger(__name__)
DATA_DIR = pl.Path(__file__).parent.parent / "data"

pytestmark = pytest.mark.skipif(
VERSIONS.transaction_era < VERSIONS.CONWAY,
reason="runs only with Tx era >= Conway",
)
pytestmark = [
pytest.mark.skipif(
VERSIONS.transaction_era < VERSIONS.CONWAY,
reason="runs only with Tx era >= Conway",
),
pytest.mark.dbsync_config,
]


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class TestTreasuryWithdrawals:

@allure.link(helpers.get_vcs_link())
@pytest.mark.dbsync
@pytest.mark.dbsync_config
@pytest.mark.long
@pytest.mark.upgrade_step3
def test_enact_treasury_withdrawals(
Expand Down
10 changes: 4 additions & 6 deletions cardano_node_tests/utils/dbsync_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,12 @@ def recreate_database(self) -> None:
This is a DESTRUCTIVE operation!
It will delete existing data and recreate the database from scratch.
"""
scripts_dir = cluster_scripts.get_testnet_variant_scriptdir(
testnet_variant=configuration.TESTNET_VARIANT
)
if not scripts_dir:
err = f"Testnet variant '{configuration.TESTNET_VARIANT}' scripts directory not found."
common_scripts_dir = cluster_scripts.COMMON_DIR
if not common_scripts_dir:
err = f"Common scripts directory '{common_scripts_dir}' not found."
raise RuntimeError(err)

db_script_template = scripts_dir / "postgres-setup.sh"
db_script_template = common_scripts_dir / "postgres-setup.sh"
if not db_script_template.exists() and configuration.BOOTSTRAP_DIR:
db_script_template = pl.Path(configuration.BOOTSTRAP_DIR) / "postgres-setup.sh"

Expand Down
2 changes: 2 additions & 0 deletions cardano_node_tests/utils/logfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"OffChainPoolFetchError",
# DB-Sync table name
"OffChainVoteFetchError",
# DB-Sync table name (lowercase)
"off_chain_vote_fetch_error",
# TODO: p2p failures on testnet
"PeerStatusChangeFailure",
# TODO: p2p failures on testnet - PeerMonitoringError
Expand Down
Loading