Skip to content
Draft
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
80 changes: 78 additions & 2 deletions cardano_node_tests/tests/test_dbsync_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from cardano_node_tests.utils import cluster_nodes
from cardano_node_tests.utils import configuration
from cardano_node_tests.utils import dbsync_service_manager as db_sync
from cardano_node_tests.utils import dbsync_queries
from cardano_node_tests.utils import dbsync_utils
from cardano_node_tests.utils import helpers

Expand Down Expand Up @@ -143,7 +144,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 @@ -158,7 +158,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 @@ -177,6 +176,83 @@ 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 vote data is inserted into the database a few minutes after the restart of db-sync
def _query_func():
off_chain_vote_data = next(
iter(dbsync_queries.query_off_chain_vote_data()), None
)
if off_chain_vote_data is None:
msg = f"No off-chain vota data record found in db-sync database"
raise dbsync_utils.DbSyncNoResponseError(msg)
return off_chain_vote_data
dbsync_utils.retry_query(query_func=_query_func, timeout=360)

check_dbsync_state(
expected_state={
db_sync.Table.COMMITTEE_DE_REGISTRATION: TableCondition.NOT_EMPTY,
db_sync.Table.COMMITTEE_MEMBER: TableCondition.NOT_EMPTY,
db_sync.Table.COMMITTEE_REGISTRATION: TableCondition.NOT_EMPTY,
db_sync.Table.COMMITTEE: TableCondition.NOT_EMPTY,
db_sync.Table.CONSTITUTION: TableCondition.NOT_EMPTY,
db_sync.Table.DELEGATION_VOTE: TableCondition.NOT_EMPTY,
db_sync.Table.DREP_DISTR: TableCondition.NOT_EMPTY,
db_sync.Table.DREP_REGISTRATION: TableCondition.NOT_EMPTY,
db_sync.Table.EPOCH_STATE: TableCondition.NOT_EMPTY,
db_sync.Table.GOV_ACTION_PROPOSAL: TableCondition.NOT_EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_DATA: TableCondition.NOT_EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_DREP_DATA: TableCondition.NOT_EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_EXTERNAL_UPDATE: TableCondition.NOT_EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_FETCH_ERROR: TableCondition.NOT_EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_GOV_ACTION_DATA: TableCondition.NOT_EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_REFERENCE: TableCondition.NOT_EMPTY,
db_sync.Table.VOTING_ANCHOR: TableCondition.NOT_EMPTY,
db_sync.Table.VOTING_PROCEDURE: TableCondition.NOT_EMPTY,
db_sync.Table.TREASURY_WITHDRAWAL: TableCondition.NOT_EMPTY,
}
)

db_sync_manager.restart_with_config(
custom_config=db_config.with_governance(
value=db_sync.SettingState.DISABLE
)
)
check_dbsync_state(
expected_state={
db_sync.Table.COMMITTEE_DE_REGISTRATION: TableCondition.EMPTY,
db_sync.Table.COMMITTEE_MEMBER: TableCondition.EMPTY,
db_sync.Table.COMMITTEE_REGISTRATION: TableCondition.EMPTY,
db_sync.Table.COMMITTEE: TableCondition.EMPTY,
db_sync.Table.CONSTITUTION: TableCondition.EMPTY,
db_sync.Table.DELEGATION_VOTE: TableCondition.EMPTY,
db_sync.Table.DREP_DISTR: TableCondition.EMPTY,
db_sync.Table.DREP_REGISTRATION: TableCondition.EMPTY,
db_sync.Table.EPOCH_STATE: TableCondition.EMPTY,
db_sync.Table.GOV_ACTION_PROPOSAL: TableCondition.EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_DATA: TableCondition.EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_DREP_DATA: TableCondition.EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_EXTERNAL_UPDATE: TableCondition.EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_FETCH_ERROR: TableCondition.EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_GOV_ACTION_DATA: TableCondition.EMPTY,
db_sync.Table.OFF_CHAIN_VOTE_REFERENCE: TableCondition.EMPTY,
db_sync.Table.VOTING_ANCHOR: TableCondition.EMPTY,
db_sync.Table.VOTING_PROCEDURE: TableCondition.EMPTY,
db_sync.Table.TREASURY_WITHDRAWAL: TableCondition.EMPTY,
}
)

yield governance

def tx_cbor_value_enable(
db_sync_manager: db_sync.DBSyncManager,
):
Expand Down
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_committee.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@

LOGGER = logging.getLogger(__name__)

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
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_constitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@

LOGGER = logging.getLogger(__name__)

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
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_drep.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@

MAINNET_DREP_DEPOSIT = 500_000_000

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
]


@dataclasses.dataclass(frozen=True, order=True)
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
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_no_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

LOGGER = logging.getLogger(__name__)

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
11 changes: 7 additions & 4 deletions cardano_node_tests/tests/tests_conway/test_pparam_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,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
]


NETWORK_GROUP_PPARAMS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

LOGGER = logging.getLogger(__name__)

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 @@ -23,10 +23,13 @@

LOGGER = logging.getLogger(__name__)

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
13 changes: 9 additions & 4 deletions cardano_node_tests/utils/dbsync_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ def query_treasury_withdrawal(txhash: str) -> tp.Generator[TreasuryWithdrawalDBR
yield TreasuryWithdrawalDBRow(*result)


def query_off_chain_vote_data(data_hash: str) -> tp.Generator[OffChainVoteDataDBRow, None, None]:
def query_off_chain_vote_data(data_hash: tp.Optional[str] = None) -> tp.Generator[OffChainVoteDataDBRow, None, None]:
"""Query the off chain vote data in db-sync."""
query = (
"SELECT"
Expand All @@ -1482,11 +1482,16 @@ def query_off_chain_vote_data(data_hash: str) -> tp.Generator[OffChainVoteDataDB
"LEFT JOIN off_chain_vote_gov_action_data gov ON data.id = gov.off_chain_vote_data_id "
"LEFT JOIN off_chain_vote_reference ref ON data.id = ref.off_chain_vote_data_id "
"LEFT JOIN voting_anchor va ON data.voting_anchor_id = va.id "
"WHERE data.hash = %s "
"ORDER BY va.id, ref.id, auth.id, updt.id;"
)

with execute(query=query, vars=(rf"\x{data_hash}",)) as cur:
query_params = ()
if data_hash is not None:
query += "WHERE data.hash = %s "
query_params = (rf"\x{data_hash}",)

query += "ORDER BY va.id, ref.id, auth.id, updt.id;"

with execute(query=query, vars=query_params) as cur:
while (result := cur.fetchone()) is not None:
yield OffChainVoteDataDBRow(*result)

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 @@ -358,14 +358,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
Loading