Skip to content

Commit

Permalink
Fix get transaction status (0xSpaceShard#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Aug 3, 2022
1 parent 9e491a2 commit a873ae5
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion starknet_devnet/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def get_transaction_status(self, tx_hash: str):

# "block_hash" will only exist after transaction enters ACCEPTED_ON_L2
if transaction.status == TransactionStatus.ACCEPTED_ON_L2 and transaction.block is not None:
status_response["block_hash"] = transaction.block.block_hash
status_response["block_hash"] = hex(transaction.block.block_hash)

# "tx_failure_reason" will only exist if the transaction was rejected.
if transaction.status == TransactionStatus.REJECTED:
Expand Down
19 changes: 19 additions & 0 deletions test/support/schemas/get_transaction_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

{
"$schema": "http:https://json-schema.org/draft-04/schema#",
"title": "Predeployed accounts fixed value response schema",
"type": "object",
"properties": {
"tx_status": {
"$ref": "type/tx_status.json"
},
"block_hash": {
"$ref": "type/hex_string.json"
}
},
"required": ["tx_status"],
"dependentRequired": {
"block_hash": ["tx_status"]
},
"additionalProperties": false
}
6 changes: 6 additions & 0 deletions test/support/schemas/type/hex_string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http:https://json-schema.org/draft-04/schema#",
"title": "Hex String with pattern validation",
"type": "string",
"pattern": "^0x[a-fA-F0-9]+$"
}
8 changes: 8 additions & 0 deletions test/support/schemas/type/tx_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http:https://json-schema.org/draft-04/schema#",
"title": "Must be one of existing transaction statuses",
"type": "string",
"enum": [
"NOT_RECEIVED", "RECEIVED", "PENDING", "REJECTED", "ACCEPTED_ON_L2", "ACCEPTED_ON_L1"
]
}
2 changes: 1 addition & 1 deletion test/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ async def test_deploy_lite():
tx_status = devnet.transactions.get_transaction_status(hex(tx_hash))

assert tx_status["tx_status"] == TransactionStatus.ACCEPTED_ON_L2.name
assert tx_status["block_hash"] == 0
assert tx_status["block_hash"] == '0x0'
27 changes: 27 additions & 0 deletions test/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from starknet_devnet.server import app
from .support.assertions import assert_valid_schema
from .util import devnet_in_background, load_file_content
from .settings import APP_URL

Expand Down Expand Up @@ -162,6 +163,12 @@ def get_state_update(block_hash, block_number):
f"{APP_URL}/feeder_gateway/get_state_update?blockHash={block_hash}&blockNumber={block_number}"
)

def get_transaction_status(tx_hash):
"""Get transaction status"""
response = requests.get(f"{APP_URL}/feeder_gateway/get_transaction_status?transactionHash={tx_hash}")
assert response.status_code == 200
return response.json()

@pytest.mark.deploy
@devnet_in_background()
def test_error_response_deploy_without_calldata():
Expand Down Expand Up @@ -248,3 +255,23 @@ def test_error_response_class_by_hash():
assert resp.status_code == 500
expected_message = f"Class with hash {INVALID_HASH} is not declared"
assert expected_message == error_message

@devnet_in_background()
def test_get_transaction_status():
"""Assert valid response schema"""
#Create Transaction
response = requests.post(f"{APP_URL}/mint", json={
"address": "0x0513493b4Fe460031d445fFACacACf3B19196a05Fd146Ed1609B7248101eF847",
"amount": 1000e18
})
assert response.status_code == 200
tx_hash = response.json().get("tx_hash")

json_response = get_transaction_status(tx_hash)
assert_valid_schema(json_response, "get_transaction_status.json")
assert json_response.get("tx_status") == "ACCEPTED_ON_L2"

invalid_tx_hash = "0x443a8b3ec1f9e0c64"
json_response = get_transaction_status(invalid_tx_hash)
assert_valid_schema(json_response, "get_transaction_status.json")
assert json_response.get("tx_status") == "NOT_RECEIVED"

0 comments on commit a873ae5

Please sign in to comment.