Skip to content

Commit db56cbe

Browse files
cfflstacmota
andauthored
Fix a few certificates (#423)
* Add account reward summary * Fix certificates * Increase epoch length * cert test bugs fix --------- Co-authored-by: tacmota <[email protected]>
1 parent ba35e9c commit db56cbe

File tree

10 files changed

+259
-74
lines changed

10 files changed

+259
-74
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ coverage.xml
1111
.code
1212
/integration-test/.env
1313
/integration-test/tmp_configs/*
14+
/integration-test/.coverage*

integration-test/configs/local-chang/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
"TestAllegraHardForkAtEpoch": 0,
100100
"TestMaryHardForkAtEpoch": 0,
101101
"TestAlonzoHardForkAtEpoch": 0,
102-
"TestBabbageHardForkAtEpoch": 10,
103-
"TestConwayHardForkAtEpoch": 11,
102+
"TestBabbageHardForkAtEpoch": 4,
103+
"TestConwayHardForkAtEpoch": 5,
104104
"EnableDevelopmentHardForkEras": true,
105105
"ExperimentalProtocolsEnabled": true
106106
}

integration-test/configs/local-chang/shelley-genesis.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
"pools": {},
4747
"stake": {}
4848
},
49-
"epochLength": 4
49+
"epochLength": 10
5050
}

integration-test/docker-compose-chang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ services:
5656
max-file: "10"
5757

5858
ogmios:
59-
image: cardanosolutions/ogmios:v6.11.0
59+
image: cardanosolutions/ogmios:v6.11.2
6060
platform: linux/amd64
6161
environment:
6262
NETWORK: "${NETWORK:-local-alonzo}"

integration-test/test/test_certificate.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,36 @@ def test_stake_delegation(self):
4242
)
4343
stake_registration = StakeRegistration(stake_credential)
4444
pool_hash = PoolKeyHash(bytes.fromhex(os.environ.get("POOL_ID").strip()))
45-
stake_delegation = StakeDelegation(stake_credential, pool_keyhash=pool_hash)
45+
# stake_delegation = StakeDelegation(stake_credential, pool_keyhash=pool_hash)
46+
47+
drep = DRep(
48+
DRepKind.VERIFICATION_KEY_HASH,
49+
self.stake_key_pair.verification_key.hash(),
50+
)
51+
52+
drep_credential = DRepCredential(
53+
self.stake_key_pair.verification_key.hash()
54+
)
55+
56+
anchor = Anchor(
57+
url="https://drep.com",
58+
data_hash=AnchorDataHash((bytes.fromhex("0" * 64))),
59+
)
60+
61+
drep_registration = RegDRepCert(
62+
drep_credential=drep_credential, coin=500000000, anchor=anchor
63+
)
64+
65+
all_in_one_cert = StakeRegistrationAndDelegationAndVoteDelegation(
66+
stake_credential, pool_hash, drep, 1000000
67+
)
4668

4769
builder = TransactionBuilder(self.chain_context)
4870

4971
builder.add_input_address(address)
5072
builder.add_output(TransactionOutput(address, 35000000))
5173

52-
builder.certificates = [stake_registration, stake_delegation]
74+
builder.certificates = [drep_registration, all_in_one_cert]
5375

5476
signed_tx = builder.build_and_sign(
5577
[self.stake_key_pair.signing_key, self.payment_key_pair.signing_key],
@@ -62,7 +84,7 @@ def test_stake_delegation(self):
6284
print("############### Submitting transaction ###############")
6385
self.chain_context.submit_tx(signed_tx)
6486

65-
time.sleep(8)
87+
time.sleep(120)
6688

6789
builder = TransactionBuilder(self.chain_context)
6890

@@ -73,7 +95,15 @@ def test_stake_delegation(self):
7395
network=self.NETWORK,
7496
)
7597

76-
builder.withdrawals = Withdrawals({bytes(stake_address): 0})
98+
rewards = self.chain_context.query_account_reward_summaries(
99+
keys=[stake_address.encode()]
100+
)
101+
102+
stake_address_reward = rewards[stake_address.staking_part.payload.hex()][
103+
"rewards"
104+
]["ada"]["lovelace"]
105+
106+
builder.withdrawals = Withdrawals({bytes(stake_address): stake_address_reward})
77107

78108
builder.add_output(TransactionOutput(address, 1000000))
79109

pycardano/backend/ogmios_v6.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ def utxo_by_tx_id(self, tx_id: str, index: int) -> Optional[UTxO]:
307307
return self._utxo_from_ogmios_result(utxos[0])
308308
return None
309309

310+
def query_account_reward_summaries(
311+
self, scripts: Optional[List[str]] = None, keys: Optional[List[str]] = None
312+
) -> List[dict]:
313+
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
314+
summaries, _ = client.query_reward_account_summaries.execute(
315+
scripts=scripts, keys=keys
316+
)
317+
return summaries
318+
310319
def submit_tx_cbor(self, cbor: Union[bytes, str]):
311320
if isinstance(cbor, bytes):
312321
cbor = cbor.hex()

0 commit comments

Comments
 (0)