Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
millken committed Jan 19, 2023
1 parent 4c23599 commit ea83bdf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
33 changes: 8 additions & 25 deletions api/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import (
"strconv"
"time"

"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/go-pkgs/util"
"github.com/iotexproject/iotex-address/address"
"github.com/iotexproject/iotex-proto/golang/iotexapi"
"github.com/iotexproject/iotex-proto/golang/iotextypes"
Expand All @@ -39,7 +37,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/api/logfilter"
apitypes "github.com/iotexproject/iotex-core/api/types"
"github.com/iotexproject/iotex-core/blockchain/block"
Expand Down Expand Up @@ -659,32 +656,18 @@ func (svr *gRPCHandler) ReadContractStorage(ctx context.Context, in *iotexapi.Re

// TraceTransactionStructLogs get trace transaction struct logs
func (svr *gRPCHandler) TraceTransactionStructLogs(ctx context.Context, in *iotexapi.TraceTransactionStructLogsRequest) (*iotexapi.TraceTransactionStructLogsResponse, error) {
actInfo, err := svr.coreService.Action(util.Remove0xPrefix(in.GetActionHash()), false)
if err != nil {
return nil, err
cfg := &logger.Config{
EnableMemory: true,
DisableStack: false,
DisableStorage: false,
EnableReturnData: true,
}
act, err := (&action.Deserializer{}).SetEvmNetworkID(svr.coreService.EVMNetworkID()).ActionToSealedEnvelope(actInfo.Action)
_, _, traces, err := svr.coreService.TraceTransaction(ctx, in.GetActionHash(), cfg)
if err != nil {
return nil, err
}
sc, ok := act.Action().(*action.Execution)
if !ok {
return nil, status.Error(codes.InvalidArgument, "the type of action is not supported")
}
tracer := logger.NewStructLogger(nil)
ctx = protocol.WithVMConfigCtx(ctx, vm.Config{
Debug: true,
Tracer: tracer,
NoBaseFee: true,
})

_, _, err = svr.coreService.SimulateExecution(ctx, act.SenderAddress(), sc)
if err != nil {
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}

structLogs := make([]*iotextypes.TransactionStructLog, 0)
for _, log := range tracer.StructLogs() {
for _, log := range traces.StructLogs() {
var stack []string
for _, s := range log.Stack {
stack = append(stack, s.String())
Expand Down
34 changes: 34 additions & 0 deletions api/web3server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"context"
"encoding/hex"
"fmt"
"io"
Expand All @@ -13,6 +14,7 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/golang/mock/gomock"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
Expand All @@ -29,6 +31,7 @@ import (
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/test/identityset"
"github.com/iotexproject/iotex-core/test/mock/mock_apicoreservice"
"github.com/iotexproject/iotex-core/testutil"
)

func TestGetWeb3Reqs(t *testing.T) {
Expand Down Expand Up @@ -534,3 +537,34 @@ func TestGetNetworkID(t *testing.T) {
func TestEthAccounts(t *testing.T) {

}

func TestTraceTransaction(t *testing.T) {
require := require.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
core := mock_apicoreservice.NewMockCoreService(ctrl)
web3svr := &web3Handler{core, nil}

ctx := context.Background()
tsf, err := action.SignedExecution(identityset.Address(29).String(),
identityset.PrivateKey(29), 1, big.NewInt(0), testutil.TestGasLimit,
big.NewInt(testutil.TestGasPriceInt64), []byte{})
require.NoError(err)
tsfhash, err := tsf.Hash()
require.NoError(err)
receipt := &action.Receipt{Status: 1, BlockHeight: 1, ActionHash: tsfhash, GasConsumed: 100000}
structLogger := &logger.StructLogger{}

core.EXPECT().TraceTransaction(ctx, gomock.Any(), gomock.Any()).AnyTimes().Return([]byte{0x01}, receipt, structLogger, nil)

in := gjson.Parse(`{"params":["` + hex.EncodeToString(tsfhash[:]) + `"]}`)
ret, err := web3svr.traceTransaction(ctx, &in)
require.NoError(err)
rlt, ok := ret.(*debugTraceTransactionResult)
require.True(ok)
require.Equal("0x01", rlt.ReturnValue)
require.False(rlt.Failed)
require.Equal(uint64(100000), rlt.Gas)
require.Empty(rlt.Revert)
require.Equal(0, len(rlt.StructLogs))
}

0 comments on commit ea83bdf

Please sign in to comment.