Skip to content

Commit 52d16f2

Browse files
authored
Merge pull request #3148 from IntersectMBO/handle_cip129_drep_id
fix(drep): correct DRep delegation assertion logic
2 parents a90ea09 + 6af8bc8 commit 52d16f2

File tree

2 files changed

+59
-21
lines changed

2 files changed

+59
-21
lines changed

cardano_node_tests/tests/tests_conway/test_drep.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,11 @@ def _deregister():
845845

846846
stake_addr_info = cluster.g_query.get_stake_addr_info(pool_user_rewards.stake.address)
847847

848-
assert stake_addr_info.vote_delegation == governance_utils.get_drep_cred_name(
849-
drep_id=drep1.drep_id
850-
), "Votes are NOT delegated to the correct DRep 1 placed at last of certificates list."
848+
assert governance_utils.get_drep_cred_name_from_addr_info(
849+
addr_info=stake_addr_info
850+
) == governance_utils.get_drep_cred_name(drep_id=drep1.drep_id), (
851+
"Votes are NOT delegated to the correct DRep 1 placed at last of certificates list."
852+
)
851853
reqc.cip087.success()
852854

853855
@allure.link(helpers.get_vcs_link())
@@ -1163,9 +1165,11 @@ def _deregister():
11631165
f"Stake address is NOT registered: {pool_user_rewards.stake.address}"
11641166
)
11651167
reqc.cli035.start(url=helpers.get_vcs_link())
1166-
assert stake_addr_info.vote_delegation == governance_utils.get_drep_cred_name(
1167-
drep_id=drep_id
1168-
), "Votes are NOT delegated to the correct DRep"
1168+
assert governance_utils.get_drep_cred_name_from_addr_info(
1169+
addr_info=stake_addr_info
1170+
) == governance_utils.get_drep_cred_name(drep_id=drep_id), (
1171+
"Votes are NOT delegated to the correct DRep"
1172+
)
11691173
reqc.cli035.success()
11701174

11711175
out_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_output)
@@ -1359,9 +1363,11 @@ def _deregister():
13591363
stake_addr_info = cluster.g_query.get_stake_addr_info(pool_user_wpr.stake.address)
13601364
assert stake_addr_info.delegation, f"Stake address was not delegated yet: {stake_addr_info}"
13611365
assert pool_id == stake_addr_info.delegation, "Stake address delegated to wrong pool"
1362-
assert stake_addr_info.vote_delegation == governance_utils.get_drep_cred_name(
1363-
drep_id=drep_id
1364-
), "Votes are NOT delegated to the correct DRep"
1366+
assert governance_utils.get_drep_cred_name_from_addr_info(
1367+
addr_info=stake_addr_info
1368+
) == governance_utils.get_drep_cred_name(drep_id=drep_id), (
1369+
"Votes are NOT delegated to the correct DRep"
1370+
)
13651371

13661372
# Check the expected balance
13671373
out_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_output)
@@ -1518,9 +1524,11 @@ def _deregister():
15181524
stake_addr_info_deleg1 = cluster.g_query.get_stake_addr_info(
15191525
pool_user_rewards.stake.address
15201526
)
1521-
assert stake_addr_info_deleg1.vote_delegation == governance_utils.get_drep_cred_name(
1522-
drep_id=drep1.drep_id
1523-
), "Votes are NOT delegated to the correct DRep 1"
1527+
assert governance_utils.get_drep_cred_name_from_addr_info(
1528+
addr_info=stake_addr_info_deleg1
1529+
) == governance_utils.get_drep_cred_name(drep_id=drep1.drep_id), (
1530+
"Votes are NOT delegated to the correct DRep 1"
1531+
)
15241532

15251533
# Change delegation to second DRep
15261534

