Skip to content

Commit dd0e610

Browse files
authored
ci: fix flakiness of snippet tests (hopefully) (#823)
1 parent f1488c1 commit dd0e610

File tree

4 files changed

+48
-46
lines changed

4 files changed

+48
-46
lines changed

.github/workflows/snippet_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
run: poetry install
4949

5050
- name: Run Snippets
51-
run: (for i in snippets/*.py; do echo "Running $i" && poetry run python $i || exit 1; done)
51+
run: (for i in snippets/*.py; do echo "Running $i" && poetry run python $i && sleep 5 || exit 1; done)

snippets/send_escrow.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from xrpl.clients import JsonRpcClient
88
from xrpl.models import AccountObjects, EscrowCreate, EscrowFinish
99
from xrpl.transaction.reliable_submission import submit_and_wait
10-
from xrpl.utils import datetime_to_ripple_time
10+
from xrpl.utils import datetime_to_ripple_time, xrp_to_drops
1111
from xrpl.wallet import generate_faucet_wallet
1212

1313
# References
@@ -19,33 +19,33 @@
1919
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
2020

2121
# Creating two wallets to send money between
22-
wallet1 = generate_faucet_wallet(client, debug=True)
23-
wallet2 = generate_faucet_wallet(client, debug=True)
22+
wallet = generate_faucet_wallet(client, debug=True)
23+
destination = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
2424

2525
# Both balances should be zero since nothing has been sent yet
2626
print("Balances of wallets before Escrow tx was created:")
27-
print(get_balance(wallet1.address, client))
28-
print(get_balance(wallet2.address, client))
27+
print(get_balance(wallet.address, client))
28+
print(get_balance(destination, client))
2929

3030
# Create a finish time (8 seconds from last ledger close)
3131
finish_after = datetime_to_ripple_time(datetime.now()) + 8
3232

3333
# Create an EscrowCreate transaction, then sign, autofill, and send it
3434
create_tx = EscrowCreate(
35-
account=wallet1.address,
36-
destination=wallet2.address,
37-
amount="1000000",
35+
account=wallet.address,
36+
destination=destination,
37+
amount=xrp_to_drops(50),
3838
finish_after=finish_after,
3939
)
4040

41-
create_escrow_response = submit_and_wait(create_tx, client, wallet1)
41+
create_escrow_response = submit_and_wait(create_tx, client, wallet)
4242
print(create_escrow_response)
4343

4444
# Create an AccountObjects request and have the client call it to see if escrow exists
45-
account_objects_request = AccountObjects(account=wallet1.address)
45+
account_objects_request = AccountObjects(account=wallet.address)
4646
account_objects = (client.request(account_objects_request)).result["account_objects"]
4747

48-
print("Escrow object exists in wallet1's account:")
48+
print("Escrow object exists in wallet's account:")
4949
print(account_objects)
5050

5151
print("Waiting for the escrow finish time to pass...")
@@ -54,14 +54,14 @@
5454

5555
# Create an EscrowFinish transaction, then sign, autofill, and send it
5656
finish_tx = EscrowFinish(
57-
account=wallet1.address,
58-
owner=wallet1.address,
57+
account=wallet.address,
58+
owner=wallet.address,
5959
offer_sequence=create_escrow_response.result["tx_json"]["Sequence"],
6060
)
6161

62-
submit_and_wait(finish_tx, client, wallet1)
62+
submit_and_wait(finish_tx, client, wallet)
6363

64-
# If escrow went through successfully, 1000000 exchanged
64+
# If escrow went through successfully, 50 XRP exchanged
6565
print("Balances of wallets after Escrow was sent:")
66-
print(get_balance(wallet1.address, client))
67-
print(get_balance(wallet2.address, client))
66+
print(get_balance(wallet.address, client))
67+
print(get_balance(destination, client))

snippets/set_regular_key.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from xrpl.clients import JsonRpcClient
55
from xrpl.models import Payment, SetRegularKey
66
from xrpl.transaction import submit_and_wait
7-
from xrpl.wallet import generate_faucet_wallet
7+
from xrpl.utils import xrp_to_drops
8+
from xrpl.wallet import Wallet, generate_faucet_wallet
89

910
# References
1011
# - https://xrpl.org/assign-a-regular-key-pair.html#assign-a-regular-key-pair
@@ -15,37 +16,37 @@
1516
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
1617

1718
# Creating two wallets to send money between
18-
wallet1 = generate_faucet_wallet(client, debug=True)
19-
wallet2 = generate_faucet_wallet(client, debug=True)
20-
regular_key_wallet = generate_faucet_wallet(client, debug=True)
19+
wallet = generate_faucet_wallet(client, debug=True)
20+
destination = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
21+
regular_key_wallet = Wallet.create()
2122

2223
# Both balances should be zero since nothing has been sent yet
2324
print("Balances before payment:")
24-
print(get_balance(wallet1.address, client))
25-
print(get_balance(wallet2.address, client))
25+
print(get_balance(wallet.address, client))
26+
print(get_balance(destination, client))
2627

27-
# Assign key pair (regular_key_wallet) to wallet1 using SetRegularKey transaction
28-
tx = SetRegularKey(account=wallet1.address, regular_key=regular_key_wallet.address)
28+
# Assign key pair (regular_key_wallet) to wallet using SetRegularKey transaction
29+
tx = SetRegularKey(account=wallet.address, regular_key=regular_key_wallet.address)
2930

30-
set_regular_key_response = submit_and_wait(tx, client, wallet1)
31+
set_regular_key_response = submit_and_wait(tx, client, wallet)
3132

3233
print("Response for successful SetRegularKey tx:")
3334
print(set_regular_key_response)
3435

35-
# Since regular_key_wallet is linked to wallet1,
36-
# walet1 can send payment to wallet2 and have regular_key_wallet sign it
36+
# Since regular_key_wallet is linked to wallet,
37+
# wallet can send payment to destination and have regular_key_wallet sign it
3738
payment = Payment(
38-
account=wallet1.address,
39-
destination=wallet2.address,
40-
amount="1000",
39+
account=wallet.address,
40+
destination=destination,
41+
amount=xrp_to_drops(50),
4142
)
4243

4344
payment_response = submit_and_wait(payment, client, regular_key_wallet)
4445

4546
print("Response for tx signed using Regular Key:")
4647
print(payment_response)
4748

48-
# Balance after sending 1000 from wallet1 to wallet2
49+
# Balance after sending 50 XRP from wallet1 to wallet2
4950
print("Balances after payment:")
50-
print(get_balance(wallet1.address, client))
51-
print(get_balance(wallet2.address, client))
51+
print(get_balance(wallet.address, client))
52+
print(get_balance(destination, client))

snippets/submit_payment.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from xrpl.clients import JsonRpcClient
55
from xrpl.models import Payment, Tx
66
from xrpl.transaction import submit_and_wait
7+
from xrpl.utils import xrp_to_drops
78
from xrpl.wallet import generate_faucet_wallet
89

910
# References:
@@ -15,24 +16,24 @@
1516
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
1617

1718
# Creating two wallets to send money between
18-
wallet1 = generate_faucet_wallet(client, debug=True)
19-
wallet2 = generate_faucet_wallet(client, debug=True)
19+
wallet = generate_faucet_wallet(client, debug=True)
20+
destination = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
2021

2122
# Both balances should be zero since nothing has been sent yet
2223
print("Balances of wallets before Payment tx")
23-
print(get_balance(wallet1.address, client))
24-
print(get_balance(wallet2.address, client))
24+
print(get_balance(wallet.address, client))
25+
print(get_balance(destination, client))
2526

2627
# Create a Payment transaction
2728
payment_tx = Payment(
28-
account=wallet1.address,
29-
amount="1000",
30-
destination=wallet2.address,
29+
account=wallet.address,
30+
amount=xrp_to_drops(50),
31+
destination=destination,
3132
)
3233

3334
# Signs, autofills, and submits transaction and waits for response
3435
# (validated or rejected)
35-
payment_response = submit_and_wait(payment_tx, client, wallet1)
36+
payment_response = submit_and_wait(payment_tx, client, wallet)
3637
print("Transaction was submitted")
3738

3839
# Create a Transaction request to see transaction
@@ -41,7 +42,7 @@
4142
# Check validated field on the transaction
4243
print("Validated:", tx_response.result["validated"])
4344

44-
# Check balances after 1000 was sent from wallet1 to wallet2
45+
# Check balances after 50 XRP was sent from wallet to destination
4546
print("Balances of wallets after Payment tx:")
46-
print(get_balance(wallet1.address, client))
47-
print(get_balance(wallet2.address, client))
47+
print(get_balance(wallet.address, client))
48+
print(get_balance(destination, client))

0 commit comments

Comments
 (0)