Skip to content

Commit

Permalink
rpcv05 update traceBlockTransactions() (#428)
Browse files Browse the repository at this point in the history
* rpcv05 update traceBlockTransacitons()

* fix rpc test

---------

Co-authored-by: Carmen Irene Cabrera Rodríguez <49727740+cicr99@users.noreply.github.com>
  • Loading branch information
rianhughes and cicr99 authored Oct 25, 2023
1 parent 2817c4f commit b962182
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ func (account *Account) Syncing(ctx context.Context) (*rpc.SyncStatus, error) {
return account.provider.Syncing(ctx)
}

func (account *Account) TraceBlockTransactions(ctx context.Context, blockHash *felt.Felt) ([]rpc.Trace, error) {
return account.provider.TraceBlockTransactions(ctx, blockHash)
func (account *Account) TraceBlockTransactions(ctx context.Context, blockID rpc.BlockID) ([]rpc.Trace, error) {
return account.provider.TraceBlockTransactions(ctx, blockID)
}

func (account *Account) TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (rpc.TransactionReceipt, error) {
Expand Down
8 changes: 4 additions & 4 deletions mocks/mock_rpc_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions rpc/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func mock_starknet_getBlockWithTxHashes(result interface{}, method string, args
"0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99",
"0x28981b14353a28bc46758dff412ac544d16f2ffc8dde31867855592ea054ab1",
})
if(err != nil){
if err != nil {
return err
}

Expand Down Expand Up @@ -675,11 +675,11 @@ func mock_starknet_traceBlockTransactions(result interface{}, method string, arg
if len(args) != 1 {
return errWrongArgs
}
blockHash, ok := args[0].(*felt.Felt)
blockID, ok := args[0].(BlockID)
if !ok {
return errors.Wrap(errWrongArgs, fmt.Sprintf("args[0] should be felt, got %T\n", args[0]))
return errors.Wrap(errWrongArgs, fmt.Sprintf("args[0] should be BlockID, got %T\n", args[0]))
}
if blockHash.String() == "0x3ddc3a8aaac071ecdc5d8d0cfbb1dc4fc6a88272bc6c67523c9baaee52a5ea2" {
if blockID.Hash.String() == "0x3ddc3a8aaac071ecdc5d8d0cfbb1dc4fc6a88272bc6c67523c9baaee52a5ea2" {

var rawBlockTrace struct {
Result []Trace `json:"result"`
Expand Down
2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type RpcProvider interface {
StorageAt(ctx context.Context, contractAddress *felt.Felt, key string, blockID BlockID) (string, error)
SpecVersion(ctx context.Context) (string, error)
Syncing(ctx context.Context) (*SyncStatus, error)
TraceBlockTransactions(ctx context.Context, blockHash *felt.Felt) ([]Trace, error)
TraceBlockTransactions(ctx context.Context, blockID BlockID) ([]Trace, error)
TransactionByBlockIdAndIndex(ctx context.Context, blockID BlockID, index uint64) (Transaction, error)
TransactionByHash(ctx context.Context, hash *felt.Felt) (Transaction, error)
TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, error)
Expand Down
6 changes: 3 additions & 3 deletions rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func (provider *Provider) TransactionTrace(ctx context.Context, transactionHash
}

// Retrieve traces for all transactions in the given block
func (provider *Provider) TraceBlockTransactions(ctx context.Context, blockHash *felt.Felt) ([]Trace, error) {
func (provider *Provider) TraceBlockTransactions(ctx context.Context, blockID BlockID) ([]Trace, error) {
var output []Trace
if err := do(ctx, provider.c, "starknet_traceBlockTransactions", &output, blockHash); err != nil {
return nil, tryUnwrapToRPCErr(err, ErrInvalidBlockHash)
if err := do(ctx, provider.c, "starknet_traceBlockTransactions", &output, blockID); err != nil {
return nil, tryUnwrapToRPCErr(err, ErrBlockNotFound)
}
return output, nil

Expand Down
8 changes: 4 additions & 4 deletions rpc/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestTraceBlockTransactions(t *testing.T) {
}

type testSetType struct {
BlockHash *felt.Felt
BlockID BlockID
ExpectedResp []Trace
ExpectedErr *RPCError
}
Expand All @@ -145,19 +145,19 @@ func TestTraceBlockTransactions(t *testing.T) {
"mainnet": {},
"mock": {
testSetType{
BlockHash: utils.TestHexToFelt(t, "0x3ddc3a8aaac071ecdc5d8d0cfbb1dc4fc6a88272bc6c67523c9baaee52a5ea2"),
BlockID: BlockID{Hash: utils.TestHexToFelt(t, "0x3ddc3a8aaac071ecdc5d8d0cfbb1dc4fc6a88272bc6c67523c9baaee52a5ea2")},
ExpectedResp: expectedResp,
ExpectedErr: nil,
},
testSetType{
BlockHash: utils.TestHexToFelt(t, "0x0"),
BlockID: BlockID{Hash: utils.TestHexToFelt(t, "0x0")},
ExpectedResp: nil,
ExpectedErr: ErrInvalidBlockHash,
}},
}[testEnv]

for _, test := range testSet {
resp, err := testConfig.provider.TraceBlockTransactions(context.Background(), test.BlockHash)
resp, err := testConfig.provider.TraceBlockTransactions(context.Background(), test.BlockID)

if err != nil {
require.Equal(t, test.ExpectedErr, err)
Expand Down

0 comments on commit b962182

Please sign in to comment.