From b96218238ee48eb7554b91348c90d8e1b44f43a5 Mon Sep 17 00:00:00 2001 From: Rian Hughes Date: Wed, 25 Oct 2023 05:59:56 +0100 Subject: [PATCH] rpcv05 update traceBlockTransactions() (#428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rpcv05 update traceBlockTransacitons() * fix rpc test --------- Co-authored-by: Carmen Irene Cabrera Rodríguez <49727740+cicr99@users.noreply.github.com> --- account/account.go | 4 ++-- mocks/mock_rpc_provider.go | 8 ++++---- rpc/mock_test.go | 8 ++++---- rpc/provider.go | 2 +- rpc/trace.go | 6 +++--- rpc/trace_test.go | 8 ++++---- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/account/account.go b/account/account.go index 592caec6..99fd2549 100644 --- a/account/account.go +++ b/account/account.go @@ -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) { diff --git a/mocks/mock_rpc_provider.go b/mocks/mock_rpc_provider.go index 7da07caf..2421c7e3 100644 --- a/mocks/mock_rpc_provider.go +++ b/mocks/mock_rpc_provider.go @@ -382,18 +382,18 @@ func (mr *MockRpcProviderMockRecorder) Syncing(ctx interface{}) *gomock.Call { } // TraceBlockTransactions mocks base method. -func (m *MockRpcProvider) TraceBlockTransactions(ctx context.Context, blockHash *felt.Felt) ([]rpc.Trace, error) { +func (m *MockRpcProvider) TraceBlockTransactions(ctx context.Context, blockID rpc.BlockID) ([]rpc.Trace, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TraceBlockTransactions", ctx, blockHash) + ret := m.ctrl.Call(m, "TraceBlockTransactions", ctx, blockID) ret0, _ := ret[0].([]rpc.Trace) ret1, _ := ret[1].(error) return ret0, ret1 } // TraceBlockTransactions indicates an expected call of TraceBlockTransactions. -func (mr *MockRpcProviderMockRecorder) TraceBlockTransactions(ctx, blockHash interface{}) *gomock.Call { +func (mr *MockRpcProviderMockRecorder) TraceBlockTransactions(ctx, blockID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TraceBlockTransactions", reflect.TypeOf((*MockRpcProvider)(nil).TraceBlockTransactions), ctx, blockHash) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TraceBlockTransactions", reflect.TypeOf((*MockRpcProvider)(nil).TraceBlockTransactions), ctx, blockID) } // TransactionByBlockIdAndIndex mocks base method. diff --git a/rpc/mock_test.go b/rpc/mock_test.go index f96492b5..e84b3246 100644 --- a/rpc/mock_test.go +++ b/rpc/mock_test.go @@ -629,7 +629,7 @@ func mock_starknet_getBlockWithTxHashes(result interface{}, method string, args "0x40c82f79dd2bc1953fc9b347a3e7ab40fe218ed5740bf4e120f74e8a3c9ac99", "0x28981b14353a28bc46758dff412ac544d16f2ffc8dde31867855592ea054ab1", }) - if(err != nil){ + if err != nil { return err } @@ -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"` diff --git a/rpc/provider.go b/rpc/provider.go index 119a8e4d..b31bdad4 100644 --- a/rpc/provider.go +++ b/rpc/provider.go @@ -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) diff --git a/rpc/trace.go b/rpc/trace.go index 167c4ee3..d42d0bbe 100644 --- a/rpc/trace.go +++ b/rpc/trace.go @@ -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 diff --git a/rpc/trace_test.go b/rpc/trace_test.go index f75f23cc..69ed9d51 100644 --- a/rpc/trace_test.go +++ b/rpc/trace_test.go @@ -136,7 +136,7 @@ func TestTraceBlockTransactions(t *testing.T) { } type testSetType struct { - BlockHash *felt.Felt + BlockID BlockID ExpectedResp []Trace ExpectedErr *RPCError } @@ -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)