Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix issues reported by go vet #2952

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gno.land/pkg/gnoweb/gnoweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
// decode path for non-ascii characters
decodedPath, err := url.PathUnescape(path)
if err != nil {
logger.Error("failed to decode path", err)
logger.Error("failed to decode path", "error", err)

Check warning on line 479 in gno.land/pkg/gnoweb/gnoweb.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoweb/gnoweb.go#L479

Added line #L479 was not covered by tests
decodedPath = path
}
w.WriteHeader(http.StatusNotFound)
Expand All @@ -491,7 +491,7 @@
if details := errors.Unwrap(err); details != nil {
logger.Error("handler", "error", err, "details", details)
} else {
logger.Error("handler", "error:", err)
logger.Error("handler", "error", err)

Check warning on line 494 in gno.land/pkg/gnoweb/gnoweb.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoweb/gnoweb.go#L494

Added line #L494 was not covered by tests
}

// XXX: writeError should return an error page template.
Expand Down
4 changes: 2 additions & 2 deletions gno.land/pkg/sdk/vm/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@

func (bnk *SDKBanker) IssueCoin(b32addr crypto.Bech32Address, denom string, amount int64) {
addr := crypto.MustAddressFromString(string(b32addr))
_, err := bnk.vmk.bank.AddCoins(bnk.ctx, addr, std.Coins{std.Coin{denom, amount}})
_, err := bnk.vmk.bank.AddCoins(bnk.ctx, addr, std.Coins{std.Coin{Denom: denom, Amount: amount}})

Check warning on line 45 in gno.land/pkg/sdk/vm/builtins.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/builtins.go#L45

Added line #L45 was not covered by tests
if err != nil {
panic(err)
}
}

