Skip to content

Commit 39df088

Browse files
alarso16ARR4N
andauthored
style: revive fix based on feedback (#1187)
Signed-off-by: Austin Larson <78000745+alarso16@users.noreply.github.com> Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
1 parent 9b32562 commit 39df088

File tree

28 files changed

+184
-99
lines changed

28 files changed

+184
-99
lines changed

core/blockchain_ext_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ func EmptyBlocksTest(t *testing.T, create createFunc) {
925925
blockchain.DrainAcceptorQueue()
926926

927927
// Nothing to assert about the state
928-
checkState := func(_ *state.StateDB) error {
928+
checkState := func(*state.StateDB) error {
929929
return nil
930930
}
931931

core/extstate/firewood_database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func (db *firewoodAccessorDb) OpenTrie(root common.Hash) (state.Trie, error) {
2929
}
3030

3131
// OpenStorageTrie opens a wrapped version of the account trie.
32-
func (*firewoodAccessorDb) OpenStorageTrie(_ common.Hash, _ common.Address, root common.Hash, self state.Trie) (state.Trie, error) {
32+
func (*firewoodAccessorDb) OpenStorageTrie(_ common.Hash, _ common.Address, accountRoot common.Hash, self state.Trie) (state.Trie, error) {
3333
accountTrie, ok := self.(*firewood.AccountTrie)
3434
if !ok {
3535
return nil, fmt.Errorf("Invalid account trie type: %T", self)
3636
}
37-
return firewood.NewStorageTrie(accountTrie, root)
37+
return firewood.NewStorageTrie(accountTrie, accountRoot)
3838
}
3939

4040
// CopyTrie returns a deep copy of the given trie.

core/fifo_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (f *BufferFIFOCache[K, V]) remove(key K) error {
6565

6666
type NoOpFIFOCache[K comparable, V any] struct{}
6767

68-
func (*NoOpFIFOCache[K, V]) Put(_ K, _ V) {}
69-
func (*NoOpFIFOCache[K, V]) Get(_ K) (V, bool) {
68+
func (*NoOpFIFOCache[K, V]) Put(K, V) {}
69+
func (*NoOpFIFOCache[K, V]) Get(K) (V, bool) {
7070
return *new(V), false
7171
}

core/state_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (*MockTrieDB) Size() (common.StorageSize, common.StorageSize, common.Storag
3434
return 0, 0, 0
3535
}
3636

37-
func (*MockTrieDB) Cap(_ common.StorageSize) error {
37+
func (*MockTrieDB) Cap(common.StorageSize) error {
3838
return nil
3939
}
4040

eth/api_debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (api *DebugAPI) Preimage(ctx context.Context, hash common.Hash) (hexutil.By
102102
// and returns them as a JSON list of block hashes.
103103
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*ethapi.BadBlockArgs, error) {
104104
internalAPI := ethapi.NewBlockChainAPI(api.eth.APIBackend)
105-
return internalAPI.GetBadBlocks()
105+
return internalAPI.GetBadBlocks(ctx)
106106
}
107107

108108
// AccountRangeMaxResults is the maximum number of results to be returned per call

internal/ethapi/api_extra.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/ava-labs/libevm/rlp"
1414

1515
"github.com/ava-labs/coreth/core"
16+
"github.com/ava-labs/coreth/params"
1617
"github.com/ava-labs/coreth/rpc"
1718
)
1819

@@ -23,6 +24,11 @@ type DetailedExecutionResult struct {
2324
ReturnData hexutil.Bytes `json:"returnData"` // Data from evm(function result or data supplied with revert opcode)
2425
}
2526

27+
// GetChainConfig returns the chain config.
28+
func (api *BlockChainAPI) GetChainConfig(context.Context) *params.ChainConfig {
29+
return api.b.ChainConfig()
30+
}
31+
2632
// CallDetailed performs the same call as Call, but returns the full context
2733
func (s *BlockChainAPI) CallDetailed(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (*DetailedExecutionResult, error) {
2834
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, nil, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
@@ -63,7 +69,7 @@ type BadBlockArgs struct {
6369

6470
// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
6571
// and returns them as a JSON list of block hashes.
66-
func (s *BlockChainAPI) GetBadBlocks() ([]*BadBlockArgs, error) {
72+
func (s *BlockChainAPI) GetBadBlocks(context.Context) ([]*BadBlockArgs, error) {
6773
var (
6874
badBlocks, reasons = s.b.BadBlocks()
6975
results = make([]*BadBlockArgs, 0, len(badBlocks))

internal/ethapi/api_extra_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,87 @@
44
package ethapi
55

66
import (
7+
"context"
78
"errors"
89
"math/big"
910
"testing"
1011

1112
"github.com/ava-labs/libevm/common"
13+
"github.com/ava-labs/libevm/common/hexutil"
1214
"github.com/ava-labs/libevm/core/types"
1315
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
1417
"go.uber.org/mock/gomock"
1518

19+
"github.com/ava-labs/coreth/consensus/dummy"
20+
"github.com/ava-labs/coreth/core"
21+
"github.com/ava-labs/coreth/params"
1622
"github.com/ava-labs/coreth/rpc"
23+
24+
ethparams "github.com/ava-labs/libevm/params"
1725
)
1826

27+
func TestBlockchainAPI_GetChainConfig(t *testing.T) {
28+
t.Parallel()
29+
30+
ctrl := gomock.NewController(t)
31+
defer ctrl.Finish()
32+
33+
wantConfig := &params.ChainConfig{
34+
ChainID: big.NewInt(43114),
35+
}
36+
backend := NewMockBackend(ctrl)
37+
backend.EXPECT().ChainConfig().Return(wantConfig)
38+
39+
api := NewBlockChainAPI(backend)
40+
41+
gotConfig := api.GetChainConfig(context.Background())
42+
assert.Equal(t, wantConfig, gotConfig)
43+
}
44+
45+
// Copy one test case from TestCall
46+
func TestBlockchainAPI_CallDetailed(t *testing.T) {
47+
t.Parallel()
48+
// Initialize test accounts
49+
var (
50+
accounts = newAccounts(2)
51+
genesis = &core.Genesis{
52+
Config: params.TestChainConfig,
53+
Alloc: types.GenesisAlloc{
54+
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
55+
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
56+
},
57+
}
58+
genBlocks = 10
59+
signer = types.HomesteadSigner{}
60+
blockNumber = rpc.LatestBlockNumber
61+
)
62+
api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, dummy.NewCoinbaseFaker(), func(i int, b *core.BlockGen) {
63+
// Transfer from account[0] to account[1]
64+
// value: 1000 wei
65+
// fee: 0 wei
66+
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key)
67+
b.AddTx(tx)
68+
}))
69+
70+
result, err := api.CallDetailed(
71+
context.Background(),
72+
TransactionArgs{
73+
From: &accounts[0].addr,
74+
To: &accounts[1].addr,
75+
Value: (*hexutil.Big)(big.NewInt(1000)),
76+
},
77+
rpc.BlockNumberOrHash{BlockNumber: &blockNumber},
78+
nil,
79+
)
80+
require.NoError(t, err)
81+
require.NotNil(t, result)
82+
require.Equal(t, 0, result.ErrCode)
83+
require.Nil(t, result.ReturnData)
84+
require.Equal(t, ethparams.TxGas, result.UsedGas)
85+
require.Empty(t, result.Err)
86+
}
87+
1988
func TestBlockChainAPI_stateQueryBlockNumberAllowed(t *testing.T) {
2089
t.Parallel()
2190

network/network_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func TestRequestAnyRequestsRoutingAndResponse(t *testing.T) {
134134
func TestAppRequestOnCtxCancellation(t *testing.T) {
135135
codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
136136
sender := testAppSender{
137-
sendAppRequestFn: func(_ context.Context, _ set.Set[ids.NodeID], _ uint32, _ []byte) error {
137+
sendAppRequestFn: func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
138138
return nil
139139
},
140-
sendAppResponseFn: func(_ ids.NodeID, _ uint32, _ []byte) error {
140+
sendAppResponseFn: func(ids.NodeID, uint32, []byte) error {
141141
return nil
142142
},
143143
}
@@ -263,7 +263,7 @@ func TestAppRequestOnShutdown(t *testing.T) {
263263
called bool
264264
)
265265
sender := testAppSender{
266-
sendAppRequestFn: func(_ context.Context, _ set.Set[ids.NodeID], _ uint32, _ []byte) error {
266+
sendAppRequestFn: func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
267267
wg.Add(1)
268268
go func() {
269269
called = true
@@ -319,7 +319,7 @@ func TestSyncedAppRequestAnyOnCtxCancellation(t *testing.T) {
319319
}
320320
return nil
321321
},
322-
sendAppResponseFn: func(_ ids.NodeID, _ uint32, _ []byte) error {
322+
sendAppResponseFn: func(ids.NodeID, uint32, []byte) error {
323323
return nil
324324
},
325325
}
@@ -639,7 +639,7 @@ func (t testAppSender) SendAppGossip(_ context.Context, config common.SendConfig
639639
return t.sendAppGossipFn(config, message)
640640
}
641641

642-
func (testAppSender) SendAppError(_ context.Context, _ ids.NodeID, _ uint32, _ int32, _ string) error {
642+
func (testAppSender) SendAppError(context.Context, ids.NodeID, uint32, int32, string) error {
643643
panic("not implemented")
644644
}
645645

@@ -751,12 +751,12 @@ type testSDKHandler struct {
751751
appRequested bool
752752
}
753753

754-
func (*testSDKHandler) AppGossip(_ context.Context, _ ids.NodeID, _ []byte) {
754+
func (*testSDKHandler) AppGossip(context.Context, ids.NodeID, []byte) {
755755
// TODO implement me
756756
panic("implement me")
757757
}
758758

759-
func (t *testSDKHandler) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, _ []byte) ([]byte, *common.AppError) {
759+
func (t *testSDKHandler) AppRequest(context.Context, ids.NodeID, time.Time, []byte) ([]byte, *common.AppError) {
760760
t.appRequested = true
761761
return nil, nil
762762
}

params/config_libevm.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ var payloads ethparams.ExtraPayloads[*extras.ChainConfig, RulesExtra]
3232
// constructRulesExtra acts as an adjunct to the [params.ChainConfig.Rules]
3333
// method. Its primary purpose is to construct the extra payload for the
3434
// [params.Rules] but it MAY also modify the [params.Rules].
35-
func constructRulesExtra(_ *ethparams.ChainConfig, _ *ethparams.Rules, cEx *extras.ChainConfig, _ *big.Int, _ bool, timestamp uint64) RulesExtra {
35+
//
36+
//nolint:revive // General-purpose types lose the meaning of args if unused ones are removed
37+
func constructRulesExtra(c *ethparams.ChainConfig, r *ethparams.Rules, cEx *extras.ChainConfig, blockNum *big.Int, isMerge bool, timestamp uint64) RulesExtra {
3638
var rules RulesExtra
3739
if cEx == nil {
3840
return rules

params/extras/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ type ChainConfig struct {
110110
UpgradeConfig `json:"-"` // Config specified in upgradeBytes (avalanche network upgrades or enable/disabling precompiles). Not serialized.
111111
}
112112

113-
func (c *ChainConfig) CheckConfigCompatible(newcfg_ *ethparams.ChainConfig, _ *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError {
113+
//nolint:revive // General-purpose types lose the meaning of args if unused ones are removed
114+
func (c *ChainConfig) CheckConfigCompatible(newcfg_ *ethparams.ChainConfig, headNumber *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError {
114115
if c == nil {
115116
return nil
116117
}

0 commit comments

Comments
 (0)