Skip to content

Commit

Permalink
Handle pending block case in traceTransaction methods (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan authored Apr 23, 2024
1 parent c04fa8e commit a9f794f
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 15 deletions.
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) TraceTransactionV0_6(ctx context.Context, hash felt.Felt) (*vm
}

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
}
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
}
}

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

0 comments on commit a9f794f

Please sign in to comment.