@@ -1549,9 +1557,11 @@ def _deregister():
15491557
stake_addr_info_deleg2 = cluster.g_query.get_stake_addr_info(
15501558
pool_user_rewards.stake.address
15511559
)
1552-
assert stake_addr_info_deleg2.vote_delegation == governance_utils.get_drep_cred_name(
1553-
drep_id=drep2.drep_id
1554-
), "Votes are NOT changed to the correct DRep 2"
1560+
assert governance_utils.get_drep_cred_name_from_addr_info(
1561+
addr_info=stake_addr_info_deleg2
1562+
) == governance_utils.get_drep_cred_name(drep_id=drep2.drep_id), (
1563+
"Votes are NOT changed to the correct DRep 2"
1564+
)
15551565
reqc.cip086.success()
15561566

15571567
# Retire the first DRep
@@ -1588,9 +1598,11 @@ def _deregister():
15881598
else:
15891599
if not stake_addr_info_ret.vote_delegation:
15901600
issues.ledger_4772.finish_test()
1591-
assert stake_addr_info_ret.vote_delegation == governance_utils.get_drep_cred_name(
1592-
drep_id=drep2.drep_id
1593-
), "Votes are no longer delegated to DRep 2!"
1601+
assert governance_utils.get_drep_cred_name_from_addr_info(
1602+
addr_info=stake_addr_info_ret
1603+
) == governance_utils.get_drep_cred_name(drep_id=drep2.drep_id), (
1604+
"Votes are no longer delegated to DRep 2!"
1605+
)
15941606
reqc.int002.success()
15951607

15961608

@@ -1707,9 +1719,11 @@ def _delegate_addr(
17071719
assert stake_addr_info.address, (
17081720
f"Stake address is NOT registered: {pool_user.stake.address}"
17091721
)
1710-
assert stake_addr_info.vote_delegation == governance_utils.get_drep_cred_name(
1711-
drep_id=drep_reg.drep_id
1712-
), "Votes are NOT delegated to the correct DRep"
1722+
assert governance_utils.get_drep_cred_name_from_addr_info(
1723+
addr_info=stake_addr_info
1724+
) == governance_utils.get_drep_cred_name(drep_id=drep_reg.drep_id), (
1725+
"Votes are NOT delegated to the correct DRep"
1726+
)
17131727

17141728
out_utxos = cluster.g_query.get_utxo(tx_raw_output=tx_output)
17151729
assert (

cardano_node_tests/utils/governance_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class AnchorData:
153153

154154

155155
def get_drep_cred_name(drep_id: str) -> str:
156+
if not drep_id:
157+
return ""
156158
cred_name = f"keyHash-{drep_id}"
157159
if drep_id == "always_abstain":
158160
cred_name = "alwaysAbstain"
@@ -162,6 +164,28 @@ def get_drep_cred_name(drep_id: str) -> str:
162164
return cred_name
163165

164166

167+
def get_drep_cred_name_from_addr_info(addr_info: clusterlib.StakeAddrInfo) -> str:
168+
drep_id_raw = addr_info.vote_delegation_hex or addr_info.vote_delegation or ""
169+
if not drep_id_raw:
170+
return ""
171+
172+
# Decode first if working with Bech32 encoded value.
173+
if drep_id_raw.startswith("drep1"):
174+
drep_id_sanitized = helpers.decode_bech32(bech32=drep_id_raw)
175+
else:
176+
# The prefix was already present for the hex value in the older version of cardano-cli.
177+
drep_id_sanitized = drep_id_raw.removeprefix("keyHash-")
178+
179+
if len(drep_id_sanitized) > 56:
180+
drep_id_sanitized = drep_id_sanitized[-56:]
181+
182+
# The DRep ID can be either hex string or special names like "alwaysAbstain".
183+
cred_name = (
184+
f"keyHash-{drep_id_sanitized}" if len(drep_id_sanitized) == 56 else drep_id_sanitized
185+
)
186+
return cred_name
187+
188+
165189
def get_vote_str(vote: clusterlib.Votes) -> str:
166190
if vote == vote.YES:
167191
return "VoteYes"

0 commit comments

Comments
 (0)