Skip to content

Commit

Permalink
fix linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
yenkhoon committed Mar 29, 2023
1 parent 37cdb31 commit 97cbeb2
Show file tree
Hide file tree
Showing 32 changed files with 88 additions and 115 deletions.
10 changes: 5 additions & 5 deletions committee/committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

func copyValidator(val *validator.Validator) *validator.Validator {
copy := validator.NewValidator(val.PublicKey(), val.Number())
copy.UpdateLastBondingHeight(val.LastBondingHeight())
copy.UpdateLastJoinedHeight(val.LastJoinedHeight())
copy.UpdateUnbondingHeight(val.UnbondingHeight())
clone := validator.NewValidator(val.PublicKey(), val.Number())
clone.UpdateLastBondingHeight(val.LastBondingHeight())
clone.UpdateLastJoinedHeight(val.LastJoinedHeight())
clone.UpdateUnbondingHeight(val.UnbondingHeight())

// Stake can't be changes as long as validator is inside committee
// Check Bond executor
return copy
return clone
}
func TestContains(t *testing.T) {
committee, signers := GenerateTestCommittee(21)
Expand Down
4 changes: 2 additions & 2 deletions consensus/change_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (s *changeProposerState) onAddVote(v *vote.Vote) {
}
}

func (s *changeProposerState) onSetProposal(p *proposal.Proposal) {
func (s *changeProposerState) onSetProposal(_ *proposal.Proposal) {
// Ignore proposals
}

func (s *changeProposerState) onTimeout(t *ticker) {
func (s *changeProposerState) onTimeout(_ *ticker) {
// Ignore timeouts
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *commitState) onSetProposal(p *proposal.Proposal) {
s.decide()
}

func (s *commitState) onTimeout(t *ticker) {
func (s *commitState) onTimeout(_ *ticker) {
// Ignore timeouts
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/height.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *newHeightState) onAddVote(v *vote.Vote) {
s.doAddVote(v)
}

func (s *newHeightState) onSetProposal(p *proposal.Proposal) {
func (s *newHeightState) onSetProposal(_ *proposal.Proposal) {
}

func (s *newHeightState) onTimeout(t *ticker) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/precommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *precommitState) onSetProposal(p *proposal.Proposal) {
}
}

func (s *precommitState) onTimeout(t *ticker) {
func (s *precommitState) onTimeout(_ *ticker) {
// Ignore timeouts
}

Expand Down
6 changes: 3 additions & 3 deletions consensus/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func (s *proposeState) createProposal(height uint32, round int16) {
s.broadcastProposal(proposal)
}

func (s *proposeState) onAddVote(v *vote.Vote) {
func (s *proposeState) onAddVote(_ *vote.Vote) {
panic("Unreachable")
}

func (s *proposeState) onSetProposal(p *proposal.Proposal) {
func (s *proposeState) onSetProposal(_ *proposal.Proposal) {
panic("Unreachable")
}

func (s *proposeState) onTimeout(t *ticker) {
func (s *proposeState) onTimeout(_ *ticker) {
panic("Unreachable")
}
func (s *proposeState) name() string {
Expand Down
2 changes: 1 addition & 1 deletion network/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (mock *MockNetwork) SendTo(data []byte, pid lp2pcore.PeerID) error {
}
return nil
}
func (mock *MockNetwork) Broadcast(data []byte, tid TopicID) error {
func (mock *MockNetwork) Broadcast(data []byte, _ TopicID) error {
mock.BroadcastCh <- BroadcastData{
Data: data,
Target: nil, // Send to all
Expand Down
12 changes: 6 additions & 6 deletions sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func (sb *sandbox) Account(addr crypto.Address) *account.Account {

s, ok := sb.accounts[addr]
if ok {
copy := new(account.Account)
*copy = s.Account
return copy
clone := new(account.Account)
*clone = s.Account
return clone
}

acc, err := sb.store.Account(addr)
Expand Down Expand Up @@ -130,9 +130,9 @@ func (sb *sandbox) Validator(addr crypto.Address) *validator.Validator {

s, ok := sb.validators[addr]
if ok {
copy := new(validator.Validator)
*copy = s.Validator
return copy
clone := new(validator.Validator)
*clone = s.Validator
return clone
}

val, err := sb.store.Validator(addr)
Expand Down
4 changes: 2 additions & 2 deletions state/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func (m *MockState) CommitBlock(h uint32, b *block.Block, cert *block.Certificat
func (m *MockState) Close() error {
return nil
}
func (m *MockState) ProposeBlock(round int16) (*block.Block, error) {
func (m *MockState) ProposeBlock(_ int16) (*block.Block, error) {
b := block.GenerateTestBlock(nil, nil)
return b, nil
}
func (m *MockState) ValidateBlock(block *block.Block) error {
func (m *MockState) ValidateBlock(_ *block.Block) error {
return nil
}
func (m *MockState) CommitteeValidators() []*validator.Validator {
Expand Down
6 changes: 1 addition & 5 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ func (st *state) ValidateBlock(block *block.Block) error {
}

sb := st.concreteSandbox()
if err := st.executeBlock(block, sb); err != nil {
return err
}

return nil
return st.executeBlock(block, sb)
}

func (st *state) CommitBlock(height uint32, block *block.Block, cert *block.Certificate) error {
Expand Down
6 changes: 1 addition & 5 deletions sync/bundle/message/block_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ func (m *BlockAnnounceMessage) SanityCheck() error {
if err := m.Block.SanityCheck(); err != nil {
return err
}
if err := m.Certificate.SanityCheck(); err != nil {
return err
}

return nil
return m.Certificate.SanityCheck()
}

func (m *BlockAnnounceMessage) Type() Type {
Expand Down
5 changes: 1 addition & 4 deletions sync/bundle/message/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func (m *HelloMessage) SanityCheck() error {
if m.PublicKey == nil {
return errors.Error(errors.ErrInvalidPublicKey)
}
if err := m.PublicKey.Verify(m.SignBytes(), m.Signature); err != nil {
return err
}
return nil
return m.PublicKey.Verify(m.SignBytes(), m.Signature)
}

func (m *HelloMessage) SignBytes() []byte {
Expand Down
6 changes: 1 addition & 5 deletions sync/bundle/message/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ func NewProposalMessage(p *proposal.Proposal) *ProposalMessage {
}

func (m *ProposalMessage) SanityCheck() error {
if err := m.Proposal.SanityCheck(); err != nil {
return err
}

return nil
return m.Proposal.SanityCheck()
}

func (m *ProposalMessage) Type() Type {
Expand Down
5 changes: 1 addition & 4 deletions sync/bundle/message/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func NewVoteMessage(v *vote.Vote) *VoteMessage {
}

func (m *VoteMessage) SanityCheck() error {
if err := m.Vote.SanityCheck(); err != nil {
return err
}
return nil
return m.Vote.SanityCheck()
}

func (m *VoteMessage) Type() Type {
Expand Down
2 changes: 1 addition & 1 deletion sync/handler_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newProposalHandler(sync *synchronizer) messageHandler {
}
}

func (handler *proposalHandler) ParsMessage(m message.Message, initiator peer.ID) error {
func (handler *proposalHandler) ParsMessage(m message.Message, _ peer.ID) error {
msg := m.(*message.ProposalMessage)
handler.logger.Trace("parsing Proposal message", "message", msg)

Expand Down
2 changes: 1 addition & 1 deletion sync/handler_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newTransactionsHandler(sync *synchronizer) messageHandler {
}
}

func (handler *transactionsHandler) ParsMessage(m message.Message, initiator peer.ID) error {
func (handler *transactionsHandler) ParsMessage(m message.Message, _ peer.ID) error {
msg := m.(*message.TransactionsMessage)
handler.logger.Trace("parsing Transactions message", "message", msg)

Expand Down
2 changes: 1 addition & 1 deletion sync/handler_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newVoteHandler(sync *synchronizer) messageHandler {
}
}

func (handler *voteHandler) ParsMessage(m message.Message, initiator peer.ID) error {
func (handler *voteHandler) ParsMessage(m message.Message, _ peer.ID) error {
msg := m.(*message.VoteMessage)
handler.logger.Trace("parsing Vote message", "message", msg)

Expand Down
4 changes: 2 additions & 2 deletions txpool/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func MockingTxPool() *MockTxPool {
Txs: make([]*tx.Tx, 0),
}
}
func (m *MockTxPool) SetNewSandboxAndRecheck(sb sandbox.Sandbox) {}
func (m *MockTxPool) SetNewSandboxAndRecheck(_ sandbox.Sandbox) {}
func (m *MockTxPool) PendingTx(id tx.ID) *tx.Tx {
for _, t := range m.Txs {
if t.ID().EqualsTo(id) {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (m *MockTxPool) AppendTxAndBroadcast(trx *tx.Tx) error {
return nil
}

func (m *MockTxPool) RemoveTx(id hash.Hash) {
func (m *MockTxPool) RemoveTx(_ hash.Hash) {
// This test pools is shared between different test objects
//delete(m.Txs, id)
}
Expand Down
6 changes: 3 additions & 3 deletions types/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func (b *Block) Decode(r io.Reader) error {
return err
}
}
len, err := encoding.ReadVarInt(r)
length, err := encoding.ReadVarInt(r)
if err != nil {
return err
}
b.data.Txs = make([]*tx.Tx, len)
for i := 0; i < int(len); i++ {
b.data.Txs = make([]*tx.Tx, length)
for i := 0; i < int(length); i++ {
tx := new(tx.Tx)
if err := tx.Decode(r); err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions types/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ func TestCBORMarshaling(t *testing.T) {

func TestEncodingBlock(t *testing.T) {
blk := GenerateTestBlock(nil, nil)
len := blk.SerializeSize()
length := blk.SerializeSize()

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
w := util.NewFixedWriter(i)
assert.Error(t, blk.Encode(w), "encode test %v failed", i)
}
w := util.NewFixedWriter(len)
w := util.NewFixedWriter(length)
assert.NoError(t, blk.Encode(w))

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
blk2 := new(Block)
r := util.NewFixedReader(i, w.Bytes())
assert.Error(t, blk2.Decode(r), "decode test %v failed", i)
}

blk2 := new(Block)
r := util.NewFixedReader(len, w.Bytes())
r := util.NewFixedReader(length, w.Bytes())
assert.NoError(t, blk2.Decode(r))
assert.Equal(t, blk.Hash(), blk2.Hash())
assert.Equal(t, blk.Header(), blk2.Header())
Expand Down
5 changes: 1 addition & 4 deletions types/block/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ func (cert *Certificate) Encode(w io.Writer) error {
return err
}
}
if err := cert.data.Signature.Encode(w); err != nil {
return err
}

return nil
return cert.data.Signature.Encode(w)
}

func (cert *Certificate) Decode(r io.Reader) error {
Expand Down
6 changes: 1 addition & 5 deletions types/tx/payload/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ func (p *SendPayload) SanityCheck() error {
if err := p.Sender.SanityCheck(); err != nil {
return err
}
if err := p.Receiver.SanityCheck(); err != nil {
return err
}

return nil
return p.Receiver.SanityCheck()
}

func (p *SendPayload) SerializeSize() int {
Expand Down
10 changes: 5 additions & 5 deletions types/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ func TestCBORMarshaling(t *testing.T) {

func TestEncodingTx(t *testing.T) {
tx1, _ := GenerateTestSendTx()
len := tx1.SerializeSize()
length := tx1.SerializeSize()

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
w := util.NewFixedWriter(i)
assert.Error(t, tx1.Encode(w), "encode test %v failed", i)
}
w := util.NewFixedWriter(len)
w := util.NewFixedWriter(length)
assert.NoError(t, tx1.Encode(w))

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
tx2 := new(Tx)
r := util.NewFixedReader(i, w.Bytes())
assert.Error(t, tx2.Decode(r), "decode test %v failed", i)
}

tx2 := new(Tx)
r := util.NewFixedReader(len, w.Bytes())
r := util.NewFixedReader(length, w.Bytes())
assert.NoError(t, tx2.Decode(r))
assert.Equal(t, tx1.ID(), tx2.ID())
}
Expand Down
20 changes: 10 additions & 10 deletions wallet/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ var tValidatorRequest *pactus.GetValidatorRequest
var tValidatorResponse *pactus.GetValidatorResponse

func (s *blockchainServer) GetBlockchainInfo(_ context.Context,
req *pactus.GetBlockchainInfoRequest) (*pactus.GetBlockchainInfoResponse, error) {
_ *pactus.GetBlockchainInfoRequest) (*pactus.GetBlockchainInfoResponse, error) {
return tBlockchainInfoResponse, nil
}

func (s *blockchainServer) GetConsensusInfo(_ context.Context,
req *pactus.GetConsensusInfoRequest) (*pactus.GetConsensusInfoResponse, error) {
_ *pactus.GetConsensusInfoRequest) (*pactus.GetConsensusInfoResponse, error) {
return nil, nil
}

func (s *blockchainServer) GetBlockHash(_ context.Context,
req *pactus.GetBlockHashRequest) (*pactus.GetBlockHashResponse, error) {
_ *pactus.GetBlockHashRequest) (*pactus.GetBlockHashResponse, error) {
return nil, nil
}

func (s *blockchainServer) GetBlockHeight(_ context.Context,
req *pactus.GetBlockHeightRequest) (*pactus.GetBlockHeightResponse, error) {
_ *pactus.GetBlockHeightRequest) (*pactus.GetBlockHeightResponse, error) {
return nil, nil
}

func (s *blockchainServer) GetBlock(_ context.Context,
req *pactus.GetBlockRequest) (*pactus.GetBlockResponse, error) {
_ *pactus.GetBlockRequest) (*pactus.GetBlockResponse, error) {
return nil, nil
}

Expand All @@ -51,7 +51,7 @@ func (s *blockchainServer) GetAccount(_ context.Context,
}

func (s *blockchainServer) GetValidatorByNumber(_ context.Context,
req *pactus.GetValidatorByNumberRequest) (*pactus.GetValidatorResponse, error) {
_ *pactus.GetValidatorByNumberRequest) (*pactus.GetValidatorResponse, error) {
return nil, nil
}

Expand All @@ -64,16 +64,16 @@ func (s *blockchainServer) GetValidator(_ context.Context,
}

func (s *blockchainServer) GetValidators(_ context.Context,
req *pactus.GetValidatorsRequest) (*pactus.GetValidatorsResponse, error) {
_ *pactus.GetValidatorsRequest) (*pactus.GetValidatorsResponse, error) {
return nil, nil
}

func (s *transactionServer) GetTransaction(ctx context.Context,
req *pactus.GetTransactionRequest) (*pactus.GetTransactionResponse, error) {
func (s *transactionServer) GetTransaction(_ context.Context,
_ *pactus.GetTransactionRequest) (*pactus.GetTransactionResponse, error) {
return nil, nil
}

func (s *transactionServer) SendRawTransaction(ctx context.Context,
func (s *transactionServer) SendRawTransaction(_ context.Context,
req *pactus.SendRawTransactionRequest) (*pactus.SendRawTransactionResponse, error) {
trx, _ := tx.FromBytes(req.Data)
return &pactus.SendRawTransactionResponse{
Expand Down

0 comments on commit 97cbeb2

Please sign in to comment.