Skip to content

Commit

Permalink
Fix TODOs in #546 (#575)
Browse files Browse the repository at this point in the history
* Switch to default/ocabci: #546 (comment)

* Switch to bcproto/ocbcproto: #546 (comment)

* Switch to bcproto/ocbcproto: #546 (comment)

* Switch to types/octypes: #546 (comment)

* Revert to privvalproto

* Format import

* Add test for codecov
  • Loading branch information
tnasu authored Mar 7, 2023
1 parent 932d950 commit b77283b
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 122 deletions.
29 changes: 14 additions & 15 deletions abci/example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ import (

"golang.org/x/net/context"

abci "github.com/tendermint/tendermint/abci/types"

"github.com/line/ostracon/libs/log"
tmnet "github.com/line/ostracon/libs/net"
"github.com/tendermint/tendermint/abci/types"

abcicli "github.com/line/ostracon/abci/client"
"github.com/line/ostracon/abci/example/code"
"github.com/line/ostracon/abci/example/kvstore"
abciserver "github.com/line/ostracon/abci/server"
"github.com/line/ostracon/abci/types"
ocabci "github.com/line/ostracon/abci/types"
"github.com/line/ostracon/libs/log"
tmnet "github.com/line/ostracon/libs/net"
)

func init() {
Expand All @@ -38,15 +37,15 @@ func TestKVStore(t *testing.T) {

func TestBaseApp(t *testing.T) {
fmt.Println("### Testing BaseApp")
testStream(t, types.NewBaseApplication())
testStream(t, ocabci.NewBaseApplication())
}

func TestGRPC(t *testing.T) {
fmt.Println("### Testing GRPC")
testGRPCSync(t, types.NewGRPCApplication(types.NewBaseApplication()))
testGRPCSync(t, ocabci.NewGRPCApplication(ocabci.NewBaseApplication()))
}

func testStream(t *testing.T, app types.Application) {
func testStream(t *testing.T, app ocabci.Application) {
numDeliverTxs := 20000
socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30))
defer os.Remove(socketFile)
Expand Down Expand Up @@ -78,10 +77,10 @@ func testStream(t *testing.T, app types.Application) {

done := make(chan struct{})
counter := 0
client.SetGlobalCallback(func(req *types.Request, res *types.Response) {
client.SetGlobalCallback(func(req *ocabci.Request, res *ocabci.Response) {
// Process response
switch r := res.Value.(type) {
case *types.Response_DeliverTx:
case *ocabci.Response_DeliverTx:
counter++
if r.DeliverTx.Code != code.CodeTypeOK {
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
Expand All @@ -96,7 +95,7 @@ func testStream(t *testing.T, app types.Application) {
}()
return
}
case *types.Response_Flush:
case *ocabci.Response_Flush:
// ignore
default:
t.Error("Unexpected response type", reflect.TypeOf(res.Value))
Expand All @@ -106,7 +105,7 @@ func testStream(t *testing.T, app types.Application) {
// Write requests
for counter := 0; counter < numDeliverTxs; counter++ {
// Send request
reqRes := client.DeliverTxAsync(abci.RequestDeliverTx{Tx: []byte("test")}, nil)
reqRes := client.DeliverTxAsync(types.RequestDeliverTx{Tx: []byte("test")}, nil)
_ = reqRes
// check err ?

Expand All @@ -130,7 +129,7 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
return tmnet.Connect(addr)
}

func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
func testGRPCSync(t *testing.T, app ocabci.ABCIApplicationServer) {
numDeliverTxs := 2000
socketFile := fmt.Sprintf("/tmp/test-%08x.sock", rand.Int31n(1<<30))
defer os.Remove(socketFile)
Expand Down Expand Up @@ -162,12 +161,12 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
}
})

client := types.NewABCIApplicationClient(conn)
client := ocabci.NewABCIApplicationClient(conn)

// Write requests
for counter := 0; counter < numDeliverTxs; counter++ {
// Send request
response, err := client.DeliverTx(context.Background(), &abci.RequestDeliverTx{Tx: []byte("test")})
response, err := client.DeliverTx(context.Background(), &types.RequestDeliverTx{Tx: []byte("test")})
if err != nil {
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
}
Expand Down
50 changes: 25 additions & 25 deletions blockchain/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"

"github.com/gogo/protobuf/proto"
tmbcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"
bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"

bcproto "github.com/line/ostracon/proto/ostracon/blockchain"
ocbcproto "github.com/line/ostracon/proto/ostracon/blockchain"
"github.com/line/ostracon/types"
)

const (
// NOTE: keep up to date with bcproto.BlockResponse
// NOTE: keep up to date with ocbcproto.BlockResponse
BlockResponseMessagePrefixSize = 4
BlockResponseMessageFieldKeySize = 1
MaxMsgSize = types.MaxBlockSizeBytes +
Expand All @@ -22,19 +22,19 @@ const (

// EncodeMsg encodes a Protobuf message
func EncodeMsg(pb proto.Message) ([]byte, error) {
msg := bcproto.Message{}
msg := ocbcproto.Message{}

switch pb := pb.(type) {
case *tmbcproto.BlockRequest:
msg.Sum = &bcproto.Message_BlockRequest{BlockRequest: pb}
case *bcproto.BlockResponse:
msg.Sum = &bcproto.Message_BlockResponse{BlockResponse: pb}
case *tmbcproto.NoBlockResponse:
msg.Sum = &bcproto.Message_NoBlockResponse{NoBlockResponse: pb}
case *tmbcproto.StatusRequest:
msg.Sum = &bcproto.Message_StatusRequest{StatusRequest: pb}
case *tmbcproto.StatusResponse:
msg.Sum = &bcproto.Message_StatusResponse{StatusResponse: pb}
case *bcproto.BlockRequest:
msg.Sum = &ocbcproto.Message_BlockRequest{BlockRequest: pb}
case *ocbcproto.BlockResponse:
msg.Sum = &ocbcproto.Message_BlockResponse{BlockResponse: pb}
case *bcproto.NoBlockResponse:
msg.Sum = &ocbcproto.Message_NoBlockResponse{NoBlockResponse: pb}
case *bcproto.StatusRequest:
msg.Sum = &ocbcproto.Message_StatusRequest{StatusRequest: pb}
case *bcproto.StatusResponse:
msg.Sum = &ocbcproto.Message_StatusResponse{StatusResponse: pb}
default:
return nil, fmt.Errorf("unknown message type %T", pb)
}
Expand All @@ -49,23 +49,23 @@ func EncodeMsg(pb proto.Message) ([]byte, error) {

// DecodeMsg decodes a Protobuf message.
func DecodeMsg(bz []byte) (proto.Message, error) {
pb := &bcproto.Message{}
pb := &ocbcproto.Message{}

err := proto.Unmarshal(bz, pb)
if err != nil {
return nil, err
}

switch msg := pb.Sum.(type) {
case *bcproto.Message_BlockRequest:
case *ocbcproto.Message_BlockRequest:
return msg.BlockRequest, nil
case *bcproto.Message_BlockResponse:
case *ocbcproto.Message_BlockResponse:
return msg.BlockResponse, nil
case *bcproto.Message_NoBlockResponse:
case *ocbcproto.Message_NoBlockResponse:
return msg.NoBlockResponse, nil
case *bcproto.Message_StatusRequest:
case *ocbcproto.Message_StatusRequest:
return msg.StatusRequest, nil
case *bcproto.Message_StatusResponse:
case *ocbcproto.Message_StatusResponse:
return msg.StatusResponse, nil
default:
return nil, fmt.Errorf("unknown message type %T", msg)
Expand All @@ -79,20 +79,20 @@ func ValidateMsg(pb proto.Message) error {
}

switch msg := pb.(type) {
case *tmbcproto.BlockRequest:
case *bcproto.BlockRequest:
if msg.Height < 0 {
return errors.New("negative Height")
}
case *bcproto.BlockResponse:
case *ocbcproto.BlockResponse:
_, err := types.BlockFromProto(msg.Block)
if err != nil {
return err
}
case *tmbcproto.NoBlockResponse:
case *bcproto.NoBlockResponse:
if msg.Height < 0 {
return errors.New("negative Height")
}
case *tmbcproto.StatusResponse:
case *bcproto.StatusResponse:
if msg.Base < 0 {
return errors.New("negative Base")
}
Expand All @@ -102,7 +102,7 @@ func ValidateMsg(pb proto.Message) error {
if msg.Base > msg.Height {
return fmt.Errorf("base %v cannot be greater than height %v", msg.Base, msg.Height)
}
case *tmbcproto.StatusRequest:
case *bcproto.StatusRequest:
return nil
default:
return fmt.Errorf("unknown message type %T", msg)
Expand Down
Loading

0 comments on commit b77283b

Please sign in to comment.