Browse Source

lint: s/common.Fmt/fmt.Sprintf

pull/1780/head
Tzu-Jung Lee 8 years ago
parent
commit
1150bbfe36
11 changed files with 43 additions and 39 deletions
  1. +3
    -2
      client/grpc_client.go
  2. +2
    -2
      client/socket_client.go
  3. +2
    -2
      cmd/abci-cli/tmsp-cli.go
  4. +2
    -1
      example/chain_aware/chain_aware_app.go
  5. +9
    -9
      example/counter/counter.go
  6. +2
    -2
      example/dummy/dummy.go
  7. +2
    -1
      example/dummy/dummy_test.go
  8. +8
    -7
      example/dummy/persistent_dummy.go
  9. +4
    -4
      example/example_test.go
  10. +1
    -1
      tests/benchmarks/simple/simple.go
  11. +8
    -8
      tests/test_app/app.go

+ 3
- 2
client/grpc_client.go View File

@ -1,6 +1,7 @@
package abcicli
import (
"fmt"
"net"
"sync"
"time"
@ -50,7 +51,7 @@ RETRY_LOOP:
if cli.mustConnect {
return err
} else {
log.Warn(common.Fmt("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
log.Warn(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
@ -93,7 +94,7 @@ func (cli *grpcClient) StopForError(err error) {
}
cli.mtx.Unlock()
log.Warn(common.Fmt("Stopping abci.grpcClient for error: %v", err.Error()))
log.Warn(fmt.Sprintf("Stopping abci.grpcClient for error: %v", err.Error()))
cli.Stop()
}


+ 2
- 2
client/socket_client.go View File

@ -70,7 +70,7 @@ RETRY_LOOP:
if cli.mustConnect {
return err
} else {
log.Warn(common.Fmt("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
log.Warn(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
@ -109,7 +109,7 @@ func (cli *socketClient) StopForError(err error) {
}
cli.mtx.Unlock()
log.Warn(common.Fmt("Stopping abci.socketClient for error: %v", err.Error()))
log.Warn(fmt.Sprintf("Stopping abci.socketClient for error: %v", err.Error()))
cli.Stop()
}


+ 2
- 2
cmd/abci-cli/tmsp-cli.go View File

@ -244,7 +244,7 @@ func cmdSetOption(c *cli.Context) error {
return errors.New("Command set_option takes 2 arguments (key, value)")
}
res := client.SetOptionSync(args[0], args[1])
rsp := newResponse(res, common.Fmt("%s=%s", args[0], args[1]), false)
rsp := newResponse(res, fmt.Sprintf("%s=%s", args[0], args[1]), false)
printResponse(c, rsp)
return nil
}
@ -284,7 +284,7 @@ func cmdCheckTx(c *cli.Context) error {
// Get application Merkle root hash
func cmdCommit(c *cli.Context) error {
res := client.CommitSync()
rsp := newResponse(res, common.Fmt("0x%X", res.Data), false)
rsp := newResponse(res, fmt.Sprintf("0x%X", res.Data), false)
printResponse(c, rsp)
return nil
}


+ 2
- 1
example/chain_aware/chain_aware_app.go View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
@ -58,7 +59,7 @@ func (app *ChainAwareApplication) Commit() types.Result {
}
func (app *ChainAwareApplication) Query(query []byte) types.Result {
return types.NewResultOK([]byte(common.Fmt("%d,%d", app.beginCount, app.endCount)), "")
return types.NewResultOK([]byte(fmt.Sprintf("%d,%d", app.beginCount, app.endCount)), "")
}
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {


+ 9
- 9
example/counter/counter.go View File

@ -2,9 +2,9 @@ package counter
import (
"encoding/binary"
"fmt"
"github.com/tendermint/abci/types"
common "github.com/tendermint/go-common"
)
type CounterApplication struct {
@ -18,7 +18,7 @@ func NewCounterApplication(serial bool) *CounterApplication {
}
func (app *CounterApplication) Info() types.ResponseInfo {
return types.ResponseInfo{Data: common.Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
return types.ResponseInfo{Data: fmt.Sprintf("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
}
func (app *CounterApplication) SetOption(key string, value string) (log string) {
@ -31,13 +31,13 @@ func (app *CounterApplication) SetOption(key string, value string) (log string)
func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
if app.serial {
if len(tx) > 8 {
return types.ErrEncodingError.SetLog(common.Fmt("Max tx size is 8 bytes, got %d", len(tx)))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx)))
}
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(tx):], tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue != uint64(app.txCount) {
return types.ErrBadNonce.SetLog(common.Fmt("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
}
}
app.txCount += 1
@ -47,13 +47,13 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
func (app *CounterApplication) CheckTx(tx []byte) types.Result {
if app.serial {
if len(tx) > 8 {
return types.ErrEncodingError.SetLog(common.Fmt("Max tx size is 8 bytes, got %d", len(tx)))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx)))
}
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(tx):], tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue < uint64(app.txCount) {
return types.ErrBadNonce.SetLog(common.Fmt("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
}
}
return types.OK
@ -76,10 +76,10 @@ func (app *CounterApplication) Query(query []byte) types.Result {
switch queryStr {
case "hash":
return types.NewResultOK(nil, common.Fmt("%v", app.hashCount))
return types.NewResultOK(nil, fmt.Sprintf("%v", app.hashCount))
case "tx":
return types.NewResultOK(nil, common.Fmt("%v", app.txCount))
return types.NewResultOK(nil, fmt.Sprintf("%v", app.txCount))
}
return types.ErrUnknownRequest.SetLog(common.Fmt("Invalid nonce. Expected hash or tx, got %v", queryStr))
return types.ErrUnknownRequest.SetLog(fmt.Sprintf("Invalid nonce. Expected hash or tx, got %v", queryStr))
}

+ 2
- 2
example/dummy/dummy.go View File

@ -2,10 +2,10 @@ package dummy
import (
"encoding/hex"
"fmt"
"strings"
"github.com/tendermint/abci/types"
common "github.com/tendermint/go-common"
"github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire"
)
@ -20,7 +20,7 @@ func NewDummyApplication() *DummyApplication {
}
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
return types.ResponseInfo{Data: common.Fmt("{\"size\":%v}", app.state.Size())}
return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())}
}
func (app *DummyApplication) SetOption(key string, value string) (log string) {


+ 2
- 1
example/dummy/dummy_test.go View File

@ -2,6 +2,7 @@ package dummy
import (
"bytes"
"fmt"
"io/ioutil"
"sort"
"testing"
@ -107,7 +108,7 @@ func TestValSetChanges(t *testing.T) {
nInit := 5
vals := make([]*types.Validator, total)
for i := 0; i < total; i++ {
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(common.Fmt("test%d", i))).PubKey().Bytes()
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(fmt.Sprintf("test%d", i))).PubKey().Bytes()
power := common.RandInt()
vals[i] = &types.Validator{pubkey, uint64(power)}
}


+ 8
- 7
example/dummy/persistent_dummy.go View File

@ -3,6 +3,7 @@ package dummy
import (
"bytes"
"encoding/hex"
"fmt"
"strconv"
"strings"
@ -135,7 +136,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) {
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
common.Exit(common.Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
common.Exit(fmt.Sprintf("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}
@ -173,7 +174,7 @@ func (app *PersistentDummyApplication) Validators() (validators []*types.Validat
}
func MakeValSetChangeTx(pubkey []byte, power uint64) []byte {
return []byte(common.Fmt("val:%X/%d", pubkey, power))
return []byte(fmt.Sprintf("val:%X/%d", pubkey, power))
}
func isValidatorTx(tx []byte) bool {
@ -188,16 +189,16 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Result {
tx = tx[len(ValidatorSetChangePrefix):]
pubKeyAndPower := strings.Split(string(tx), "/")
if len(pubKeyAndPower) != 2 {
return types.ErrEncodingError.SetLog(common.Fmt("Expected 'pubkey/power'. Got %v", pubKeyAndPower))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower))
}
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1]
pubkey, err := hex.DecodeString(pubkeyS)
if err != nil {
return types.ErrEncodingError.SetLog(common.Fmt("Pubkey (%s) is invalid hex", pubkeyS))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS))
}
power, err := strconv.Atoi(powerS)
if err != nil {
return types.ErrEncodingError.SetLog(common.Fmt("Power (%s) is not an int", powerS))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Power (%s) is not an int", powerS))
}
// update
@ -210,14 +211,14 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
if v.Power == 0 {
// remove validator
if !app.app.state.Has(key) {
return types.ErrUnauthorized.SetLog(common.Fmt("Cannot remove non-existent validator %X", key))
return types.ErrUnauthorized.SetLog(fmt.Sprintf("Cannot remove non-existent validator %X", key))
}
app.app.state.Remove(key)
} else {
// add or update validator
value := bytes.NewBuffer(make([]byte, 0))
if err := types.WriteMessage(v, value); err != nil {
return types.ErrInternalError.SetLog(common.Fmt("Error encoding validator: %v", err))
return types.ErrInternalError.SetLog(fmt.Sprintf("Error encoding validator: %v", err))
}
app.app.state.Set(key, value.Bytes())
}


+ 4
- 4
example/example_test.go View File

@ -41,14 +41,14 @@ func testStream(t *testing.T, app types.Application) {
// Start the listener
server, err := server.NewSocketServer("unix://test.sock", app)
if err != nil {
common.Exit(common.Fmt("Error starting socket server: %v", err.Error()))
common.Exit(fmt.Sprintf("Error starting socket server: %v", err.Error()))
}
defer server.Stop()
// Connect to the socket
client, err := abcicli.NewSocketClient("unix://test.sock", false)
if err != nil {
common.Exit(common.Fmt("Error starting socket client: %v", err.Error()))
common.Exit(fmt.Sprintf("Error starting socket client: %v", err.Error()))
}
client.Start()
defer client.Stop()
@ -114,14 +114,14 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
// Start the listener
server, err := server.NewGRPCServer("unix://test.sock", app)
if err != nil {
common.Exit(common.Fmt("Error starting GRPC server: %v", err.Error()))
common.Exit(fmt.Sprintf("Error starting GRPC server: %v", err.Error()))
}
defer server.Stop()
// Connect to the socket
conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
if err != nil {
common.Exit(common.Fmt("Error dialing GRPC server: %v", err.Error()))
common.Exit(fmt.Sprintf("Error dialing GRPC server: %v", err.Error()))
}
defer conn.Close()


+ 1
- 1
tests/benchmarks/simple/simple.go View File

@ -62,7 +62,7 @@ func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) {
return nil, err
}
if _, ok := resFlush.Value.(*types.Response_Flush); !ok {
return nil, errors.New(common.Fmt("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)))
return nil, errors.New(fmt.Sprintf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)))
}
return res, nil


+ 8
- 8
tests/test_app/app.go View File

@ -46,7 +46,7 @@ func SetOption(client abcicli.Client, key, value string) {
res := client.SetOptionSync(key, value)
_, _, log := res.Code, res.Data, res.Log
if res.IsErr() {
panic(common.Fmt("setting %v=%v: \nlog: %v", key, value, log))
panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
}
}
@ -54,10 +54,10 @@ func Commit(client abcicli.Client, hashExp []byte) {
res := client.CommitSync()
_, data, log := res.Code, res.Data, res.Log
if res.IsErr() {
panic(common.Fmt("committing %v\nlog: %v", log))
panic(fmt.Sprintf("committing %v\nlog: %v", log))
}
if !bytes.Equal(res.Data, hashExp) {
panic(common.Fmt("Commit hash was unexpected. Got %X expected %X",
panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
data, hashExp))
}
}
@ -66,11 +66,11 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, da
res := client.DeliverTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if code != codeExp {
panic(common.Fmt("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
panic(common.Fmt("DeliverTx response data was unexpected. Got %X expected %X",
panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
data, dataExp))
}
}
@ -79,14 +79,14 @@ func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, data
res := client.CheckTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if res.IsErr() {
panic(common.Fmt("checking tx %X: %v\nlog: %v", txBytes, log))
panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
}
if code != codeExp {
panic(common.Fmt("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
panic(common.Fmt("CheckTx response data was unexpected. Got %X expected %X",
panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
data, dataExp))
}
}

Loading…
Cancel
Save