-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add integration tests for sidechain transactions #571
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7adf985
fix EscrowCreate test
mvadari 4bb3a31
add XChainCreateBridge integration test
mvadari b85b614
add reusable bridge
mvadari 73a74c5
improve XChainCreateBridge test
mvadari 65b63ca
add XChainCreateClaimID integration test
mvadari d281fbe
add XChainCommit integration test
mvadari 97296fd
add XChainAccountCreateCommit integration test
mvadari 81b561c
add XChainModifyBridge integration test
mvadari 1870a6e
add XChainAddAccountCreateAttestation integration test
mvadari 3fabf6b
add XChainAddClaimAttestation integration test
mvadari 8e32f68
fix tests
mvadari b4d599b
add XChainClaim integration test
mvadari b0687df
improve tests
mvadari 83eb04e
fix test name
mvadari a7ab1e1
fix tests
mvadari a67f057
clean up
mvadari c039240
fix rebase issues
mvadari c7b49d9
Merge branch 'main' into sidechain-2.5-integ
mvadari d07f711
Merge branch 'main' into sidechain-2.5-integ
mvadari fa3aff0
make more progress
mvadari 6aed3cb
Merge branch 'main' into sidechain-2.5-integ
mvadari 8fa5ac0
simplify
mvadari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/integration/transactions/test_xchain_account_create_commit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import BRIDGE, WALLET | ||
from xrpl.models import AccountInfo, XChainAccountCreateCommit | ||
from xrpl.wallet import Wallet | ||
|
||
|
||
class TestXChainAccountCreateCommit(IntegrationTestCase): | ||
@test_async_and_sync(globals()) | ||
async def test_basic_functionality(self, client): | ||
locking_chain_door = BRIDGE.xchain_bridge.locking_chain_door | ||
account_info1 = await client.request(AccountInfo(account=locking_chain_door)) | ||
initial_balance = int(account_info1.result["account_data"]["Balance"]) | ||
amount = int(BRIDGE.min_account_create_amount) | ||
|
||
response = await sign_and_reliable_submission_async( | ||
XChainAccountCreateCommit( | ||
account=WALLET.classic_address, | ||
xchain_bridge=BRIDGE.xchain_bridge, | ||
amount=str(amount), | ||
signature_reward=BRIDGE.signature_reward, | ||
destination=Wallet.create().classic_address, | ||
), | ||
WALLET, | ||
client, | ||
) | ||
self.assertTrue(response.is_successful()) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
account_info2 = await client.request(AccountInfo(account=locking_chain_door)) | ||
final_balance = int(account_info2.result["account_data"]["Balance"]) | ||
self.assertEqual( | ||
final_balance, initial_balance + amount + int(BRIDGE.signature_reward) | ||
) |
66 changes: 66 additions & 0 deletions
66
tests/integration/transactions/test_xchain_add_account_create_attestation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import BRIDGE, WITNESS_WALLET | ||
from xrpl.asyncio.account import does_account_exist | ||
from xrpl.core.binarycodec import encode | ||
from xrpl.core.keypairs import sign | ||
from xrpl.models import ( | ||
AccountObjects, | ||
AccountObjectType, | ||
XChainAddAccountCreateAttestation, | ||
) | ||
from xrpl.utils import xrp_to_drops | ||
from xrpl.wallet import Wallet | ||
|
||
|
||
class TestXChainAddAccountCreateAttestation(IntegrationTestCase): | ||
@test_async_and_sync(globals(), ["xrpl.account.does_account_exist"]) | ||
async def test_basic_functionality(self, client): | ||
destination = Wallet.create().classic_address | ||
other_chain_source = Wallet.create().classic_address | ||
self.assertFalse(await does_account_exist(destination, client)) | ||
|
||
account_objects = await client.request( | ||
AccountObjects( | ||
account=BRIDGE.xchain_bridge.locking_chain_door, | ||
type=AccountObjectType.BRIDGE, | ||
) | ||
) | ||
bridge_obj = account_objects.result["account_objects"][0] | ||
|
||
attestation_to_sign = { | ||
"XChainBridge": BRIDGE.to_xrpl()["XChainBridge"], | ||
"OtherChainSource": other_chain_source, | ||
"Amount": xrp_to_drops(300), | ||
"AttestationRewardAccount": WITNESS_WALLET.classic_address, | ||
"WasLockingChainSend": 0, | ||
"XChainAccountCreateCount": int(bridge_obj["XChainAccountClaimCount"]) + 1, | ||
"Destination": destination, | ||
"SignatureReward": BRIDGE.signature_reward, | ||
} | ||
encoded_attestation = encode(attestation_to_sign) | ||
attestation_signature = sign( | ||
bytes.fromhex(encoded_attestation), | ||
WITNESS_WALLET.private_key, | ||
) | ||
|
||
response = await sign_and_reliable_submission_async( | ||
XChainAddAccountCreateAttestation.from_xrpl( | ||
{ | ||
"Account": WITNESS_WALLET.classic_address, | ||
"AttestationSignerAccount": WITNESS_WALLET.classic_address, | ||
**attestation_to_sign, | ||
"PublicKey": WITNESS_WALLET.public_key, | ||
"Signature": attestation_signature, | ||
} | ||
), | ||
WITNESS_WALLET, | ||
client, | ||
) | ||
self.assertTrue(response.is_successful()) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
self.assertTrue(await does_account_exist(destination, client)) |
89 changes: 89 additions & 0 deletions
89
tests/integration/transactions/test_xchain_add_claim_attestation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import BRIDGE, DESTINATION, WITNESS_WALLET | ||
from xrpl.core.binarycodec import encode | ||
from xrpl.core.keypairs import sign | ||
from xrpl.models import AccountInfo, Tx, XChainAddClaimAttestation, XChainCreateClaimID | ||
from xrpl.utils import xrp_to_drops | ||
from xrpl.wallet import Wallet | ||
|
||
|
||
class TestXChainAddClaimAttestation(IntegrationTestCase): | ||
@test_async_and_sync(globals()) | ||
async def test_basic_functionality(self, client): | ||
other_chain_source = Wallet.create().classic_address | ||
|
||
claim_id_response = await sign_and_reliable_submission_async( | ||
XChainCreateClaimID( | ||
account=DESTINATION.classic_address, | ||
xchain_bridge=BRIDGE.xchain_bridge, | ||
signature_reward=BRIDGE.signature_reward, | ||
other_chain_source=other_chain_source, | ||
), | ||
DESTINATION, | ||
client, | ||
) | ||
claim_id_hash = ( | ||
claim_id_response.result.get("tx_json") or claim_id_response.result | ||
)["hash"] | ||
claim_id_tx_response = await client.request(Tx(transaction=claim_id_hash)) | ||
|
||
nodes = claim_id_tx_response.result["meta"]["AffectedNodes"] | ||
created_nodes = [ | ||
node["CreatedNode"] for node in nodes if "CreatedNode" in node.keys() | ||
] | ||
claim_ids_ledger_entries = [ | ||
node | ||
for node in created_nodes | ||
if node["LedgerEntryType"] == "XChainOwnedClaimID" | ||
] | ||
assert len(claim_ids_ledger_entries) == 1, len(claim_ids_ledger_entries) | ||
xchain_claim_id = claim_ids_ledger_entries[0]["NewFields"]["XChainClaimID"] | ||
|
||
account_info1 = await client.request( | ||
AccountInfo(account=DESTINATION.classic_address) | ||
) | ||
initial_balance = int(account_info1.result["account_data"]["Balance"]) | ||
amount = xrp_to_drops(3) | ||
|
||
attestation_to_sign = { | ||
"XChainBridge": BRIDGE.to_xrpl()["XChainBridge"], | ||
"OtherChainSource": other_chain_source, | ||
"Amount": amount, | ||
"AttestationRewardAccount": WITNESS_WALLET.classic_address, | ||
"WasLockingChainSend": 0, | ||
"XChainClaimID": xchain_claim_id, | ||
"Destination": DESTINATION.classic_address, | ||
} | ||
encoded_attestation = encode(attestation_to_sign) | ||
attestation_signature = sign( | ||
bytes.fromhex(encoded_attestation), | ||
WITNESS_WALLET.private_key, | ||
) | ||
|
||
response = await sign_and_reliable_submission_async( | ||
XChainAddClaimAttestation.from_xrpl( | ||
{ | ||
"Account": WITNESS_WALLET.classic_address, | ||
"AttestationSignerAccount": WITNESS_WALLET.classic_address, | ||
**attestation_to_sign, | ||
"PublicKey": WITNESS_WALLET.public_key, | ||
"Signature": attestation_signature, | ||
} | ||
), | ||
WITNESS_WALLET, | ||
client, | ||
) | ||
self.assertTrue(response.is_successful()) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
account_info2 = await client.request( | ||
AccountInfo(account=DESTINATION.classic_address) | ||
) | ||
final_balance = int(account_info2.result["account_data"]["Balance"]) | ||
self.assertEqual( | ||
final_balance, initial_balance + int(amount) - int(BRIDGE.signature_reward) | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this using a different assert than the rest of the testing framework?