From 167d73f979283ff75c73daffd1114a8c48d9178f Mon Sep 17 00:00:00 2001 From: tony Date: Wed, 31 Jan 2024 00:14:45 +0800 Subject: [PATCH] enable golangci-lint for test files as well --- .golangci.pull-request.yml | 20 -------- .golangci.yml | 12 +++-- abi/abi_test.go | 1 - api/accounts/accounts_test.go | 74 +++++++++++++-------------- api/blocks/blocks_test.go | 17 ++---- api/node/node_test.go | 4 +- api/transactions/transactions_test.go | 10 ++-- block/gas_limit_test.go | 2 - chain/block_reader_test.go | 1 - chain/repository_test.go | 1 - consensus/consensus_test.go | 7 ++- genesis/customnet_test.go | 1 - logdb/logdb_test.go | 2 - logdb/sequence_test.go | 6 ++- packer/flow_test.go | 2 +- poa/candidates_test.go | 3 -- poa/sched_test.go | 1 - poa/seed_test.go | 1 - runtime/resolved_tx_test.go | 2 - stackedmap/stackedmap_test.go | 1 - state/state_test.go | 5 +- tracers/tracers_test.go | 4 +- trie/trie_test.go | 15 +----- tx/receipt_test.go | 3 -- tx/transaction_test.go | 6 +-- txpool/blocklist_test.go | 3 +- txpool/tx_object_map_test.go | 1 - txpool/tx_object_test.go | 1 - txpool/tx_pool_test.go | 2 - vm/contracts_test.go | 26 ++-------- vm/instructions_test.go | 4 +- vrf/vrf_test.go | 5 +- 32 files changed, 76 insertions(+), 167 deletions(-) delete mode 100644 .golangci.pull-request.yml diff --git a/.golangci.pull-request.yml b/.golangci.pull-request.yml deleted file mode 100644 index 6fcbb0ba2..000000000 --- a/.golangci.pull-request.yml +++ /dev/null @@ -1,20 +0,0 @@ -# Please refer to the official golangci-lint config documentation for more details: -# https://golangci-lint.run/usage/configuration/ -# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml - -linters: - enable-all: true - -run: - timeout: 10m - tests: false - -issues: - max-issues-per-linter: 1000 - exclude-rules: - - path: vm/contracts.go - text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.' - - path: vm/bn256/cloudflare/optate.go - linters: - - deadcode - - staticcheck diff --git a/.golangci.yml b/.golangci.yml index de8cec3e5..cb30087d8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,12 @@ # Please refer to the official golangci-lint config documentation for more details: # https://golangci-lint.run/usage/configuration/ # https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml +run: + timeout: 10m + tests: true + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true linters: disable-all: true @@ -28,9 +34,9 @@ linters: # - makezero # false positives # - nilerr # several intentional -run: - timeout: 10m - tests: false +linters-settings: + gofmt: + simplify: true issues: max-issues-per-linter: 1000 diff --git a/abi/abi_test.go b/abi/abi_test.go index 4a90ccfb6..b9f921b91 100644 --- a/abi/abi_test.go +++ b/abi/abi_test.go @@ -81,6 +81,5 @@ func TestABI(t *testing.T) { assert.Nil(t, err) assert.Equal(t, value, d) - } } diff --git a/api/accounts/accounts_test.go b/api/accounts/accounts_test.go index 98338c83d..9697501d9 100644 --- a/api/accounts/accounts_test.go +++ b/api/accounts/accounts_test.go @@ -8,7 +8,7 @@ package accounts_test import ( "bytes" "encoding/json" - "io/ioutil" + "io" "math/big" "net/http" "net/http/httptest" @@ -32,16 +32,16 @@ import ( "github.com/vechain/thor/v2/tx" ) -var sol = ` pragma solidity ^0.4.18; - contract Test { - uint8 value; - function add(uint8 a,uint8 b) public pure returns(uint8) { - return a+b; - } - function set(uint8 v) public { - value = v; - } - }` +// pragma solidity ^0.4.18; +// contract Test { +// uint8 value; +// function add(uint8 a,uint8 b) public pure returns(uint8) { +// return a+b; +// } +// function set(uint8 v) public { +// value = v; +// } +// } var abiJSON = `[ { @@ -111,32 +111,31 @@ func TestAccount(t *testing.T) { } func getAccount(t *testing.T) { - res, statusCode := httpGet(t, ts.URL+"/accounts/"+invalidAddr) + _, statusCode := httpGet(t, ts.URL+"/accounts/"+invalidAddr) assert.Equal(t, http.StatusBadRequest, statusCode, "bad address") - res, statusCode = httpGet(t, ts.URL+"/accounts/"+addr.String()+"?revision="+invalidNumberRevision) + _, statusCode = httpGet(t, ts.URL+"/accounts/"+addr.String()+"?revision="+invalidNumberRevision) assert.Equal(t, http.StatusBadRequest, statusCode, "bad revision") //revision is optional defaut `best` - res, statusCode = httpGet(t, ts.URL+"/accounts/"+addr.String()) + res, statusCode := httpGet(t, ts.URL+"/accounts/"+addr.String()) var acc accounts.Account if err := json.Unmarshal(res, &acc); err != nil { t.Fatal(err) } assert.Equal(t, math.HexOrDecimal256(*value), acc.Balance, "balance should be equal") assert.Equal(t, http.StatusOK, statusCode, "OK") - } func getCode(t *testing.T) { - res, statusCode := httpGet(t, ts.URL+"/accounts/"+invalidAddr+"/code") + _, statusCode := httpGet(t, ts.URL+"/accounts/"+invalidAddr+"/code") assert.Equal(t, http.StatusBadRequest, statusCode, "bad address") - res, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/code?revision="+invalidNumberRevision) + _, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/code?revision="+invalidNumberRevision) assert.Equal(t, http.StatusBadRequest, statusCode, "bad revision") //revision is optional defaut `best` - res, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/code") + res, statusCode := httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/code") var code map[string]string if err := json.Unmarshal(res, &code); err != nil { t.Fatal(err) @@ -150,17 +149,17 @@ func getCode(t *testing.T) { } func getStorage(t *testing.T) { - res, statusCode := httpGet(t, ts.URL+"/accounts/"+invalidAddr+"/storage/"+storageKey.String()) + _, statusCode := httpGet(t, ts.URL+"/accounts/"+invalidAddr+"/storage/"+storageKey.String()) assert.Equal(t, http.StatusBadRequest, statusCode, "bad address") - res, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/storage/"+invalidBytes32) + _, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/storage/"+invalidBytes32) assert.Equal(t, http.StatusBadRequest, statusCode, "bad storage key") - res, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/storage/"+storageKey.String()+"?revision="+invalidNumberRevision) + _, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/storage/"+storageKey.String()+"?revision="+invalidNumberRevision) assert.Equal(t, http.StatusBadRequest, statusCode, "bad revision") //revision is optional defaut `best` - res, statusCode = httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/storage/"+storageKey.String()) + res, statusCode := httpGet(t, ts.URL+"/accounts/"+contractAddr.String()+"/storage/"+storageKey.String()) var value map[string]string if err := json.Unmarshal(res, &value); err != nil { t.Fatal(err) @@ -190,9 +189,9 @@ func initAccountServer(t *testing.T) { packTx(repo, stater, transaction, t) method := "set" - abi, err := ABI.New([]byte(abiJSON)) + abi, _ := ABI.New([]byte(abiJSON)) m, _ := abi.MethodByName(method) - input, err := m.EncodeInput(uint8(storageValue)) + input, err := m.EncodeInput(storageValue) if err != nil { t.Fatal(err) } @@ -252,7 +251,7 @@ func deployContractWithCall(t *testing.T) { Gas: 10000000, Data: "abc", } - res, statusCode := httpPost(t, ts.URL+"/accounts", badBody) + _, statusCode := httpPost(t, ts.URL+"/accounts", badBody) assert.Equal(t, http.StatusBadRequest, statusCode, "bad data") reqBody := &accounts.CallData{ @@ -260,33 +259,32 @@ func deployContractWithCall(t *testing.T) { Data: hexutil.Encode(bytecode), } - res, statusCode = httpPost(t, ts.URL+"/accounts?revision="+invalidNumberRevision, reqBody) + _, statusCode = httpPost(t, ts.URL+"/accounts?revision="+invalidNumberRevision, reqBody) assert.Equal(t, http.StatusBadRequest, statusCode, "bad revision") //revision is optional defaut `best` - res, statusCode = httpPost(t, ts.URL+"/accounts", reqBody) + res, _ := httpPost(t, ts.URL+"/accounts", reqBody) var output *accounts.CallResult if err := json.Unmarshal(res, &output); err != nil { t.Fatal(err) } assert.False(t, output.Reverted) - } func callContract(t *testing.T) { - res, statusCode := httpPost(t, ts.URL+"/accounts/"+invalidAddr, nil) + _, statusCode := httpPost(t, ts.URL+"/accounts/"+invalidAddr, nil) assert.Equal(t, http.StatusBadRequest, statusCode, "invalid address") badBody := &accounts.CallData{ Data: "input", } - res, statusCode = httpPost(t, ts.URL+"/accounts/"+contractAddr.String(), badBody) + _, statusCode = httpPost(t, ts.URL+"/accounts/"+contractAddr.String(), badBody) assert.Equal(t, http.StatusBadRequest, statusCode, "invalid input data") a := uint8(1) b := uint8(2) method := "add" - abi, err := ABI.New([]byte(abiJSON)) + abi, _ := ABI.New([]byte(abiJSON)) m, _ := abi.MethodByName(method) input, err := m.EncodeInput(a, b) if err != nil { @@ -295,7 +293,7 @@ func callContract(t *testing.T) { reqBody := &accounts.CallData{ Data: hexutil.Encode(input), } - res, statusCode = httpPost(t, ts.URL+"/accounts/"+contractAddr.String(), reqBody) + res, statusCode := httpPost(t, ts.URL+"/accounts/"+contractAddr.String(), reqBody) var output *accounts.CallResult if err = json.Unmarshal(res, &output); err != nil { t.Fatal(err) @@ -327,13 +325,13 @@ func batchCall(t *testing.T) { Value: nil, }}, } - res, statusCode := httpPost(t, ts.URL+"/accounts/*", badBody) + _, statusCode := httpPost(t, ts.URL+"/accounts/*", badBody) assert.Equal(t, http.StatusBadRequest, statusCode, "invalid data") a := uint8(1) b := uint8(2) method := "add" - abi, err := ABI.New([]byte(abiJSON)) + abi, _ := ABI.New([]byte(abiJSON)) m, _ := abi.MethodByName(method) input, err := m.EncodeInput(a, b) if err != nil { @@ -353,10 +351,10 @@ func batchCall(t *testing.T) { }}, } - res, statusCode = httpPost(t, ts.URL+"/accounts/*?revision="+invalidNumberRevision, badBody) + _, statusCode = httpPost(t, ts.URL+"/accounts/*?revision="+invalidNumberRevision, badBody) assert.Equal(t, http.StatusBadRequest, statusCode, "invalid revision") - res, statusCode = httpPost(t, ts.URL+"/accounts/*", reqBody) + res, statusCode := httpPost(t, ts.URL+"/accounts/*", reqBody) var results accounts.BatchCallResults if err = json.Unmarshal(res, &results); err != nil { t.Fatal(err) @@ -399,7 +397,7 @@ func httpPost(t *testing.T, url string, body interface{}) ([]byte, int) { if err != nil { t.Fatal(err) } - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) @@ -412,7 +410,7 @@ func httpGet(t *testing.T, url string) ([]byte, int) { if err != nil { t.Fatal(err) } - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) diff --git a/api/blocks/blocks_test.go b/api/blocks/blocks_test.go index 941fbb1b6..f7079bfb4 100644 --- a/api/blocks/blocks_test.go +++ b/api/blocks/blocks_test.go @@ -7,7 +7,7 @@ package blocks import ( "encoding/json" - "io/ioutil" + "io" "math/big" "net/http" "net/http/httptest" @@ -28,11 +28,6 @@ import ( "github.com/vechain/thor/v2/tx" ) -const ( - testAddress = "56e81f171bcc55a6ff8345e692c0f86e5b48e01a" - testPrivHex = "efa321f290811731036e5eccd373114e5186d9fe419081f5a607231279d5ef01" -) - var blk *block.Block var ts *httptest.Server @@ -43,13 +38,13 @@ func TestBlock(t *testing.T) { initBlockServer(t) defer ts.Close() //invalid block id - res, statusCode := httpGet(t, ts.URL+"/blocks/"+invalidBytes32) + _, statusCode := httpGet(t, ts.URL+"/blocks/"+invalidBytes32) assert.Equal(t, http.StatusBadRequest, statusCode) //invalid block number - res, statusCode = httpGet(t, ts.URL+"/blocks/"+invalidNumberRevision) + _, statusCode = httpGet(t, ts.URL+"/blocks/"+invalidNumberRevision) assert.Equal(t, http.StatusBadRequest, statusCode) - res, statusCode = httpGet(t, ts.URL+"/blocks/"+blk.Header().ID().String()) + res, statusCode := httpGet(t, ts.URL+"/blocks/"+blk.Header().ID().String()) rb := new(JSONCollapsedBlock) if err := json.Unmarshal(res, rb); err != nil { t.Fatal(err) @@ -70,7 +65,6 @@ func TestBlock(t *testing.T) { } checkBlock(t, blk, rb) assert.Equal(t, http.StatusOK, statusCode) - } func initBlockServer(t *testing.T) { @@ -145,7 +139,6 @@ func checkBlock(t *testing.T, expBl *block.Block, actBl *JSONCollapsedBlock) { for i, tx := range expBl.Transactions() { assert.Equal(t, tx.ID(), actBl.Transactions[i], "txid should be equal") } - } func httpGet(t *testing.T, url string) ([]byte, int) { @@ -153,7 +146,7 @@ func httpGet(t *testing.T, url string) ([]byte, int) { if err != nil { t.Fatal(err) } - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) diff --git a/api/node/node_test.go b/api/node/node_test.go index 59ecb0de5..7952415a3 100644 --- a/api/node/node_test.go +++ b/api/node/node_test.go @@ -6,7 +6,7 @@ package node_test import ( "encoding/json" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -60,7 +60,7 @@ func httpGet(t *testing.T, url string) []byte { if err != nil { t.Fatal(err) } - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) diff --git a/api/transactions/transactions_test.go b/api/transactions/transactions_test.go index d727562c7..c11f4c1bb 100644 --- a/api/transactions/transactions_test.go +++ b/api/transactions/transactions_test.go @@ -8,7 +8,7 @@ package transactions_test import ( "bytes" "encoding/json" - "io/ioutil" + "io" "math/big" "net/http" "net/http/httptest" @@ -69,7 +69,7 @@ func getTxReceipt(t *testing.T) { if err := json.Unmarshal(r, &receipt); err != nil { t.Fatal(err) } - assert.Equal(t, uint64(receipt.GasUsed), transaction.Gas(), "gas should be equal") + assert.Equal(t, receipt.GasUsed, transaction.Gas(), "gas should be equal") } func senTx(t *testing.T) { @@ -111,7 +111,7 @@ func httpPost(t *testing.T, url string, obj interface{}) []byte { if err != nil { t.Fatal(err) } - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) @@ -172,7 +172,6 @@ func initTransactionServer(t *testing.T) { router := mux.NewRouter() transactions.New(repo, txpool.New(repo, stater, txpool.Options{Limit: 10000, LimitPerAccount: 16, MaxLifetime: 10 * time.Minute})).Mount(router, "/transactions") ts = httptest.NewServer(router) - } func checkTx(t *testing.T, expectedTx *tx.Transaction, actualTx *transactions.Transaction) { @@ -189,7 +188,6 @@ func checkTx(t *testing.T, expectedTx *tx.Transaction, actualTx *transactions.Tr assert.Equal(t, *c.Value(), big.Int(actualTx.Clauses[i].Value)) assert.Equal(t, c.To(), actualTx.Clauses[i].To) } - } func httpGet(t *testing.T, url string) []byte { @@ -197,7 +195,7 @@ func httpGet(t *testing.T, url string) []byte { if err != nil { t.Fatal(err) } - r, err := ioutil.ReadAll(res.Body) + r, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { t.Fatal(err) diff --git a/block/gas_limit_test.go b/block/gas_limit_test.go index c01cb4749..5fde2c413 100644 --- a/block/gas_limit_test.go +++ b/block/gas_limit_test.go @@ -15,7 +15,6 @@ import ( ) func TestGasLimit_IsValid(t *testing.T) { - tests := []struct { gl uint64 parentGL uint64 @@ -35,7 +34,6 @@ func TestGasLimit_IsValid(t *testing.T) { } func TestGasLimit_Adjust(t *testing.T) { - tests := []struct { gl uint64 delta int64 diff --git a/chain/block_reader_test.go b/chain/block_reader_test.go index 2253179ce..7d4c306e3 100644 --- a/chain/block_reader_test.go +++ b/chain/block_reader_test.go @@ -44,7 +44,6 @@ func TestBlockReader(t *testing.T) { break } blks = append(blks, r...) - } assert.Equal(t, []*chain.ExtendedBlock{ diff --git a/chain/repository_test.go b/chain/repository_test.go index b83f0a7f1..08a23c037 100644 --- a/chain/repository_test.go +++ b/chain/repository_test.go @@ -83,7 +83,6 @@ func TestRepository(t *testing.T) { repo1.SetBestBlockID(b1.Header().ID()) repo2, _ := NewRepository(db, b0) for _, repo := range []*Repository{repo1, repo2} { - assert.Equal(t, b1.Header().ID(), repo.BestBlockSummary().Header.ID()) s, err := repo.GetBlockSummary(b1.Header().ID()) assert.Nil(t, err) diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go index 9f98a5ae1..4904b2656 100644 --- a/consensus/consensus_test.go +++ b/consensus/consensus_test.go @@ -90,7 +90,7 @@ func newTestConsensus() (*testConsensus, error) { proposer := genesis.DevAccounts()[0] p := packer.New(repo, stater, proposer.Address, &proposer.Address, forkConfig) parentSum, _ := repo.GetBlockSummary(parent.Header().ID()) - flow, err := p.Schedule(parentSum, uint64(parent.Header().Timestamp()+100*thor.BlockInterval)) + flow, err := p.Schedule(parentSum, parent.Header().Timestamp()+100*thor.BlockInterval) if err != nil { return nil, err } @@ -121,7 +121,7 @@ func newTestConsensus() (*testConsensus, error) { proposer2 := genesis.DevAccounts()[1] p2 := packer.New(repo, stater, proposer2.Address, &proposer2.Address, forkConfig) b1sum, _ := repo.GetBlockSummary(b1.Header().ID()) - flow2, err := p2.Schedule(b1sum, uint64(b1.Header().Timestamp()+100*thor.BlockInterval)) + flow2, err := p2.Schedule(b1sum, b1.Header().Timestamp()+100*thor.BlockInterval) if err != nil { return nil, err } @@ -229,7 +229,7 @@ func TestNewConsensus(t *testing.T) { } func TestNewRuntimeForReplay(t *testing.T) { - consensus, err := newTestConsensus() + consensus, _ := newTestConsensus() b1 := consensus.parent // Test for success scenario @@ -351,7 +351,6 @@ func TestValidateBlockHeader(t *testing.T) { assert.Equal(t, expected, err) assert.True(t, IsCritical(err)) assert.Equal(t, err.Error(), "block gas limit invalid: parent 10000000, current 20000000") - }, }, { diff --git a/genesis/customnet_test.go b/genesis/customnet_test.go index f5ff67664..f53a9cfec 100644 --- a/genesis/customnet_test.go +++ b/genesis/customnet_test.go @@ -58,7 +58,6 @@ func CustomNetWithParams(t *testing.T, executor genesis.Executor, baseGasPrice g } func TestNewCustomNet(t *testing.T) { - customGenesis := CustomNetWithParams(t, genesis.Executor{}, genesis.HexOrDecimal256{}, genesis.HexOrDecimal256{}, genesis.HexOrDecimal256{}) genesisBlock, err := genesis.NewCustomNet(&customGenesis) diff --git a/logdb/logdb_test.go b/logdb/logdb_test.go index 87fbd8ea2..684c245cc 100644 --- a/logdb/logdb_test.go +++ b/logdb/logdb_test.go @@ -133,7 +133,6 @@ func TestEvents(t *testing.T) { var allTransfers transferLogs for i := 0; i < 100; i++ { - b = new(block.Builder). ParentID(b.Header().ID()). Transaction(newTx()). @@ -428,5 +427,4 @@ func TestLogDB_HasBlockID(t *testing.T) { t.Fatal(err) } assert.True(t, has) - } diff --git a/logdb/sequence_test.go b/logdb/sequence_test.go index d6bdf2395..24c7e47a2 100644 --- a/logdb/sequence_test.go +++ b/logdb/sequence_test.go @@ -1,7 +1,9 @@ package logdb -import "testing" -import "math" +import ( + "math" + "testing" +) func TestSequence(t *testing.T) { type args struct { diff --git a/packer/flow_test.go b/packer/flow_test.go index 1c88f9833..d9baac228 100644 --- a/packer/flow_test.go +++ b/packer/flow_test.go @@ -112,7 +112,7 @@ func TestPack(t *testing.T) { proposer := genesis.DevAccounts()[0] p := packer.New(repo, stater, proposer.Address, &proposer.Address, forkConfig) parentSum, _ := repo.GetBlockSummary(parent.Header().ID()) - flow, _ := p.Schedule(parentSum, uint64(parent.Header().Timestamp()+100*thor.BlockInterval)) + flow, _ := p.Schedule(parentSum, parent.Header().Timestamp()+100*thor.BlockInterval) flow.Pack(proposer.PrivateKey, 0, false) diff --git a/poa/candidates_test.go b/poa/candidates_test.go index b71ad26c0..16e43fd4e 100644 --- a/poa/candidates_test.go +++ b/poa/candidates_test.go @@ -17,7 +17,6 @@ import ( ) func generateCandidateList(candidateCount int) []*authority.Candidate { - candidateList := make([]*authority.Candidate, 0, candidateCount) for i := 0; i < candidateCount; i++ { var nodeMaster, endorsor thor.Address @@ -39,7 +38,6 @@ func generateCandidateList(candidateCount int) []*authority.Candidate { } func TestNewCandidates(t *testing.T) { - candidateList := generateCandidateList(5) // Call NewCandidates with the mock data @@ -124,7 +122,6 @@ func TestPick(t *testing.T) { } func TestUpdate(t *testing.T) { - candidateList := generateCandidateList(5) // Call NewCandidates with the mock data diff --git a/poa/sched_test.go b/poa/sched_test.go index 0fed063e9..8beb63891 100644 --- a/poa/sched_test.go +++ b/poa/sched_test.go @@ -34,7 +34,6 @@ var ( ) func TestSchedule(t *testing.T) { - _, err := poa.NewSchedulerV1(thor.BytesToAddress([]byte("px")), proposers, 1, parentTime) assert.NotNil(t, err) diff --git a/poa/seed_test.go b/poa/seed_test.go index 2d5192173..ce16d13e8 100644 --- a/poa/seed_test.go +++ b/poa/seed_test.go @@ -200,5 +200,4 @@ func TestSeeder_Generate(t *testing.T) { } }) } - } diff --git a/runtime/resolved_tx_test.go b/runtime/resolved_tx_test.go index 07c846b94..009cbcb3c 100644 --- a/runtime/resolved_tx_test.go +++ b/runtime/resolved_tx_test.go @@ -72,7 +72,6 @@ func (tr *testResolvedTransaction) currentState() *state.State { } func (tr *testResolvedTransaction) TestResolveTransaction() { - txBuild := func() *tx.Builder { return txBuilder(tr.repo.ChainTag()) } @@ -98,7 +97,6 @@ func (tr *testResolvedTransaction) TestResolveTransaction() { } func (tr *testResolvedTransaction) TestCommonTo() { - txBuild := func() *tx.Builder { return txBuilder(tr.repo.ChainTag()) } diff --git a/stackedmap/stackedmap_test.go b/stackedmap/stackedmap_test.go index b3b357efa..d9dbedec8 100644 --- a/stackedmap/stackedmap_test.go +++ b/stackedmap/stackedmap_test.go @@ -16,7 +16,6 @@ func M(a ...interface{}) []interface{} { return a } func TestStackedMap(t *testing.T) { - assert := assert.New(t) src := make(map[string]string) src["foo"] = "bar" diff --git a/state/state_test.go b/state/state_test.go index baaf586db..94cf3f979 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -96,7 +96,6 @@ func TestStateRevert(t *testing.T) { assert.Equal(t, state.NewCheckpoint(), 1) state.RevertTo(0) assert.Equal(t, state.NewCheckpoint(), 0) - } func TestEnergy(t *testing.T) { @@ -142,9 +141,7 @@ func TestEncodeDecodeStorage(t *testing.T) { // Function to decode the storage value var decodedValue []byte decodeFunc := func(b []byte) error { - var err error - err = rlp.DecodeBytes(b, &decodedValue) - return err + return rlp.DecodeBytes(b, &decodedValue) } // Decode the stored value diff --git a/tracers/tracers_test.go b/tracers/tracers_test.go index 3913eefa8..bd44a85c0 100644 --- a/tracers/tracers_test.go +++ b/tracers/tracers_test.go @@ -236,7 +236,6 @@ func TestCallTracers(t *testing.T) { } assert.Equal(t, prestate(testData.State), pre) }) - } } @@ -266,7 +265,6 @@ func TestPreStateTracers(t *testing.T) { } assert.Equal(t, testData.diffState, got) }) - } } @@ -392,7 +390,7 @@ func TestInternals(t *testing.T) { rt.SetVMConfig(vm.Config{Tracer: tr}) gas := uint64(80000) - clause := tx.NewClause(&to).WithValue((*big.Int)(big.NewInt(0))) + clause := tx.NewClause(&to).WithValue(big.NewInt(0)) // to remain the same with testcases from ethereum, here deduct intrinsic gas since ethereum captures gas including intrinsic and we don't // we are capturing at clause level exec, _ := rt.PrepareClause(clause, 0, gas-21000, &xenv.TransactionContext{ diff --git a/trie/trie_test.go b/trie/trie_test.go index 006712753..22e49354d 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -20,7 +20,6 @@ import ( "bytes" "encoding/binary" "fmt" - "io/ioutil" "math/big" "math/rand" "os" @@ -52,7 +51,7 @@ func TestEmptyTrie(t *testing.T) { var trie Trie res := trie.Hash() exp := emptyRoot - if res != thor.Bytes32(exp) { + if res != exp { t.Errorf("expected %x got %x", exp, res) } } @@ -314,16 +313,6 @@ func TestLargeValue(t *testing.T) { trie.Hash() } -type countingDB struct { - Database - gets map[string]int -} - -func (db *countingDB) Get(key []byte) ([]byte, error) { - db.gets[string(key)]++ - return db.Database.Get(key) -} - // TestCacheUnload checks that decoded nodes are unloaded after a // certain number of commit operations. // func TestCacheUnload(t *testing.T) { @@ -587,7 +576,7 @@ func BenchmarkHash(b *testing.B) { } func tempDB() (string, Database) { - dir, err := ioutil.TempDir("", "trie-bench") + dir, err := os.MkdirTemp("", "trie-bench") if err != nil { panic(fmt.Sprintf("can't create temporary directory: %v", err)) } diff --git a/tx/receipt_test.go b/tx/receipt_test.go index 8b800ba08..6c1dc9f0f 100644 --- a/tx/receipt_test.go +++ b/tx/receipt_test.go @@ -36,7 +36,6 @@ func TestReceipt(t *testing.T) { } func TestReceiptStructure(t *testing.T) { - receipt := getMockReceipt() assert.Equal(t, uint64(1000), receipt.GasUsed) @@ -45,11 +44,9 @@ func TestReceiptStructure(t *testing.T) { assert.Equal(t, big.NewInt(50), receipt.Reward) assert.Equal(t, false, receipt.Reverted) assert.Equal(t, []*Output{}, receipt.Outputs) - } func TestEmptyRootHash(t *testing.T) { - receipt1 := getMockReceipt() receipt2 := getMockReceipt() diff --git a/tx/transaction_test.go b/tx/transaction_test.go index 50b1f0b96..1a1f121d8 100644 --- a/tx/transaction_test.go +++ b/tx/transaction_test.go @@ -42,8 +42,7 @@ func TestIsExpired(t *testing.T) { func TestHash(t *testing.T) { tx := GetMockTx() res := tx.Hash() - assert.Equal(t, res, thor.Bytes32(thor.Bytes32{0x4b, 0xff, 0x70, 0x1, 0xfe, 0xc4, 0x2, 0x84, 0xd9, 0x3b, 0x4c, 0x45, 0x61, 0x7d, 0xc7, 0x41, 0xb9, 0xa8, 0x8e, 0xd5, 0x9d, 0xf, 0x1, 0xa3, 0x76, 0x39, 0x4c, 0x7b, 0xfe, 0xa6, 0xed, 0x24})) - + assert.Equal(t, res, thor.Bytes32{0x4b, 0xff, 0x70, 0x1, 0xfe, 0xc4, 0x2, 0x84, 0xd9, 0x3b, 0x4c, 0x45, 0x61, 0x7d, 0xc7, 0x41, 0xb9, 0xa8, 0x8e, 0xd5, 0x9d, 0xf, 0x1, 0xa3, 0x76, 0x39, 0x4c, 0x7b, 0xfe, 0xa6, 0xed, 0x24}) } func TestDependsOn(t *testing.T) { @@ -58,7 +57,6 @@ func TestTestFeatures(t *testing.T) { supportedFeatures := tx.Features(1) res := txx.TestFeatures(supportedFeatures) assert.Equal(t, res, nil) - } func TestToString(t *testing.T) { @@ -76,7 +74,6 @@ func TestToString(t *testing.T) { } func TestTxSize(t *testing.T) { - tx := GetMockTx() size := tx.Size() @@ -210,7 +207,6 @@ func TestTx(t *testing.T) { assert.Equal(t, "f8970184aabbccdd20f840df947567d83b7b8d80addcb281a71d54fc7b3364ffed82271086000000606060df947567d83b7b8d80addcb281a71d54fc7b3364ffed824e208600000060606081808252088083bc614ec0b841f76f3c91a834165872aa9464fc55b03a13f46ea8d3b858e528fcceaf371ad6884193c3f313ff8effbb57fe4d1adc13dceb933bedbf9dbb528d2936203d5511df00", func() string { d, _ := rlp.EncodeToBytes(trx); return hex.EncodeToString(d) }(), ) - } func TestDelegatedTx(t *testing.T) { diff --git a/txpool/blocklist_test.go b/txpool/blocklist_test.go index 0ae3ca705..8ff879bba 100644 --- a/txpool/blocklist_test.go +++ b/txpool/blocklist_test.go @@ -78,7 +78,7 @@ func TestSave(t *testing.T) { t.Errorf("Load failed: %s", err) } - fileContents, err := os.ReadFile(testFilePath) + fileContents, _ := os.ReadFile(testFilePath) str := string(fileContents) assert.True(t, strings.Contains(str, "0x25df024637d4e56c1ae9563987bf3e92c9f534c0")) assert.True(t, strings.Contains(str, "0x25df024637d4e56c1ae9563987bf3e92c9f534c1")) @@ -158,7 +158,6 @@ func TestFetch(t *testing.T) { t.Errorf("Fetch() missing address %s", addr) } } - }) } } diff --git a/txpool/tx_object_map_test.go b/txpool/tx_object_map_test.go index ae5c7dafa..52c4deb5a 100644 --- a/txpool/tx_object_map_test.go +++ b/txpool/tx_object_map_test.go @@ -111,7 +111,6 @@ func TestTxObjMap(t *testing.T) { assert.Equal(t, []*txObject{txObj3}, m.ToTxObjects()) assert.Equal(t, tx.Transactions{tx3}, m.ToTxs()) - } func TestLimitByDelegator(t *testing.T) { diff --git a/txpool/tx_object_test.go b/txpool/tx_object_test.go index 468e1a365..036e2c57a 100644 --- a/txpool/tx_object_test.go +++ b/txpool/tx_object_test.go @@ -136,7 +136,6 @@ func TestResolve(t *testing.T) { assert.Equal(t, tx, txObj.Transaction) assert.Equal(t, acc.Address, txObj.Origin()) - } func TestExecutable(t *testing.T) { diff --git a/txpool/tx_pool_test.go b/txpool/tx_pool_test.go index 8913c06d8..b59ee0682 100644 --- a/txpool/tx_pool_test.go +++ b/txpool/tx_pool_test.go @@ -129,7 +129,6 @@ func TestAddWithFullErrorUnsyncedChain(t *testing.T) { defer pool.Close() FillPoolWithTxs(pool, t) - } func TestAddWithFullErrorSyncedChain(t *testing.T) { @@ -140,7 +139,6 @@ func TestAddWithFullErrorSyncedChain(t *testing.T) { } func TestNewCloseWithError(t *testing.T) { - pool := newPoolWithParams(LIMIT, LIMIT_PER_ACCOUNT, " ", " ", uint64(time.Now().Unix())+10000) defer pool.Close() diff --git a/vm/contracts_test.go b/vm/contracts_test.go index a254c3e86..973ea1c14 100644 --- a/vm/contracts_test.go +++ b/vm/contracts_test.go @@ -20,8 +20,8 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "math/big" + "os" "testing" "time" @@ -184,7 +184,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { return } if common.Bytes2Hex(res) != test.Expected { - bench.Error(fmt.Sprintf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res))) + bench.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res)) return } }) @@ -278,16 +278,6 @@ func testJson(name, addr string, t *testing.T) { } } -func testJsonFail(name, addr string, t *testing.T) { - tests, err := loadJsonFail(name) - if err != nil { - t.Fatal(err) - } - for _, test := range tests { - testPrecompiledFailure(addr, test, t) - } -} - func benchJson(name, addr string, b *testing.B) { tests, err := loadJson(name) if err != nil { @@ -299,7 +289,7 @@ func benchJson(name, addr string, b *testing.B) { } func loadJson(name string) ([]precompiledTest, error) { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/precompiles/%v.json", name)) + data, err := os.ReadFile(fmt.Sprintf("testdata/precompiles/%v.json", name)) if err != nil { return nil, err } @@ -307,13 +297,3 @@ func loadJson(name string) ([]precompiledTest, error) { err = json.Unmarshal(data, &testcases) return testcases, err } - -func loadJsonFail(name string) ([]precompiledFailureTest, error) { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/precompiles/fail-%v.json", name)) - if err != nil { - return nil, err - } - var testcases []precompiledFailureTest - err = json.Unmarshal(data, &testcases) - return testcases, err -} diff --git a/vm/instructions_test.go b/vm/instructions_test.go index e1d146828..4ce3ec91b 100644 --- a/vm/instructions_test.go +++ b/vm/instructions_test.go @@ -464,13 +464,12 @@ func TestCreate2Addreses(t *testing.T) { expected: "0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0", }, } { - origin := common.BytesToAddress(common.FromHex(tt.origin)) salt := common.BytesToHash(common.FromHex(tt.salt)) code := common.FromHex(tt.code) codeHash := thor.Keccak256(code).Bytes() // THOR: Cannot use crypto.CreateAddress2 function. - // v1.8.14 -> v1.8.27 depedency issue. See patch.go file. + // v1.8.14 -> v1.8.27 dependency issue. See patch.go file. address := CreateAddress2(origin, salt, codeHash) /* stack := newstack() @@ -485,6 +484,5 @@ func TestCreate2Addreses(t *testing.T) { if !bytes.Equal(expected.Bytes(), address.Bytes()) { t.Errorf("test %d: expected %s, got %s", i, expected.String(), address.String()) } - } } diff --git a/vrf/vrf_test.go b/vrf/vrf_test.go index d21b8691a..3dace6795 100644 --- a/vrf/vrf_test.go +++ b/vrf/vrf_test.go @@ -9,7 +9,7 @@ import ( "crypto/ecdsa" "encoding/hex" "encoding/json" - "io/ioutil" + "io" "os" "reflect" "testing" @@ -34,7 +34,7 @@ func readCases(fileName string) ([]Case, error) { } defer jsonFile.Close() - byteValue, err2 := ioutil.ReadAll(jsonFile) + byteValue, err2 := io.ReadAll(jsonFile) if err2 != nil { return nil, err2 } @@ -190,7 +190,6 @@ func Test_Secp256K1Sha256Tai_vrf_Verify_bad_message(t *testing.T) { return } }) - } func BenchmarkVRF(b *testing.B) {