Skip to content

Commit c95fb61

Browse files
committed
Basic test
1 parent a944c2a commit c95fb61

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5901e9010000323232323232323232323232322232323232323232323232323374a90001bb1498c8c8ccccd400c01001401840084004030030488888c8c8c94ccd5cd19180d88009980c180aa8012400c2930992999ab9a32301c100133019301650034801052615333573464603820029404c00452613263357389201136e6f7420612076616c696420707572706f7365004988c00852624984004c0454004405840584c98cd5ce2481104e616d654572726f723a207e626f6f6c004984c98cd5ce2481144e616d654572726f723a2076616c696461746f72004984c98cd5ce2481124e616d654572726f723a20707572706f7365004984c98cd5ce2481104e616d654572726f723a20646174756d004984c98cd5ce2481124e616d654572726f723a20636f6e74657874004984c98cd5ce2481144e616d654572726f723a20526577617264696e67004984c98cd5ce2481154e616d654572726f723a2043657274696679696e67004980080088c010c0200048c0140040108c018c94ccd55cf800899319ab9c49010a496e6465784572726f72004984d5d1000800919000a80091aab9d3754002e1c8d55cf1baa00123253335573e002264c66ae712410a496e6465784572726f72004984d5d0800800919ba548018cd5d028009bb14988cdd2a400866ae814004dd8a4c1

integration-test/test/test_certificate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_stake_delegation(self):
2525
builder = TransactionBuilder(self.chain_context)
2626

2727
builder.add_input_address(giver_address)
28-
builder.add_output(TransactionOutput(address, 440000000000))
28+
builder.add_output(TransactionOutput(address, 44000000000))
2929

3030
signed_tx = builder.build_and_sign([self.payment_skey], giver_address)
3131

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import os
2+
import time
3+
4+
import cbor2
5+
from retry import retry
6+
7+
from pycardano import *
8+
9+
from .base import TEST_RETRIES, TestBase
10+
11+
12+
class TestDelegation(TestBase):
13+
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
14+
def test_stake_delegation(self):
15+
with open("./plutus_scripts/pass_certifying_and_rewarding.plutus", "r") as f:
16+
script_hex = f.read()
17+
stake_script = PlutusV2Script(bytes.fromhex(script_hex))
18+
cert_script_hash = plutus_script_hash(stake_script)
19+
address = Address(
20+
self.payment_key_pair.verification_key.hash(),
21+
cert_script_hash,
22+
self.NETWORK,
23+
)
24+
25+
utxos = self.chain_context.utxos(address)
26+
27+
if not utxos:
28+
giver_address = Address(self.payment_vkey.hash(), network=self.NETWORK)
29+
30+
builder = TransactionBuilder(self.chain_context)
31+
32+
builder.add_input_address(giver_address)
33+
builder.add_output(TransactionOutput(address, 44000000000))
34+
35+
signed_tx = builder.build_and_sign([self.payment_skey], giver_address)
36+
37+
print("############### Transaction created ###############")
38+
print(signed_tx)
39+
print(signed_tx.to_cbor_hex())
40+
print("############### Submitting transaction ###############")
41+
self.chain_context.submit_tx(signed_tx)
42+
43+
time.sleep(3)
44+
45+
stake_credential = StakeCredential(cert_script_hash)
46+
stake_registration = StakeRegistration(stake_credential)
47+
pool_hash = PoolKeyHash(bytes.fromhex(os.environ.get("POOL_ID").strip()))
48+
stake_delegation = StakeDelegation(stake_credential, pool_keyhash=pool_hash)
49+
50+
builder = TransactionBuilder(self.chain_context)
51+
52+
builder.add_input_address(address)
53+
builder.add_output(TransactionOutput(address, 35000000))
54+
builder.certificates = [stake_registration, stake_delegation]
55+
redeemer = Redeemer(0)
56+
builder.add_certificate_script(stake_script, redeemer=redeemer)
57+
58+
signed_tx = builder.build_and_sign(
59+
[self.payment_key_pair.signing_key],
60+
address,
61+
)
62+
63+
print("############### Transaction created ###############")
64+
print(signed_tx)
65+
print(signed_tx.to_cbor_hex())
66+
print("############### Submitting transaction ###############")
67+
self.chain_context.submit_tx(signed_tx)
68+
69+
70+
# time.sleep(8)
71+
#
72+
# builder = TransactionBuilder(self.chain_context)
73+
#
74+
# builder.add_input_address(address)
75+
#
76+
# stake_address = Address(
77+
# staking_part=cert_script_hash,
78+
# network=self.NETWORK,
79+
# )
80+
#
81+
# builder.withdrawals = Withdrawals({bytes(stake_address): 0})
82+
#
83+
# builder.add_output(TransactionOutput(address, 1000000))
84+
# redeemer = Redeemer(0)
85+
# builder.add_withdrawal_script(stake_script, redeemer=redeemer)
86+
#
87+
# signed_tx = builder.build_and_sign(
88+
# [self.payment_key_pair.signing_key],
89+
# address,
90+
# )
91+
#
92+
# print("############### Transaction created ###############")
93+
# print(signed_tx)
94+
# print(signed_tx.to_cbor_hex())
95+
# print("############### Submitting transaction ###############")
96+
# self.chain_context.submit_tx(signed_tx)
97+
#

0 commit comments

Comments
 (0)