Skip to content

Commit

Permalink
feat: Support for the new, optional diagnostic_events_xdr field on …
Browse files Browse the repository at this point in the history
…the `SorobanServer.send_transaction` method. (#866)
  • Loading branch information
overcat authored Jan 12, 2024
1 parent 6ab765e commit 09d81ec
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release History
### Pending
#### Update
- feat: add `scv.to_void` and `scv.from_void`. ([#863](https://github.com/StellarCN/py-stellar-base/pull/863))
- feat: Support for the new, optional `diagnostic_events_xdr` field on the `SorobanServer.send_transaction` method. ([#866](https://github.com/stellar/java-stellar-sdk/pull/866))

### Version 9.1.3

Expand Down
3 changes: 3 additions & 0 deletions stellar_sdk/soroban_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ class SendTransactionResponse(BaseModel):
more information."""

error_result_xdr: Optional[str] = Field(alias="errorResultXdr", default=None)
diagnostic_events_xdr: Optional[List[str]] = Field(
alias="diagnosticEventsXdr", default=None
)
status: SendTransactionStatus = Field(alias="status")
hash: str = Field(alias="hash")
latest_ledger: int = Field(alias="latestLedger")
Expand Down
32 changes: 32 additions & 0 deletions tests/test_soroban_server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,38 @@ async def test_send_transaction(self):
assert request_data["params"] == {"transaction": transaction.to_xdr()}
assert result["hash"] == transaction.hash_hex()

async def test_send_transaction_error(self):
result = {
"status": "ERROR",
"errorResultXdr": "AAAAAAAAf67////6AAAAAA==",
"diagnosticEventsXdr": [
"AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgr/p6gt6h8MrmSw+WNJnu3+sCP9dHXx7jR8IH0sG6Cy0AAAAPAAAABWhlbGxvAAAAAAAADwAAAAVBbG9oYQAAAA=="
],
"hash": "64977cc4bb7f8bf75bdc47570548a994667899d3319b72f95cb2a64e567ad52c",
"latestLedger": "1479",
"latestLedgerCloseTime": "1690594566",
}
data = {
"jsonrpc": "2.0",
"id": "688dfcf3bcd04f52af4866e98dffe387",
"result": result,
}

transaction = _build_soroban_transaction(None, [])
with aioresponses() as m:
m.post(PRC_URL, payload=data)
async with SorobanServerAsync(PRC_URL) as client:
assert (
await client.send_transaction(transaction)
) == SendTransactionResponse.model_validate(result)

request_data = m.requests[("POST", URL(PRC_URL))][0].kwargs["json"]
assert len(request_data["id"]) == 32
assert request_data["jsonrpc"] == "2.0"
assert request_data["method"] == "sendTransaction"
assert request_data["params"] == {"transaction": transaction.to_xdr()}
assert result["hash"] == transaction.hash_hex()

async def test_soroban_rpc_error_response_raise(self):
data = {
"jsonrpc": "2.0",
Expand Down
31 changes: 31 additions & 0 deletions tests/test_soroban_server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,37 @@ def test_send_transaction(self):
assert request_data["params"] == {"transaction": transaction.to_xdr()}
assert result["hash"] == transaction.hash_hex()

def test_send_transaction_error(self):
result = {
"status": "ERROR",
"errorResultXdr": "AAAAAAAAf67////6AAAAAA==",
"diagnosticEventsXdr": [
"AAAAAQAAAAAAAAAAAAAAAgAAAAAAAAADAAAADwAAAAdmbl9jYWxsAAAAAA0AAAAgr/p6gt6h8MrmSw+WNJnu3+sCP9dHXx7jR8IH0sG6Cy0AAAAPAAAABWhlbGxvAAAAAAAADwAAAAVBbG9oYQAAAA=="
],
"hash": "64977cc4bb7f8bf75bdc47570548a994667899d3319b72f95cb2a64e567ad52c",
"latestLedger": "1479",
"latestLedgerCloseTime": "1690594566",
}
data = {
"jsonrpc": "2.0",
"id": "688dfcf3bcd04f52af4866e98dffe387",
"result": result,
}

transaction = _build_soroban_transaction(None, [])
with requests_mock.Mocker() as m:
m.post(PRC_URL, json=data)
assert SorobanServer(PRC_URL).send_transaction(
transaction
) == SendTransactionResponse.model_validate(result)

request_data = m.last_request.json()
assert len(request_data["id"]) == 32
assert request_data["jsonrpc"] == "2.0"
assert request_data["method"] == "sendTransaction"
assert request_data["params"] == {"transaction": transaction.to_xdr()}
assert result["hash"] == transaction.hash_hex()

def test_soroban_rpc_error_response_raise(self):
data = {
"jsonrpc": "2.0",
Expand Down

0 comments on commit 09d81ec

Please sign in to comment.