diff --git a/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py b/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py index 3396d3b0f..9efb39a63 100644 --- a/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py +++ b/cardano_node_tests/tests/tests_conway/test_treasury_withdrawals.py @@ -52,7 +52,7 @@ class TestTreasuryWithdrawals: @allure.link(helpers.get_vcs_link()) @pytest.mark.dbsync @pytest.mark.long - def test_treasury_withdrawals( # noqa: C901 + def test_enact_treasury_withdrawals( # noqa: C901 self, cluster_use_governance: governance_utils.GovClusterT, pool_user_ug: clusterlib.PoolUser, @@ -358,19 +358,19 @@ def _cast_vote( governance_utils.check_vote_view(cluster_obj=cluster, vote_data=voted_votes.cc[0]) governance_utils.check_vote_view(cluster_obj=cluster, vote_data=voted_votes.drep[0]) + # Check dbsync _url = helpers.get_vcs_link() [r.start(url=_url) for r in (reqc.cip084, reqc.db009, reqc.db022)] - # Check dbsync + transfer_amts = [transfer_amt] * actions_num dbsync_utils.check_treasury_withdrawal( - actions_num=actions_num, stake_address=recv_stake_addr_rec.address, - transfer_amt=transfer_amt, + transfer_amts=transfer_amts, txhash=action_txid, ) dbsync_utils.check_reward_rest( - actions_num=actions_num, stake_address=recv_stake_addr_rec.address, - transfer_amt=transfer_amt, + transfer_amts=transfer_amts, + type="treasury", ) [r.success() for r in (reqc.cip084, reqc.db009, reqc.db022)] diff --git a/cardano_node_tests/utils/dbsync_queries.py b/cardano_node_tests/utils/dbsync_queries.py index 996f574bf..9d7e5ea21 100644 --- a/cardano_node_tests/utils/dbsync_queries.py +++ b/cardano_node_tests/utils/dbsync_queries.py @@ -518,13 +518,16 @@ class NewCommitteeMemberDBRow: @dataclasses.dataclass(frozen=True) class TreasuryWithdrawalDBRow: # pylint: disable-next=invalid-name + id: int + tx_id: int + action_ix: int expiration: int ratified_epoch: int enacted_epoch: int dropped_epoch: int expired_epoch: int addr_view: str - amount: int + amount: decimal.Decimal @dataclasses.dataclass(frozen=True) @@ -1360,7 +1363,7 @@ def query_treasury_withdrawal(txhash: str) -> tp.Generator[TreasuryWithdrawalDBR """Query treasury_withdrawal table in db-sync.""" query = ( "SELECT" - " gap.expiration, gap.ratified_epoch, gap.enacted_epoch, " + " gap.id, gap.tx_id, gap.index, gap.expiration, gap.ratified_epoch, gap.enacted_epoch, " " gap.dropped_epoch, gap.expired_epoch, " " sa.view AS addr_view, tw.amount " "FROM gov_action_proposal AS gap " diff --git a/cardano_node_tests/utils/dbsync_utils.py b/cardano_node_tests/utils/dbsync_utils.py index 5d5bed2b7..e4a2ce2eb 100644 --- a/cardano_node_tests/utils/dbsync_utils.py +++ b/cardano_node_tests/utils/dbsync_utils.py @@ -1229,22 +1229,28 @@ def check_committee_info(gov_state: dict, txid: str, action_ix: int = 0) -> None ), "The number of committee members doesn't match in dbsync" -def check_treasury_withdrawal( - actions_num: int, stake_address: str, transfer_amt: int, txhash: str -) -> None: +def check_treasury_withdrawal(stake_address: str, transfer_amts: tp.List[int], txhash: str) -> None: """Check treasury_withdrawal in db-sync.""" if not configuration.HAS_DBSYNC: return - db_tr_withdrawals = list(dbsync_queries.query_treasury_withdrawal(txhash=txhash)) - assert len(db_tr_withdrawals) == actions_num, ( - f"Assertion failed: Expected {actions_num} records but got {len(db_tr_withdrawals)}." + actions_num = len(transfer_amts) + db_tr_withdrawals = [ + r + for r in dbsync_queries.query_treasury_withdrawal(txhash=txhash) + if r.addr_view == stake_address + ] + db_tr_withdrawals_len = len(db_tr_withdrawals) + assert db_tr_withdrawals_len == actions_num, ( + f"Assertion failed: Expected {actions_num} records but got {db_tr_withdrawals_len}." f"Data in db-sync: {db_tr_withdrawals}" ) + rem_amts = transfer_amts[:] for row in db_tr_withdrawals: - assert row.addr_view == stake_address, "Wrong stake address in db-sync" - assert row.amount == transfer_amt, "Wrong transfer amount in db-sync" + r_amount = int(row.amount) + assert r_amount in rem_amts, "Wrong transfer amount in db-sync" + rem_amts.remove(r_amount) assert row.enacted_epoch, "Action not marked as enacted in db-sync" assert ( row.enacted_epoch == row.ratified_epoch + 1 @@ -1254,24 +1260,29 @@ def check_treasury_withdrawal( ), "Wrong relation between enacted and dropped epochs in db-sync" -def check_reward_rest( - actions_num: int, - stake_address: str, - transfer_amt: int, -) -> None: +def check_reward_rest(stake_address: str, transfer_amts: tp.List[int], type: str = "") -> None: """Check reward_rest in db-sync.""" if not configuration.HAS_DBSYNC: return - db_rewards = list(dbsync_queries.query_address_reward_rest(stake_address)) - assert len(db_rewards) == actions_num, ( - f"Assertion failed: Expected {actions_num} records but got {len(db_rewards)}." + actions_num = len(transfer_amts) + db_rewards = [ + r + for r in dbsync_queries.query_address_reward_rest(stake_address) + if not type or r.type == type + ] + db_rewards_len = len(db_rewards) + assert db_rewards_len >= actions_num, ( + f"Assertion failed: Expected {actions_num} records but got {db_rewards_len}." f"Data in db-sync: {db_rewards}" ) + rem_amts = transfer_amts[:] for row in db_rewards: assert row.address == stake_address, "Wrong stake address in db-sync" - assert row.amount == transfer_amt, "Wrong transfer amount in db-sync" + r_amount = int(row.amount) + assert r_amount in rem_amts, "Wrong transfer amount in db-sync" + rem_amts.remove(r_amount) assert ( row.spendable_epoch == row.earned_epoch + 1 ), "Wrong relation between earned and spendable epochs in db-sync"