Skip to content
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

Handle pending block case in traceTransaction method #1833

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/starknet-js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: npm ci

- name: Run tests
run: npm test -- rpcProvider.test.ts transactionReceipt.test.ts rpcChannel.test.ts defaultProvider.test.ts contract.test.ts cairo1v2.test.ts cairo1v2_typed.test.ts cairo1.test.ts account.test.ts account.starknetId.test.ts --testNamePattern="^(?!.*traceTransaction|.*declare Sierra 1.5.0).*$"
run: npm test -- rpcProvider.test.ts transactionReceipt.test.ts rpcChannel.test.ts defaultProvider.test.ts contract.test.ts cairo1v2.test.ts cairo1v2_typed.test.ts cairo1.test.ts account.test.ts account.starknetId.test.ts --testNamePattern="^(?!.*declare Sierra 1.5.0).*$"
env:
TEST_RPC_URL: ${{ secrets.TEST_RPC_URL }}
TEST_ACCOUNT_ADDRESS: ${{ secrets.TEST_ACCOUNT_ADDRESS }}
Expand Down
2 changes: 1 addition & 1 deletion clients/gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAddInvokeTx(t *testing.T) {
client := gateway.NewTestClient(t)

t.Run("Correct request", func(t *testing.T) {
invokeTx := "{\"max_fee\":\"0x1\",\"version\":\"0x1\",\"signature\":[],\"nonce\":\"0x1\",\"type\":\"INVOKE\",\"sender_address\":\"0x326e3db4580b94948ca9d1d87fa359f2fa047a31a34757734a86aa4231fb9bb\",\"calldata\":[]}"
invokeTx := `{"max_fee":"0x1","version":"0x1","signature":[],"nonce":"0x1","type":"INVOKE","sender_address":"0x326e3db4580b94948ca9d1d87fa359f2fa047a31a34757734a86aa4231fb9bb","calldata":[]}`

invokeTxByte, err := json.Marshal(invokeTx)
require.NoError(t, err)
Expand Down
21 changes: 17 additions & 4 deletions rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,27 @@
}

func (h *Handler) traceTransaction(ctx context.Context, hash *felt.Felt, v0_6Response bool) (*vm.TransactionTrace, *jsonrpc.Error) {
_, _, blockNumber, err := h.bcReader.Receipt(hash)
_, blockHash, _, err := h.bcReader.Receipt(hash)
if err != nil {
return nil, ErrTxnHashNotFound
}

block, err := h.bcReader.BlockByNumber(blockNumber)
if err != nil {
return nil, ErrBlockNotFound
var block *core.Block
isPendingBlock := blockHash == nil
if isPendingBlock {
var pending blockchain.Pending
pending, err = h.bcReader.Pending()
if err != nil {
// for traceTransaction handlers there is no block not found error
return nil, ErrTxnHashNotFound

Check warning on line 151 in rpc/trace.go

View check run for this annotation

Codecov / codecov/patch

rpc/trace.go#L151

Added line #L151 was not covered by tests
}
block = pending.Block
} else {
block, err = h.bcReader.BlockByHash(blockHash)
if err != nil {
// for traceTransaction handlers there is no block not found error
return nil, ErrTxnHashNotFound

Check warning on line 158 in rpc/trace.go

View check run for this annotation

Codecov / codecov/patch

rpc/trace.go#L158

Added line #L158 was not covered by tests
}
}

txIndex := slices.IndexFunc(block.Transactions, func(tx core.Transaction) bool {
Expand Down
Loading
Loading