2024-09-25 12:27:04 +00:00
|
|
|
import uuid
|
2024-10-11 08:08:39 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from conftest import option
|
|
|
|
from constants import user_1, user_2
|
2024-09-25 12:27:04 +00:00
|
|
|
from test_cases import SignalTestCase
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.rpc
|
|
|
|
@pytest.mark.transaction
|
|
|
|
@pytest.mark.wallet
|
|
|
|
class TestTransactionFromRoute(SignalTestCase):
|
|
|
|
await_signals = [
|
|
|
|
"wallet.suggested.routes",
|
|
|
|
"wallet.router.sign-transactions",
|
|
|
|
"wallet.router.sending-transactions-started",
|
|
|
|
"wallet.transaction.status-changed",
|
|
|
|
"wallet.router.transactions-sent"
|
|
|
|
]
|
|
|
|
|
|
|
|
def test_tx_from_route(self):
|
|
|
|
|
|
|
|
_uuid = str(uuid.uuid4())
|
|
|
|
amount_in = "0xde0b6b3a7640000"
|
|
|
|
|
|
|
|
method = "wallet_getSuggestedRoutesAsync"
|
|
|
|
params = [
|
|
|
|
{
|
|
|
|
"uuid": _uuid,
|
|
|
|
"sendType": 0,
|
|
|
|
"addrFrom": user_1.address,
|
|
|
|
"addrTo": user_2.address,
|
|
|
|
"amountIn": amount_in,
|
|
|
|
"amountOut": "0x0",
|
|
|
|
"tokenID": "ETH",
|
|
|
|
"tokenIDIsOwnerToken": False,
|
|
|
|
"toTokenID": "",
|
|
|
|
"disabledFromChainIDs": [10, 42161],
|
|
|
|
"disabledToChainIDs": [10, 42161],
|
|
|
|
"gasFeeMode": 1,
|
|
|
|
"fromLockedAmount": {}
|
|
|
|
}
|
|
|
|
]
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_valid_request(method, params)
|
2024-09-25 12:27:04 +00:00
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
routes = self.signal_client.wait_for_signal("wallet.suggested.routes")
|
2024-09-25 12:27:04 +00:00
|
|
|
assert routes['event']['Uuid'] == _uuid
|
|
|
|
|
|
|
|
method = "wallet_buildTransactionsFromRoute"
|
|
|
|
params = [
|
|
|
|
{
|
|
|
|
"uuid": _uuid,
|
|
|
|
"slippagePercentage": 0
|
|
|
|
}
|
|
|
|
]
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_valid_request(method, params)
|
2024-09-25 12:27:04 +00:00
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
wallet_router_sign_transactions = self.signal_client.wait_for_signal(
|
|
|
|
"wallet.router.sign-transactions")
|
2024-09-25 12:27:04 +00:00
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
assert wallet_router_sign_transactions['event']['signingDetails']['signOnKeycard'] == False
|
|
|
|
transaction_hashes = wallet_router_sign_transactions['event']['signingDetails']['hashes']
|
2024-09-25 12:27:04 +00:00
|
|
|
|
|
|
|
assert transaction_hashes, "Transaction hashes are empty!"
|
|
|
|
|
|
|
|
tx_signatures = {}
|
|
|
|
|
|
|
|
for hash in transaction_hashes:
|
|
|
|
|
|
|
|
method = "wallet_signMessage"
|
|
|
|
params = [
|
|
|
|
hash,
|
|
|
|
user_1.address,
|
|
|
|
option.password
|
|
|
|
]
|
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_valid_request(method, params)
|
2024-09-25 12:27:04 +00:00
|
|
|
|
|
|
|
if response.json()["result"].startswith("0x"):
|
|
|
|
tx_signature = response.json()["result"][2:]
|
|
|
|
|
|
|
|
signature = {
|
|
|
|
"r": tx_signature[:64],
|
|
|
|
"s": tx_signature[64:128],
|
|
|
|
"v": tx_signature[128:]
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_signatures[hash] = signature
|
|
|
|
|
|
|
|
method = "wallet_sendRouterTransactionsWithSignatures"
|
|
|
|
params = [
|
|
|
|
{
|
|
|
|
"uuid": _uuid,
|
|
|
|
"Signatures": tx_signatures
|
|
|
|
}
|
|
|
|
]
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_valid_request(method, params)
|
2024-09-25 12:27:04 +00:00
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
tx_status = self.signal_client.wait_for_signal(
|
|
|
|
"wallet.transaction.status-changed")
|
2024-09-25 12:27:04 +00:00
|
|
|
|
|
|
|
assert tx_status["event"]["chainId"] == 31337
|
|
|
|
assert tx_status["event"]["status"] == "Success"
|
|
|
|
tx_hash = tx_status["event"]["hash"]
|
|
|
|
|
|
|
|
method = "eth_getTransactionByHash"
|
|
|
|
params = [tx_hash]
|
|
|
|
|
2024-10-07 15:40:18 +00:00
|
|
|
response = self.rpc_client.rpc_valid_request(method, params, url=option.anvil_url)
|
2024-09-25 12:27:04 +00:00
|
|
|
tx_details = response.json()["result"]
|
|
|
|
|
|
|
|
assert tx_details["value"] == amount_in
|
|
|
|
assert tx_details["to"] == user_2.address
|
|
|
|
assert tx_details["from"] == user_1.address
|