Skip to content

Commit

Permalink
Update treasury withdrawals test
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturWieczorek committed Jul 22, 2024
1 parent eb3e68b commit 69a2e21
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ def _cast_vote(
transfer_amt=transfer_amt,
txhash=action_txid,
)
dbsync_utils.check_reward_rest(
actions_num=actions_num,
stake_address=recv_stake_addr_rec.address,
transfer_amt=transfer_amt,
)

reqc.cip084.success()

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 @@ -516,7 +516,10 @@ class NewCommitteeMemberDBRow:
class TreasuryWithdrawalDBRow:
# pylint: disable-next=invalid-name
expiration: int
ratified_epoch: int
enacted_epoch: int
dropped_epoch: int
expired_epoch: int
addr_view: str
amount: int

Expand Down Expand Up @@ -1315,10 +1318,12 @@ def query_treasury_withdrawal(txhash: str) -> tp.Generator[TreasuryWithdrawalDBR
"""Query treasury_withdrawal table in db-sync."""
query = (
"SELECT"
" gap.expiration, gap.enacted_epoch, stake_address.view, treasury_withdrawal.amount "
"FROM gov_action_proposal as gap "
"INNER JOIN treasury_withdrawal ON treasury_withdrawal.gov_action_proposal_id = gap.id "
"INNER JOIN stake_address ON treasury_withdrawal.stake_address_id = stake_address.id "
" 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 "
"INNER JOIN treasury_withdrawal AS tw ON tw.gov_action_proposal_id = gap.id "
"INNER JOIN stake_address AS sa ON tw.stake_address_id = sa.id "
"INNER JOIN tx ON tx.id = gap.tx_id "
"WHERE tx.hash = %s;"
)
Expand Down
45 changes: 39 additions & 6 deletions cardano_node_tests/utils/dbsync_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,43 @@ def check_treasury_withdrawal(
if not configuration.HAS_DBSYNC:
return

dbsync_data = list(dbsync_queries.query_treasury_withdrawal(txhash=txhash))
assert len(dbsync_data) == actions_num
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)}."
f"Data in db-sync: {db_tr_withdrawals}"
)

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"
assert row.enacted_epoch, "Action not marked as enacted in db-sync"
assert (
row.enacted_epoch == row.ratified_epoch + 1
), "Wrong relation between enacted and ratified epochs in db-sync"
assert (
row.enacted_epoch == row.dropped_epoch
), "Wrong relation between enacted and dropped epochs in db-sync"


def check_reward_rest(
actions_num: int,
stake_address: str,
transfer_amt: int,
) -> 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)}."
f"Data in db-sync: {db_rewards}"
)

for entry in dbsync_data:
assert entry.addr_view == stake_address, "Wrong stake address on dbsync"
assert entry.amount == transfer_amt, "Wrong transfer amount in dbsync"
assert entry.enacted_epoch, "Action not marked as enacted in dbsync"
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"
assert (
row.spendable_epoch == row.earned_epoch + 1
), "Wrong relation between earned and spendable epochs in db-sync"
assert row.type == "treasury", "Type not marked as treasury in db-sync"

0 comments on commit 69a2e21

Please sign in to comment.