Skip to content

Commit

Permalink
CNS-632: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Oct 22, 2023
1 parent 723e53e commit 9c61c38
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 37 deletions.
7 changes: 4 additions & 3 deletions protocol/chainlib/chainproxy/rpcclient/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,11 @@ func (h *handler) handleResponse(msg *JsonrpcMessage) {
// handleCallMsg executes a call message and returns the answer.
func (h *handler) handleCallMsg(ctx *callProc, msg *JsonrpcMessage) *JsonrpcMessage {
start := time.Now()
servedStr := "Served "
switch {
case msg.isEthereumNotification(), msg.isTendermintNotification():
h.handleCall(ctx, msg)
h.log.Debug("Served "+msg.Method, "duration", time.Since(start))
h.log.Debug(servedStr+msg.Method, "duration", time.Since(start))
return nil
case msg.isCall():
resp := h.handleCall(ctx, msg)
Expand All @@ -321,9 +322,9 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *JsonrpcMessage) *JsonrpcMess
if resp.Error.Data != nil {
ctx = append(ctx, "errdata", resp.Error.Data)
}
h.log.Warn("Served "+msg.Method, ctx...)
h.log.Warn(servedStr+msg.Method, ctx...)
} else {
h.log.Debug("Served "+msg.Method, ctx...)
h.log.Debug(servedStr+msg.Method, ctx...)
}
return resp
case msg.hasValidID():
Expand Down
8 changes: 5 additions & 3 deletions protocol/chaintracker/chain_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func NewMockChainFetcher(startBlock, blocksToSave int64) *MockChainFetcher {
return &mockCHainFetcher
}

const startedTestStr = "started test "

func TestChainTracker(t *testing.T) {
tests := []struct {
name string
Expand All @@ -126,7 +128,7 @@ func TestChainTracker(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
utils.LavaFormatInfo("started test " + tt.name)
utils.LavaFormatInfo(startedTestStr + tt.name)
mockChainFetcher := NewMockChainFetcher(1000, tt.mockBlocks)
currentLatestBlockInMock := mockChainFetcher.AdvanceBlock()

Expand Down Expand Up @@ -272,7 +274,7 @@ func TestChainTrackerCallbacks(t *testing.T) {
require.NoError(t, err)
t.Run("one long test", func(t *testing.T) {
for _, tt := range tests {
utils.LavaFormatInfo("started test " + tt.name)
utils.LavaFormatInfo(startedTestStr + tt.name)
callbackCalledFork = false
callbackCalledNewLatest = false
for i := 0; i < int(tt.advancement); i++ {
Expand Down Expand Up @@ -354,7 +356,7 @@ func TestChainTrackerMaintainMemory(t *testing.T) {
require.NoError(t, err)
t.Run("one long test", func(t *testing.T) {
for _, tt := range tests {
utils.LavaFormatInfo("started test " + tt.name)
utils.LavaFormatInfo(startedTestStr + tt.name)
callbackCalledFork = false
for i := 0; i < int(tt.advancement); i++ {
currentLatestBlockInMock = mockChainFetcher.AdvanceBlock()
Expand Down
8 changes: 5 additions & 3 deletions protocol/lavasession/consumer_session_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func createGRPCServer(serverStarted chan struct{}) error {
return nil
}

const providerStr = "provider"

func createPairingList(providerPrefixAddress string, enabled bool) map[uint64]*ConsumerSessionsWithProvider {
cswpList := make(map[uint64]*ConsumerSessionsWithProvider, 0)
pairingEndpoints := make([]*Endpoint, 1)
Expand All @@ -118,7 +120,7 @@ func createPairingList(providerPrefixAddress string, enabled bool) map[uint64]*C
}

cswpList[uint64(p)] = &ConsumerSessionsWithProvider{
PublicLavaAddress: "provider" + providerPrefixAddress + strconv.Itoa(p),
PublicLavaAddress: providerStr + providerPrefixAddress + strconv.Itoa(p),
Endpoints: endpoints,
Sessions: map[int64]*SingleConsumerSession{},
MaxComputeUnits: 200,
Expand Down Expand Up @@ -549,7 +551,7 @@ func TestUpdateAllProviders(t *testing.T) {
require.Equal(t, len(csm.pairingAddresses), numberOfProviders)
require.Equal(t, csm.currentEpoch, uint64(firstEpochHeight)) // verify epoch
for p := 0; p < numberOfProviders; p++ {
require.Contains(t, csm.pairing, "provider"+strconv.Itoa(p)) // verify pairings
require.Contains(t, csm.pairing, providerStr+strconv.Itoa(p)) // verify pairings
}
}

Expand All @@ -565,7 +567,7 @@ func TestUpdateAllProvidersWithSameEpoch(t *testing.T) {
require.Equal(t, len(csm.pairingAddresses), numberOfProviders)
require.Equal(t, csm.currentEpoch, uint64(firstEpochHeight)) // verify epoch
for p := 0; p < numberOfProviders; p++ {
require.Contains(t, csm.pairing, "provider"+strconv.Itoa(p)) // verify pairings
require.Contains(t, csm.pairing, providerStr+strconv.Itoa(p)) // verify pairings
}
}

Expand Down
8 changes: 5 additions & 3 deletions testutil/e2e/protocolE2E.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ func (lt *lavaTest) listenCmdCommand(cmd *exec.Cmd, panicReason string, function
panic(panicReason)
}

const OKstr = " OK"

func (lt *lavaTest) startLava(ctx context.Context) {
command := "./scripts/start_env_dev.sh"
logName := "00_StartLava"
funcName := "startLava"

lt.execCommand(ctx, funcName, logName, command, true)
utils.LavaFormatInfo(funcName + " OK")
utils.LavaFormatInfo(funcName + OKstr)
}

func (lt *lavaTest) checkLava(timeout time.Duration) {
Expand All @@ -196,7 +198,7 @@ func (lt *lavaTest) stakeLava(ctx context.Context) {
funcName := "stakeLava"

lt.execCommand(ctx, funcName, logName, command, true)
utils.LavaFormatInfo(funcName + " OK")
utils.LavaFormatInfo(funcName + OKstr)
}

func (lt *lavaTest) checkStakeLava(
Expand Down Expand Up @@ -319,7 +321,7 @@ func (lt *lavaTest) startJSONRPCProxy(ctx context.Context) {
funcName := "startJSONRPCProxy"

lt.execCommand(ctx, funcName, logName, command, false)
utils.LavaFormatInfo(funcName + " OK")
utils.LavaFormatInfo(funcName + OKstr)
}

func (lt *lavaTest) startJSONRPCProvider(ctx context.Context) {
Expand Down
6 changes: 3 additions & 3 deletions testutil/e2e/proxy/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func createProxyRequest(req *http.Request, hostURL, body string) (proxyRequest *
}
reqUrlStr, err := url.QueryUnescape(reqUrl.String())
if err != nil {
return nil, fmt.Errorf(" ::: XXX ::: Could not QueryUnescape new request ::: " + reqUrl.Host + " ::: " + err.Error())
return nil, fmt.Errorf(" ::: XXX ::: Could not QueryUnescape new request ::: " + reqUrl.Host + dotsStr + err.Error())
}
proxyReq, err := http.NewRequest(req.Method, scheme+":"+reqUrlStr, strings.NewReader(body))
if err != nil {
return nil, fmt.Errorf(" ::: XXX ::: Could not reproduce new request ::: " + reqUrl.Host + " ::: " + err.Error())
return nil, fmt.Errorf(" ::: XXX ::: Could not reproduce new request ::: " + reqUrl.Host + dotsStr + err.Error())
}
proxyReq.Header.Set("Host", req.Host)
proxyReq.Header.Set("X-Forwarded-For", req.RemoteAddr)
Expand All @@ -66,7 +66,7 @@ func sendRequest(request *http.Request) (*http.Response, error) {
proxyRes, err := client.Do(request)
// proxyReq.Header.Set("Content-Length", )
if err != nil {
println(" ::: XXX ::: Reply From Host Error ::: "+request.Host+" ::: ", err.Error())
println(" ::: XXX ::: Reply From Host Error ::: "+request.Host+dotsStr, err.Error())
return nil, err
}
return proxyRes, nil
Expand Down
12 changes: 7 additions & 5 deletions testutil/e2e/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ func idInstertedResponse(val string, replyMessage *rpcInterfaceMessages.JsonrpcM
return fmt.Sprintf("{\"jsonrpc\":\"2.0\",\"id\":%s,\"result\":%s}", respId, string(resultJSON))
}

const dotsStr = " ::: "

func (p proxyProcess) LavaTestProxy(rw http.ResponseWriter, req *http.Request) {
host := p.host
mock := p.mock
Expand All @@ -256,7 +258,7 @@ func (p proxyProcess) LavaTestProxy(rw http.ResponseWriter, req *http.Request) {
// rawBodyS = first + sep + "1," + second

println()
println(" ::: "+p.port+" ::: "+p.id+" ::: INCOMING PROXY MSG :::", rawBodyS)
println(dotsStr+p.port+dotsStr+p.id+" ::: INCOMING PROXY MSG :::", rawBodyS)

var respmsg rpcclient.JsonrpcMessage
if err := json.NewDecoder(req.Body).Decode(&respmsg); err != nil {
Expand All @@ -283,7 +285,7 @@ func (p proxyProcess) LavaTestProxy(rw http.ResponseWriter, req *http.Request) {
rawBodySNoID, _ := json.Marshal(jStruct)
if val, ok := mock.requests[string(rawBodySNoID)]; ok && p.cache {
orderedJSON := idInstertedResponse(val, replyMessage)
println(" ::: "+p.port+" ::: "+p.id+" ::: Cached Response ::: ", orderedJSON)
println(dotsStr+p.port+dotsStr+p.id+" ::: Cached Response ::: ", orderedJSON)
cacheCount += 1

// Change Response
Expand Down Expand Up @@ -317,7 +319,7 @@ func (p proxyProcess) LavaTestProxy(rw http.ResponseWriter, req *http.Request) {
respBodyStr = string(respBody)
mock.requests[rawBodyS] = respBodyStr
realCount += 1
println(" ::: "+p.port+" ::: "+p.id+" ::: Real Response ::: ", respBodyStr)
println(dotsStr+p.port+dotsStr+p.id+" ::: Real Response ::: ", respBodyStr)
}

// Check if response is not good, if not - try again
Expand All @@ -341,7 +343,7 @@ func (p proxyProcess) LavaTestProxy(rw http.ResponseWriter, req *http.Request) {
status = proxyRes.StatusCode
}
realCount += 1
println(" ::: "+p.port+" ::: "+p.id+" ::: Real Response ::: ", string(respBody))
println(dotsStr+p.port+dotsStr+p.id+" ::: Real Response ::: ", string(respBody))

// TODO: Check if response is good, if not - try again
if strings.Contains(string(respBody), "error") || strings.Contains(string(respBody), "Error") {
Expand All @@ -358,7 +360,7 @@ func (p proxyProcess) LavaTestProxy(rw http.ResponseWriter, req *http.Request) {
if fakeResponse {
// respBody = []byte("{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0xe000000000000000000\"}")
respBody = []byte(fakeResult(respBodyStr, "0xe000000000000000000"))
println(" ::: "+p.port+" ::: "+p.id+" ::: Fake Response ::: ", string(respBody))
println(dotsStr+p.port+dotsStr+p.id+" ::: Fake Response ::: ", string(respBody))
fakeCount += 1
}
responsesChanged = true
Expand Down
20 changes: 11 additions & 9 deletions utils/decoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func comment(yaml string, from, count int) string {
return strings.Join(lines, "\n")
}

const keyStr = "key:\n"

func TestDecode(t *testing.T) {
var result mockStruct

Expand All @@ -56,19 +58,19 @@ func TestDecode(t *testing.T) {
require.Error(t, err)

// decode good key
input = "key:\n" + mockDefaultYaml
input = keyStr + mockDefaultYaml
err = Decode(input, "key", &result, nil, nil, nil)
require.NoError(t, err)
require.Equal(t, mockDefault, result)

// decode nested key
input = "nested:\n" + " key:\n" + indent(mockDefaultYaml)
input = "nested:\n" + " " + keyStr + indent(mockDefaultYaml)
err = Decode(input, "nested.key", &result, nil, nil, nil)
require.NoError(t, err)
require.Equal(t, mockDefault, result)

// decode empty value
input = "key:\n"
input = keyStr
err = Decode(input, "key", &result, nil, nil, nil)
require.Error(t, err)

Expand All @@ -83,21 +85,21 @@ func TestDecodeMissing(t *testing.T) {
var unset []string

// decode nothing missing
input := "key:\n" + mockDefaultYaml
input := keyStr + mockDefaultYaml
err := Decode(input, "key", &result, nil, &unset, nil)
require.NoError(t, err)
require.Equal(t, 0, len(unset))
require.Equal(t, mockDefault, result)

// decode 1 missing field
input = "key:\n" + " num: 1\n" + " str: string\n"
input = keyStr + " num: 1\n" + " str: string\n"
err = Decode(input, "key", &result, nil, &unset, nil)
require.NoError(t, err)
require.Equal(t, 1, len(unset))
require.Equal(t, "Bool", unset[0])

// decode 2 missing fields
input = "key:\n" + " num: 1\n"
input = keyStr + " num: 1\n"
err = Decode(input, "key", &result, nil, &unset, nil)
require.NoError(t, err)
require.Equal(t, 2, len(unset))
Expand All @@ -108,7 +110,7 @@ func TestDecodeExtra(t *testing.T) {
var unused []string

// decode nothing extra
input := "key:\n" + mockDefaultYaml
input := keyStr + mockDefaultYaml
err := Decode(input, "key", &result, nil, nil, &unused)
require.NoError(t, err)
require.Equal(t, 0, len(unused))
Expand Down Expand Up @@ -150,7 +152,7 @@ func TestDecodeArray(t *testing.T) {
str: string
bool: True
`
input := "key:\n" + mock1yaml + mock2yaml
input := keyStr + mock1yaml + mock2yaml
err := Decode(input, "key", &results, nil, nil, nil)
require.NoError(t, err)
require.Equal(t, []mockStruct{mock1, mock2}, results)
Expand All @@ -164,7 +166,7 @@ func TestSetDefault(t *testing.T) {
require.NotEqual(t, mockDefault, result)

// decode 2 missing
input := "key:\n" + comment(mockDefaultYaml, 1, 2)
input := keyStr + comment(mockDefaultYaml, 1, 2)
err := Decode(input, "key", &result, nil, &unset, nil)
require.NoError(t, err)
require.Equal(t, 2, len(unset))
Expand Down
3 changes: 2 additions & 1 deletion x/conflict/keeper/msg_server_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lavanet/lava/testutil/common"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/utils/sigs"
conflicttypes "github.com/lavanet/lava/x/conflict/types"
conflictconstruct "github.com/lavanet/lava/x/conflict/types/construct"
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestDetection(t *testing.T) {
if tt.Valid {
events := ts.Ctx.EventManager().Events()
require.Nil(t, err)
require.Equal(t, events[len(events)-1].Type, "lava_"+conflicttypes.ConflictVoteDetectionEventName)
require.Equal(t, events[len(events)-1].Type, utils.EventPrefix+conflicttypes.ConflictVoteDetectionEventName)
}
})
}
Expand Down
9 changes: 5 additions & 4 deletions x/conflict/keeper/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/lavanet/lava/testutil/common"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/utils/rand"
"github.com/lavanet/lava/utils/sigs"
conflicttypes "github.com/lavanet/lava/x/conflict/types"
Expand Down Expand Up @@ -365,7 +366,7 @@ func TestFullMajorityVote(t *testing.T) {

events := ts.Ctx.EventManager().Events()
LastEvent := events[len(events)-1]
require.Equal(t, LastEvent.Type, "lava_"+conflicttypes.ConflictVoteResolvedEventName)
require.Equal(t, LastEvent.Type, utils.EventPrefix+conflicttypes.ConflictVoteResolvedEventName)
}

func TestFullStrongMajorityVote(t *testing.T) {
Expand Down Expand Up @@ -408,7 +409,7 @@ func TestFullStrongMajorityVote(t *testing.T) {

events := ts.Ctx.EventManager().Events()
LastEvent := events[len(events)-1]
require.Equal(t, LastEvent.Type, "lava_"+conflicttypes.ConflictVoteResolvedEventName)
require.Equal(t, LastEvent.Type, utils.EventPrefix+conflicttypes.ConflictVoteResolvedEventName)
}

func TestNoVotersConflict(t *testing.T) {
Expand All @@ -423,7 +424,7 @@ func TestNoVotersConflict(t *testing.T) {

events := ts.Ctx.EventManager().Events()
LastEvent := events[len(events)-1]
require.Equal(t, LastEvent.Type, "lava_"+conflicttypes.ConflictVoteUnresolvedEventName)
require.Equal(t, LastEvent.Type, utils.EventPrefix+conflicttypes.ConflictVoteUnresolvedEventName)
}

func TestNoDecisionVote(t *testing.T) {
Expand Down Expand Up @@ -494,5 +495,5 @@ func TestNoDecisionVote(t *testing.T) {

events := ts.Ctx.EventManager().Events()
LastEvent := events[len(events)-1]
require.Equal(t, "lava_"+conflicttypes.ConflictVoteUnresolvedEventName, LastEvent.Type)
require.Equal(t, utils.EventPrefix+conflicttypes.ConflictVoteUnresolvedEventName, LastEvent.Type)
}
8 changes: 5 additions & 3 deletions x/spec/keeper/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func (ts *tester) expandSpec(spec types.Spec) (types.Spec, error) {
return ts.Keepers.Spec.ExpandSpec(ts.Ctx, spec)
}

const ApiStr = "API-"

// prepareMockApis returns a slice of mock ServiceApi for use in Spec
func prepareMockApis(count int, apiDiff string) []*types.Api {
if count%2 != 0 {
Expand All @@ -50,7 +52,7 @@ func prepareMockApis(count int, apiDiff string) []*types.Api {

for i := 0; i < count/2; i++ {
api := &types.Api{
Name: "API-" + strconv.Itoa(i),
Name: ApiStr + strconv.Itoa(i),
BlockParsing: types.BlockParser{
DefaultValue: apiDiff,
},
Expand All @@ -60,7 +62,7 @@ func prepareMockApis(count int, apiDiff string) []*types.Api {
mockApis[i] = api

api = &types.Api{
Name: "API-" + strconv.Itoa(i+count/2),
Name: ApiStr + strconv.Itoa(i+count/2),
Enabled: false,
BlockParsing: types.BlockParser{
DefaultValue: apiDiff,
Expand All @@ -76,7 +78,7 @@ func prepareMockParsing(count int) []*types.ParseDirective {
mockParsing := make([]*types.ParseDirective, count)

for i := 0; i < count; i++ {
uniqueName := "API-" + strconv.Itoa(i)
uniqueName := ApiStr + strconv.Itoa(i)
api := &types.Api{
Name: uniqueName,
}
Expand Down

0 comments on commit 9c61c38

Please sign in to comment.