mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 15:07:24 +00:00
broadcast_tx via grpc
This commit is contained in:
@@ -9,10 +9,37 @@ TESTNAME=$1
|
||||
|
||||
function sendTx() {
|
||||
TX=$1
|
||||
RESPONSE=`curl -s localhost:46657/broadcast_tx_commit?tx=\"$TX\"`
|
||||
CODE=`echo $RESPONSE | jq .result[1].code`
|
||||
ERROR=`echo $RESPONSE | jq .error`
|
||||
ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes
|
||||
if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
|
||||
RESPONSE=`curl -s localhost:46657/broadcast_tx_commit?tx=\"$TX\"`
|
||||
CODE=`echo $RESPONSE | jq .result[1].code`
|
||||
ERROR=`echo $RESPONSE | jq .error`
|
||||
ERROR=$(echo "$ERROR" | tr -d '"') # remove surrounding quotes
|
||||
else
|
||||
RESPONSE=`go run grpc_client.go $TX`
|
||||
echo $RESPONSE | jq . &> /dev/null
|
||||
IS_JSON=$?
|
||||
if [[ "$IS_JSON" != "0" ]]; then
|
||||
ERROR="$RESPONSE"
|
||||
else
|
||||
ERROR="" # reset
|
||||
fi
|
||||
|
||||
if [[ "$RESPONSE" == "{}" ]]; then
|
||||
# protobuf auto adds `omitempty` to everything so code OK and empty data/log
|
||||
# will not even show when marshalled into json
|
||||
# apparently we can use github.com/golang/protobuf/jsonpb to do the marshalling ...
|
||||
CODE=0
|
||||
else
|
||||
# this wont actually work if theres an error ...
|
||||
CODE=`echo $RESPONSE | jq .code`
|
||||
fi
|
||||
#echo "-------"
|
||||
#echo "TX $TX"
|
||||
#echo "RESPONSE $RESPONSE"
|
||||
#echo "CODE $CODE"
|
||||
#echo "ERROR $ERROR"
|
||||
#echo "----"
|
||||
fi
|
||||
}
|
||||
|
||||
# 0 should pass once and get in block, with no error
|
||||
|
||||
36
test/app/grpc_client.go
Normal file
36
test/app/grpc_client.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/tendermint/go-wire"
|
||||
"github.com/tendermint/tendermint/rpc/grpc"
|
||||
)
|
||||
|
||||
var grpcAddr = "tcp://localhost:36656"
|
||||
|
||||
func main() {
|
||||
args := os.Args
|
||||
if len(args) == 1 {
|
||||
fmt.Println("Must enter a transaction to send (hex)")
|
||||
os.Exit(1)
|
||||
}
|
||||
tx := args[1]
|
||||
txBytes, err := hex.DecodeString(tx)
|
||||
if err != nil {
|
||||
fmt.Println("Invalid hex", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
clientGRPC := core_grpc.StartGRPCClient(grpcAddr)
|
||||
res, err := clientGRPC.BroadcastTx(context.Background(), &core_grpc.RequestBroadcastTx{txBytes})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(string(wire.JSONBytes(res)))
|
||||
}
|
||||
@@ -77,6 +77,23 @@ function counter_over_grpc() {
|
||||
kill -9 $pid_counter $pid_tendermint
|
||||
}
|
||||
|
||||
function counter_over_grpc_grpc() {
|
||||
rm -rf $TMROOT
|
||||
tendermint init
|
||||
echo "Starting counter and tendermint"
|
||||
counter --serial --tmsp grpc > /dev/null &
|
||||
pid_counter=$!
|
||||
GRPC_PORT=36656
|
||||
tendermint node --tmsp grpc --grpc_laddr tcp://localhost:$GRPC_PORT > tendermint.log &
|
||||
pid_tendermint=$!
|
||||
sleep 5
|
||||
|
||||
echo "running test"
|
||||
GRPC_BROADCAST_TX=true bash counter_test.sh "Counter over GRPC via GRPC BroadcastTx"
|
||||
|
||||
kill -9 $pid_counter $pid_tendermint
|
||||
}
|
||||
|
||||
cd $GOPATH/src/github.com/tendermint/tendermint/test/app
|
||||
|
||||
case "$1" in
|
||||
@@ -92,6 +109,9 @@ case "$1" in
|
||||
"counter_over_grpc")
|
||||
counter_over_grpc
|
||||
;;
|
||||
"counter_over_grpc_grpc")
|
||||
counter_over_grpc_grpc
|
||||
;;
|
||||
*)
|
||||
echo "Running all"
|
||||
dummy_over_socket
|
||||
@@ -101,5 +121,7 @@ case "$1" in
|
||||
counter_over_socket
|
||||
echo ""
|
||||
counter_over_grpc
|
||||
echo ""
|
||||
counter_over_grpc_grpc
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user