Skip to content

Commit

Permalink
feedback and update api
Browse files Browse the repository at this point in the history
  • Loading branch information
countvonzero committed Aug 17, 2023
1 parent 3c0113f commit 0c23579
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions api/grpcserver/mesh_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,10 @@ func (s MeshService) MalfeasanceQuery(ctx context.Context, req *pb.MalfeasanceRe
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

Check warning on line 622 in api/grpcserver/mesh_service.go

View check run for this annotation

Codecov / codecov/patch

api/grpcserver/mesh_service.go#L621-L622

Added lines #L621 - L622 were not covered by tests
if l := len(parsed); l != types.NodeIDSize {
return nil, status.Error(codes.InvalidArgument,
fmt.Sprintf("invalid smesher id length (%d), expected (%d)", l, types.NodeIDSize))
}
id := types.BytesToNodeID(parsed)
proof, err := s.cdb.GetMalfeasanceProof(id)
if err != nil && !errors.Is(err, sql.ErrNotFound) {
Expand Down
9 changes: 8 additions & 1 deletion api/grpcserver/mesh_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/golang/mock/gomock"
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -149,10 +151,15 @@ func TestMeshService_MalfeasanceQuery(t *testing.T) {
nodeID, proof := BallotMalfeasance(t, db)

req := &pb.MalfeasanceRequest{
SmesherHex: hex.EncodeToString(nodeID.Bytes()),
SmesherHex: "0123456789abcdef",
IncludeProof: true,
}
resp, err := client.MalfeasanceQuery(context.Background(), req)
require.Equal(t, status.Code(err), codes.InvalidArgument)
require.Nil(t, resp)

req.SmesherHex = hex.EncodeToString(nodeID.Bytes())
resp, err = client.MalfeasanceQuery(context.Background(), req)
require.NoError(t, err)
require.Equal(t, nodeID, types.BytesToNodeID(resp.Proof.SmesherId.Id))
require.EqualValues(t, layer, resp.Proof.Layer.Number)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/pyroscope-io/pyroscope v0.37.2
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/seehuhn/mt19937 v1.0.0
github.com/spacemeshos/api/release/go v1.18.1-0.20230816145459-03b178b521ff
github.com/spacemeshos/api/release/go v1.19.0
github.com/spacemeshos/economics v0.1.0
github.com/spacemeshos/fixed v0.1.0
github.com/spacemeshos/go-scale v1.1.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hg
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/spacemeshos/api/release/go v1.18.1-0.20230816145459-03b178b521ff h1:zfNegCytNfTLteAsKMtHelEYYOjOU4nO07k3B0X/RMY=
github.com/spacemeshos/api/release/go v1.18.1-0.20230816145459-03b178b521ff/go.mod h1:nC5g7IVRNxF8Kl/Tzvr7cQeYBwHN4sMTVsIEa6Ebtl4=
github.com/spacemeshos/api/release/go v1.19.0 h1:QPt1nUuSVQ4DfZPNsSAuJpjjYlbS9HJhDunE7K8rn08=
github.com/spacemeshos/api/release/go v1.19.0/go.mod h1:nC5g7IVRNxF8Kl/Tzvr7cQeYBwHN4sMTVsIEa6Ebtl4=
github.com/spacemeshos/economics v0.1.0 h1:PJAKbhBKqbbdCYTB29pkmc8sYqK3pKUAiuAvQxuSJEg=
github.com/spacemeshos/economics v0.1.0/go.mod h1:Bz0wRDwCOUP1A6w3cPW6iuUBGME8Tz48sIriYiohsBg=
github.com/spacemeshos/fixed v0.1.0 h1:20KIGvxLlAsuidQrvuwwHe6PrvqeTKzbJIsScbmnUPQ=
Expand Down

0 comments on commit 0c23579

Please sign in to comment.