Skip to content

Commit

Permalink
fix code style check script failed (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
sulenn authored Jul 9, 2020
1 parent b9eb818 commit 082c254
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 65 deletions.
18 changes: 9 additions & 9 deletions .ci/check-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SHELL_FOLDER=$(
)

# check_script=gofmt -e -s -w
check_script="goimports -w"
check_script="goimports -d"
commit_limit=2
file_limit=35
insert_limit=800
Expand Down Expand Up @@ -39,17 +39,18 @@ execute_cmd() {
}

function check_codeFormat() {
# Redirect output to stderr.
exec 1>&2
go get golang.org/x/tools/cmd/goimports
sum=0
for file in $(git diff-index --name-status HEAD^ -- | grep -v D | grep -E '\.go' | awk '{print $2}'); do
execute_cmd "$check_script $file"
sum=$(expr ${sum} + $?)
for file in $(git diff-index --name-status HEAD^ | grep -v D | grep -E '\.go' | awk '{print $2}'); do
checkResult=$(eval "${check_script} ${file}")
if [ -n "${checkResult}" ]; then
LOG_ERROR "file ${file} does not meet the format requirements"
echo "${checkResult}"
sum=1
fi
done

if [ ${sum} -ne 0 ]; then
echo "######### ERROR: Format check failed, please adjust them before commit"
LOG_ERROR "######### ERROR: Format check failed, please adjust them before commit"
exit 1
fi
}
Expand Down Expand Up @@ -100,6 +101,5 @@ function check_PR_limit() {
LOG_INFO "modify ${files} files, insert ${insertions} lines, valid insertion ${valid_insertions}, delete ${deletions} lines. Total ${commits} commits."
}

go get golang.org/x/tools/cmd/goimports
check_codeFormat
check_PR_limit
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
fetch-depth: 5
# - uses: actions/cache@v1
# id: cache
# with:
Expand Down
12 changes: 6 additions & 6 deletions client/goclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package client
import (
"context"
"fmt"
helloworld "github.com/FISCO-BCOS/go-sdk/.ci/hello"
"strings"
"testing"

helloworld "github.com/FISCO-BCOS/go-sdk/.ci/hello"
"github.com/FISCO-BCOS/go-sdk/conf"
)

var (
contractAddress = ""
blockHash = "" // get blockHash by TestBlockHashByNumber test case
blockHash = "" // get blockHash by TestBlockHashByNumber test case
transactionHash = ""
)

Expand Down Expand Up @@ -54,7 +54,7 @@ func TestBlockHashByNumber(t *testing.T) {
}

t.Logf("block hash by number:\n%s", raw)
blockHash = strings.Trim(string(raw),"\"")
blockHash = strings.Trim(string(raw), "\"")
}