func (bnk *SDKBanker) RemoveCoin(b32addr crypto.Bech32Address, denom string, amount int64) {
addr := crypto.MustAddressFromString(string(b32addr))
_, err := bnk.vmk.bank.SubtractCoins(bnk.ctx, addr, std.Coins{std.Coin{denom, amount}})
_, err := bnk.vmk.bank.SubtractCoins(bnk.ctx, addr, std.Coins{std.Coin{Denom: denom, Amount: amount}})

Check warning on line 53 in gno.land/pkg/sdk/vm/builtins.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/builtins.go#L53

Added line #L53 was not covered by tests
if err != nil {
panic(err)
}
Expand Down
18 changes: 9 additions & 9 deletions gno.land/pkg/sdk/vm/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestVMKeeperOrigSend1(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

import "std"
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestVMKeeperOrigSend2(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

import "std"
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestVMKeeperOrigSend3(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

import "std"
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestVMKeeperRealmSend1(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

import "std"
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestVMKeeperRealmSend2(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

import "std"
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestVMKeeperOrigCallerInit(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

import "std"
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestVMKeeperRunSimple(t *testing.T) {
env.acck.SetAccount(ctx, acc)

files := []*std.MemFile{
{"script.gno", `
{Name: "script.gno", Body: `
package main

func main() {
Expand Down Expand Up @@ -402,7 +402,7 @@ func testVMKeeperRunImportStdlibs(t *testing.T, env testEnv) {
env.acck.SetAccount(ctx, acc)

files := []*std.MemFile{
{"script.gno", `
{Name: "script.gno", Body: `
package main

import "std"
Expand Down Expand Up @@ -474,7 +474,7 @@ func TestVMKeeperReinitialize(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test

func Echo(msg string) string {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnomod/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (in *input) readToken() {

// Otherwise, save comment for later attachment to syntax tree.
in.endToken(_EOLCOMMENT)
in.comments = append(in.comments, modfile.Comment{in.token.pos, in.token.text, suffix})
in.comments = append(in.comments, modfile.Comment{Start: in.token.pos, Token: in.token.text, Suffix: suffix})
return
}

Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@

func (tb *testBanker) IssueCoin(addr crypto.Bech32Address, denom string, amt int64) {
coins, _ := tb.coinTable[addr]
sum := coins.Add(std.Coins{{denom, amt}})
sum := coins.Add(std.Coins{{Denom: denom, Amount: amt}})

Check warning on line 600 in gnovm/tests/file.go

View check run for this annotation

Codecov / codecov/patch

gnovm/tests/file.go#L600

Added line #L600 was not covered by tests
tb.coinTable[addr] = sum
}

func (tb *testBanker) RemoveCoin(addr crypto.Bech32Address, denom string, amt int64) {
coins, _ := tb.coinTable[addr]
rest := coins.Sub(std.Coins{{denom, amt}})
rest := coins.Sub(std.Coins{{Denom: denom, Amount: amt}})

Check warning on line 606 in gnovm/tests/file.go

View check run for this annotation

Codecov / codecov/patch

gnovm/tests/file.go#L606

Added line #L606 was not covered by tests
tb.coinTable[addr] = rest
}
2 changes: 1 addition & 1 deletion misc/logos/cmd/logos.go
thehowl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func makeTestPage() *logos.BufferedElemView {
// make a buffered page.
ts := makeTestString()
style := logos.DefaultStyle()
style.Padding = logos.Padding{2, 2, 2, 2}
style.Padding = logos.Padding{Left: 2, Top: 2, Right: 2, Bottom: 2}
style.Border = logos.DefaultBorder()
// TODO width shouldn't matter.
page := logos.NewPage(ts, 84, true, style)
Expand Down
1 change: 0 additions & 1 deletion tm2/pkg/amino/wellknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func isJSONWellKnownType(rt reflect.Type) (wellKnown bool) {
default:
return false
}
return false
}

// Returns ok=false if nothing was done because the default behavior is fine (or if err).
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/abci/example/kvstore/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func RandVal(i int) abci.ValidatorUpdate {
pubkey := ed25519.GenPrivKey().PubKey()
power := random.RandUint16() + 1
v := abci.ValidatorUpdate{pubkey.Address(), pubkey, int64(power)}
v := abci.ValidatorUpdate{Address: pubkey.Address(), PubKey: pubkey, Power: int64(power)}
return v
}

Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) (res abci.Re
}

// update
return app.updateValidator(abci.ValidatorUpdate{pubkey.Address(), pubkey, power})
return app.updateValidator(abci.ValidatorUpdate{Address: pubkey.Address(), PubKey: pubkey, Power: power})
}

// add, update, or remove a validator
Expand Down
22 changes: 11 additions & 11 deletions tm2/pkg/bft/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
if ti == nil {
return cstypes.HRS{}
} else {
return cstypes.HRS{ti.Height, ti.Round, ti.Step}
return cstypes.HRS{Height: ti.Height, Round: ti.Round, Step: ti.Step}

Check warning on line 76 in tm2/pkg/bft/consensus/state.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/consensus/state.go#L76

Added line #L76 was not covered by tests
}
}

Expand Down Expand Up @@ -746,13 +746,13 @@
case cstypes.RoundStepNewRound:
cs.enterPropose(ti.Height, 0)
case cstypes.RoundStepPropose:
cs.evsw.FireEvent(cstypes.EventTimeoutPropose{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventTimeoutPropose{HRS: cs.RoundState.GetHRS()})
cs.enterPrevote(ti.Height, ti.Round)
case cstypes.RoundStepPrevoteWait:
cs.evsw.FireEvent(cstypes.EventTimeoutWait{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventTimeoutWait{HRS: cs.RoundState.GetHRS()})
cs.enterPrecommit(ti.Height, ti.Round)
case cstypes.RoundStepPrecommitWait:
cs.evsw.FireEvent(cstypes.EventTimeoutWait{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventTimeoutWait{HRS: cs.RoundState.GetHRS()})
cs.enterPrecommit(ti.Height, ti.Round)
cs.enterNewRound(ti.Height, ti.Round+1)
default:
Expand Down Expand Up @@ -1126,7 +1126,7 @@
}

// At this point +2/3 prevoted for a particular block or nil.
cs.evsw.FireEvent(cstypes.EventPolka{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventPolka{HRS: cs.RoundState.GetHRS()})

// the latest POLRound should be this round.
polRound, _ := cs.Votes.POLInfo()
Expand All @@ -1143,7 +1143,7 @@
cs.LockedRound = -1
cs.LockedBlock = nil
cs.LockedBlockParts = nil
cs.evsw.FireEvent(cstypes.EventUnlock{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventUnlock{HRS: cs.RoundState.GetHRS()})

Check warning on line 1146 in tm2/pkg/bft/consensus/state.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/consensus/state.go#L1146

Added line #L1146 was not covered by tests
}
cs.signAddVote(types.PrecommitType, nil, types.PartSetHeader{})
return
Expand All @@ -1155,7 +1155,7 @@
if cs.LockedBlock.HashesTo(blockID.Hash) {
logger.Info("enterPrecommit: +2/3 prevoted locked block. Relocking")
cs.LockedRound = round
cs.evsw.FireEvent(cstypes.EventRelock{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventRelock{HRS: cs.RoundState.GetHRS()})
cs.signAddVote(types.PrecommitType, blockID.Hash, blockID.PartsHeader)
return
}
Expand All @@ -1170,7 +1170,7 @@
cs.LockedRound = round
cs.LockedBlock = cs.ProposalBlock
cs.LockedBlockParts = cs.ProposalBlockParts
cs.evsw.FireEvent(cstypes.EventLock{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventLock{HRS: cs.RoundState.GetHRS()})
cs.signAddVote(types.PrecommitType, blockID.Hash, blockID.PartsHeader)
return
}
Expand All @@ -1186,7 +1186,7 @@
cs.ProposalBlock = nil
cs.ProposalBlockParts = types.NewPartSetFromHeader(blockID.PartsHeader)
}
cs.evsw.FireEvent(cstypes.EventUnlock{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventUnlock{HRS: cs.RoundState.GetHRS()})
cs.signAddVote(types.PrecommitType, nil, types.PartSetHeader{})
}

Expand Down Expand Up @@ -1591,7 +1591,7 @@
return
}

cs.evsw.FireEvent(types.EventVote{vote})
cs.evsw.FireEvent(types.EventVote{Vote: vote})

switch vote.Type {
case types.PrevoteType:
Expand Down Expand Up @@ -1620,7 +1620,7 @@
cs.LockedRound = -1
cs.LockedBlock = nil
cs.LockedBlockParts = nil
cs.evsw.FireEvent(cstypes.EventUnlock{cs.RoundState.GetHRS()})
cs.evsw.FireEvent(cstypes.EventUnlock{HRS: cs.RoundState.GetHRS()})
}

// Update Valid* if we can.
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/consensus/wal_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (w *heightStopWAL) Write(m walm.WALMessage) error {
}

w.logger.Debug("WAL Write Message", "msg", m)
err := w.enc.Write(walm.TimedWALMessage{fixedTime, m})
err := w.enc.Write(walm.TimedWALMessage{Time: fixedTime, Msg: m})
if err != nil {
panic(fmt.Sprintf("failed to encode the msg %v", m))
}
Expand Down
6 changes: 3 additions & 3 deletions tm2/pkg/bft/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var validatorPubKeyTypeURLs = map[string]struct{}{

func DefaultConsensusParams() abci.ConsensusParams {
return abci.ConsensusParams{
DefaultBlockParams(),
DefaultValidatorParams(),
Block: DefaultBlockParams(),
Validator: DefaultValidatorParams(),
}
}

Expand All @@ -51,7 +51,7 @@ func DefaultBlockParams() *abci.BlockParams {
}

func DefaultValidatorParams() *abci.ValidatorParams {
return &abci.ValidatorParams{[]string{
return &abci.ValidatorParams{PubKeyTypeURLs: []string{
amino.GetTypeURL(ed25519.PubKeyEd25519{}),
}}
}
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/crypto/hd/hdpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func mnemonicToSeed(mnemonic string) []byte {
return bip39.NewSeed(mnemonic, defaultBIP39Passphrase)
}

func ExampleStringifyPathParams() {
func ExampleNewParams() {
path := NewParams(44, 0, 0, false, 0)
fmt.Println(path.String())
path = NewParams(44, 33, 7, true, 9)
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestParamsFromPath(t *testing.T) {
}
}

func ExampleSomeBIP32TestVecs() {
func ExampleDerivePrivateKeyForPath() {
seed := mnemonicToSeed("barrel original fuel morning among eternal " +
"filter ball stove pluck matrix mechanic")
master, ch := ComputeMastersFromSeed(seed)
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/db/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@
// It is safe to modify the contents of the argument after Set returns but not
// before.
func (bdb *boltDBBatch) Set(key, value []byte) {
bdb.ops = append(bdb.ops, internal.Operation{internal.OpTypeSet, key, value})
bdb.ops = append(bdb.ops, internal.Operation{OpType: internal.OpTypeSet, Key: key, Value: value})

Check warning on line 173 in tm2/pkg/db/boltdb/boltdb.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/db/boltdb/boltdb.go#L173

Added line #L173 was not covered by tests
}

// It is safe to modify the contents of the argument after Delete returns but
// not before.
func (bdb *boltDBBatch) Delete(key []byte) {
bdb.ops = append(bdb.ops, internal.Operation{internal.OpTypeDelete, key, nil})
bdb.ops = append(bdb.ops, internal.Operation{OpType: internal.OpTypeDelete, Key: key})

Check warning on line 179 in tm2/pkg/db/boltdb/boltdb.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/db/boltdb/boltdb.go#L179

Added line #L179 was not covered by tests
}

// NOTE: the operation is synchronous (see BoltDB for reasons)
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/db/memdb/mem_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (db *MemDB) NewBatch() dbm.Batch {
db.mtx.Lock()
defer db.mtx.Unlock()

return &internal.MemBatch{db, nil}
return &internal.MemBatch{DB: db}
}

// ----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
if t, ok := sw.transport.(TransportLifecycle); ok {
err := t.Close()
if err != nil {
sw.Logger.Error("Error stopping transport on stop: ", err)
sw.Logger.Error("Error stopping transport on stop: ", "error", err)

Check warning on line 222 in tm2/pkg/p2p/switch.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/p2p/switch.go#L222

Added line #L222 was not covered by tests
}
}

Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/sdk/bank/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestBankKeeper(t *testing.T) {
// validate coins with invalid denoms or negative values cannot be sent
// NOTE: We must use the Coin literal as the constructor does not allow
// negative values.
err = bank.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.Coin{"FOOCOIN", -5}})
err = bank.SendCoins(ctx, addr, addr2, sdk.Coins{sdk.Coin{Denom: "FOOCOIN", Amount: -5}})
require.Error(t, err)
}

Expand Down
4 changes: 0 additions & 4 deletions tm2/pkg/sdk/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
default:
return handleQueryCustom(app, path, req)
}

msg := "unknown query path " + req.Path
res.Error = ABCIError(std.ErrUnknownRequest(msg))
return
}

func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abci.ResponseQuery) {
Expand Down
Loading
Loading