func TestClientVersion(t *testing.T) {
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestPBFTView(t *testing.T) {
}

func TestBlockLimit(t *testing.T) {
c := GetClient(t)
c := GetClient(t)
// cannot use big.NewInt to construct json request
// TODO: analysis the ethereum's big.NewInt
bl, err := c.GetBlockLimit(context.Background())
Expand All @@ -103,15 +103,15 @@ func TestBlockLimit(t *testing.T) {
}

func TestGroupID(t *testing.T) {
c := GetClient(t)
c := GetClient(t)
// cannot use big.NewInt to construct json request
// TODO: analysis the ethereum's big.NewInt
groupid := c.GetGroupID()
t.Logf("current groupID: \n%s", groupid)
}

func TestChainID(t *testing.T) {
c := GetClient(t)
c := GetClient(t)
// cannot use big.NewInt to construct json request
// TODO: analysis the ethereum's big.NewInt
chainid, err := c.GetChainID(context.Background())
Expand Down
11 changes: 6 additions & 5 deletions precompiled/cns/cns_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cns
import (
"context"
"crypto/ecdsa"
"github.com/FISCO-BCOS/go-sdk/abi/bind"
"testing"

"github.com/FISCO-BCOS/go-sdk/abi/bind"

"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -42,7 +43,7 @@ func GetService(t *testing.T) *Service {
}

const (
name = "store"
name = "store"
version = "5.0"
address = "0x0626918C51A1F36c7ad4354BB1197460A533a2B9"
testABI = `[
Expand Down Expand Up @@ -128,7 +129,7 @@ const (
]`
)

func TestRegisterCns(t *testing.T) {
func TestRegisterCns(t *testing.T) {
c := GetClient(t)
service := GetService(t)
// test RegisterCns
Expand All @@ -144,7 +145,7 @@ func TestRegisterCns(t *testing.T) {
t.Logf("transaction hash: %s\n", receipt.GetTransactionHash())
}

func TestGetAddressByContractNameAndVersion(t *testing.T) {
func TestGetAddressByContractNameAndVersion(t *testing.T) {
service := GetService(t)

// test GetAddressByContractNameAndVersion
Expand All @@ -155,7 +156,7 @@ func TestGetAddressByContractNameAndVersion(t *testing.T) {
t.Logf("address: %s", addr)
}

func TestQueryCnsByNameAndVersion(t *testing.T) {
func TestQueryCnsByNameAndVersion(t *testing.T) {
service := GetService(t)

// test QueryCnsByNameAndVersion
Expand Down
3 changes: 2 additions & 1 deletion precompiled/config/system_config_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package config

import (
"context"
"testing"

"github.com/FISCO-BCOS/go-sdk/abi/bind"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"testing"
)

func TestSetValueByKey(t *testing.T) {
Expand Down
40 changes: 20 additions & 20 deletions precompiled/consensus/consensus_service.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package consensus

import (
"fmt"
"crypto/ecdsa"
"math/big"
"context"
"crypto/ecdsa"
"encoding/json"
"fmt"
"math/big"

"github.com/FISCO-BCOS/go-sdk/client"
"github.com/ethereum/go-ethereum/common"
"github.com/FISCO-BCOS/go-sdk/abi/bind"
"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/core/types"
"github.com/ethereum/go-ethereum/common"
)

// ConsensusService is a precompile contract service.
type ConsensusService struct {
consensus *Consensus
consensus *Consensus
consensusAuth *bind.TransactOpts
client *client.Client
client *client.Client
}

// contract address
Expand All @@ -31,7 +31,7 @@ func NewConsensusService(client *client.Client, privateKey *ecdsa.PrivateKey) (*
}
auth := bind.NewKeyedTransactor(privateKey)
auth.GasLimit = big.NewInt(30000000)
return &ConsensusService{consensus:instance, consensusAuth:auth, client: client}, nil
return &ConsensusService{consensus: instance, consensusAuth: auth, client: client}, nil
}

// AddObserver add a new observe node according to the node ID
Expand All @@ -45,7 +45,7 @@ func (service *ConsensusService) AddObserver(nodeID string) (*types.Transaction,

observerRaw, err := service.client.GetObserverList(context.Background())
if err != nil {
return nil, fmt.Errorf("get the observer list failed: %v", err)
return nil, fmt.Errorf("get the observer list failed: %v", err)
}

var nodeIDs []string
Expand All @@ -60,8 +60,8 @@ func (service *ConsensusService) AddObserver(nodeID string) (*types.Transaction,
}
}
tx, err := service.consensus.AddObserver(service.consensusAuth, nodeID)
if err != nil {
return nil, fmt.Errorf("ConsensusService addObserver failed: %+v", err)
if err != nil {
return nil, fmt.Errorf("ConsensusService addObserver failed: %+v", err)
}
return tx, nil
}
Expand All @@ -77,7 +77,7 @@ func (service *ConsensusService) AddSealer(nodeID string) (*types.Transaction, e

sealerRaw, err := service.client.GetSealerList(context.Background())
if err != nil {
return nil, fmt.Errorf("get the sealer list failed: %v", err)
return nil, fmt.Errorf("get the sealer list failed: %v", err)
}

var nodeIDs []string
Expand All @@ -93,8 +93,8 @@ func (service *ConsensusService) AddSealer(nodeID string) (*types.Transaction, e
}

tx, err := service.consensus.AddSealer(service.consensusAuth, nodeID)
if err != nil {
return nil, fmt.Errorf("ConsensusService addSealer failed: %+v", err)
if err != nil {
return nil, fmt.Errorf("ConsensusService addSealer failed: %+v", err)
}

return tx, nil
Expand All @@ -104,7 +104,7 @@ func (service *ConsensusService) AddSealer(nodeID string) (*types.Transaction, e
func (service *ConsensusService) RemoveNode(nodeID string) (*types.Transaction, error) {
peersRaw, err := service.client.GetGroupPeers(context.Background())
if err != nil {
return nil, fmt.Errorf("get the group peers failed: %v", err)
return nil, fmt.Errorf("get the group peers failed: %v", err)
}

var nodeIDs []string
Expand All @@ -125,10 +125,10 @@ func (service *ConsensusService) RemoveNode(nodeID string) (*types.Transaction,
}

tx, err := service.consensus.Remove(service.consensusAuth, nodeID)
// maybe will occur something wrong
// maybe will occur something wrong
// when request the receipt from the SDK since the connected node of SDK is removed
if err != nil {
return nil, fmt.Errorf("ConsensusService Remove failed: %+v", err)
if err != nil {
return nil, fmt.Errorf("ConsensusService Remove failed: %+v", err)
}
return tx, nil
}
Expand All @@ -138,7 +138,7 @@ func (service *ConsensusService) isValidNodeID(nodeID string) (bool, error) {
var flag = false
nodeIDRaw, err := service.client.GetNodeIDList(context.Background())
if err != nil {
return flag, fmt.Errorf("get the valid Node IDs failed: %v", err)
return flag, fmt.Errorf("get the valid Node IDs failed: %v", err)
}
var nodeIDs []string
err = json.Unmarshal(nodeIDRaw, &nodeIDs)
Expand All @@ -151,4 +151,4 @@ func (service *ConsensusService) isValidNodeID(nodeID string) (bool, error) {
}
}
return flag, nil
}
}
5 changes: 3 additions & 2 deletions precompiled/consensus/consensus_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package consensus
import (
"context"
"crypto/ecdsa"
"github.com/FISCO-BCOS/go-sdk/abi/bind"
"regexp"
"testing"

"github.com/FISCO-BCOS/go-sdk/abi/bind"

"github.com/FISCO-BCOS/go-sdk/client"
"github.com/FISCO-BCOS/go-sdk/conf"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestGetNodeID(t *testing.T) {
}
reg := regexp.MustCompile(`[\w]+`)
nodeList := reg.FindAllString(string(sealerList), -1)
if len(nodeList) < 4 { // pbft consensus needs 2f+1
if len(nodeList) < 4 { // pbft consensus needs 2f+1
t.Fatalf("the number of nodes does not exceed 4")
}
nodeID = nodeList[1]
Expand Down
2 changes: 1 addition & 1 deletion precompiled/crud/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ func (c *Condition) GetConditions() map[string]map[EnumOP]string {

func (c *Condition) SetConditions(newMap map[string]map[EnumOP]string) {
c.conditions = newMap
}
}
3 changes: 1 addition & 2 deletions precompiled/crud/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ type Entry struct {
fields map[string]string
}


func (e *Entry) GetFields() map[string]string {
return e.fields
}
Expand All @@ -19,4 +18,4 @@ func (e *Entry) Put(key string, value string) {

func (e *Entry) Get(key string) string {
return e.fields[key]
}
}
14 changes: 7 additions & 7 deletions precompiled/crud/enumop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package crud
type EnumOP string

const (
EQ EnumOP = "eq"
NE EnumOP = "ne"
GT EnumOP = "gt"
GE EnumOP = "ge"
LT EnumOP = "lt"
LE EnumOP = "le"
EQ EnumOP = "eq"
NE EnumOP = "ne"
GT EnumOP = "gt"
GE EnumOP = "ge"
LT EnumOP = "lt"
LE EnumOP = "le"
Limit EnumOP = "limit"
)
)
14 changes: 7 additions & 7 deletions precompiled/crud/table.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package crud

type Table struct {
TableName string
Key string
ValueFields string
Optional string
TableName string
Key string
ValueFields string
Optional string
}

func (t *Table) GetTableName() string {
Expand Down Expand Up @@ -40,9 +40,9 @@ func (t *Table) SetOptional(optional string) {
}

func (t *Table) GetEntry() *Entry {
return &Entry{fields:make(map[string]string)}
return &Entry{fields: make(map[string]string)}
}

func (t *Table) GetCondition() *Condition {
return &Condition{conditions:make(map[string]map[EnumOP]string)}
}
return &Condition{conditions: make(map[string]map[EnumOP]string)}
}
6 changes: 3 additions & 3 deletions precompiled/permission/permission_info.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package permission

type PermissionInfo struct {
Address string `json:"address"`
EnableNum string `json:"enable_num"`
TableName string `json:"table_name"`
Address string `json:"address"`
EnableNum string `json:"enable_num"`
TableName string `json:"table_name"`
}

func (p *PermissionInfo) GetTableName() string {
Expand Down
Loading

0 comments on commit 082c254

Please sign in to comment.