Skip to content

Commit c2e7b23

Browse files
author
Darren Kelly
committed
chore: add golines
1 parent e49a163 commit c2e7b23

51 files changed

Lines changed: 1745 additions & 304 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@ formatters:
5555
- goimports
5656
- gofmt
5757
- gofumpt
58+
- golines
5859
settings:
5960
gofmt:
6061
simplify: true
6162
goimports:
6263
local-prefixes:
6364
- github.com/vechain/thor
65+
golines:
66+
max-len: 160
67+
tab-len: 4
68+
shorten-comments: true
69+
# Default: true
70+
reformat-tags: false
6471
exclusions:
6572
generated: lax
6673
paths:

api/accounts/accounts_test.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,20 @@ const (
9191
)
9292

9393
var (
94-
gasLimit = math.MaxUint32
95-
addr = thor.BytesToAddress([]byte("to"))
96-
value = big.NewInt(10000)
97-
storageKey = thor.Bytes32{}
98-
genesisBlock *block.Block
99-
contractAddr thor.Address
100-
bytecode = common.Hex2Bytes("608060405234801561001057600080fd5b50610125806100206000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806324b8ba5f14604e578063bb4e3f4d14607b575b600080fd5b348015605957600080fd5b506079600480360381019080803560ff16906020019092919050505060cf565b005b348015608657600080fd5b5060b3600480360381019080803560ff169060200190929190803560ff16906020019092919050505060ec565b604051808260ff1660ff16815260200191505060405180910390f35b806000806101000a81548160ff021916908360ff16021790555050565b60008183019050929150505600a165627a7a723058201584add23e31d36c569b468097fe01033525686b59bbb263fb3ab82e9553dae50029")
101-
runtimeBytecode = common.Hex2Bytes("6080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806324b8ba5f14604e578063bb4e3f4d14607b575b600080fd5b348015605957600080fd5b506079600480360381019080803560ff16906020019092919050505060cf565b005b348015608657600080fd5b5060b3600480360381019080803560ff169060200190929190803560ff16906020019092919050505060ec565b604051808260ff1660ff16815260200191505060405180910390f35b806000806101000a81548160ff021916908360ff16021790555050565b60008183019050929150505600a165627a7a723058201584add23e31d36c569b468097fe01033525686b59bbb263fb3ab82e9553dae50029")
102-
ts *httptest.Server
103-
tclient *thorclient.Client
94+
gasLimit = math.MaxUint32
95+
addr = thor.BytesToAddress([]byte("to"))
96+
value = big.NewInt(10000)
97+
storageKey = thor.Bytes32{}
98+
genesisBlock *block.Block
99+
contractAddr thor.Address
100+
bytecode = common.Hex2Bytes(
101+
"608060405234801561001057600080fd5b50610125806100206000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806324b8ba5f14604e578063bb4e3f4d14607b575b600080fd5b348015605957600080fd5b506079600480360381019080803560ff16906020019092919050505060cf565b005b348015608657600080fd5b5060b3600480360381019080803560ff169060200190929190803560ff16906020019092919050505060ec565b604051808260ff1660ff16815260200191505060405180910390f35b806000806101000a81548160ff021916908360ff16021790555050565b60008183019050929150505600a165627a7a723058201584add23e31d36c569b468097fe01033525686b59bbb263fb3ab82e9553dae50029",
102+
)
103+
runtimeBytecode = common.Hex2Bytes(
104+
"6080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806324b8ba5f14604e578063bb4e3f4d14607b575b600080fd5b348015605957600080fd5b506079600480360381019080803560ff16906020019092919050505060cf565b005b348015608657600080fd5b5060b3600480360381019080803560ff169060200190929190803560ff16906020019092919050505060ec565b604051808260ff1660ff16815260200191505060405180910390f35b806000806101000a81548160ff021916908360ff16021790555050565b60008183019050929150505600a165627a7a723058201584add23e31d36c569b468097fe01033525686b59bbb263fb3ab82e9553dae50029",
105+
)
106+
ts *httptest.Server
107+
tclient *thorclient.Client
104108
)
105109

106110
func TestAccount(t *testing.T) {
@@ -252,7 +256,8 @@ func getStorage(t *testing.T) {
252256
require.NoError(t, err)
253257
assert.Equal(t, http.StatusBadRequest, statusCode, "bad storage key")
254258

255-
_, statusCode, err = tclient.RawHTTPClient().RawHTTPGet("/accounts/" + contractAddr.String() + "/storage/" + storageKey.String() + "?revision=" + invalidNumberRevision)
259+
_, statusCode, err = tclient.RawHTTPClient().
260+
RawHTTPGet("/accounts/" + contractAddr.String() + "/storage/" + storageKey.String() + "?revision=" + invalidNumberRevision)
256261
require.NoError(t, err)
257262
assert.Equal(t, http.StatusBadRequest, statusCode, "bad revision")
258263

@@ -274,7 +279,8 @@ func getStorage(t *testing.T) {
274279
func getStorageWithNonExistingRevision(t *testing.T) {
275280
revision64Len := "0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a"
276281

277-
res, statusCode, err := tclient.RawHTTPClient().RawHTTPGet("/accounts/" + contractAddr.String() + "/storage/" + storageKey.String() + "?revision=" + revision64Len)
282+
res, statusCode, err := tclient.RawHTTPClient().
283+
RawHTTPGet("/accounts/" + contractAddr.String() + "/storage/" + storageKey.String() + "?revision=" + revision64Len)
278284
require.NoError(t, err)
279285

280286
assert.Equal(t, http.StatusBadRequest, statusCode, "bad revision")

api/debug/debug.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ func New(
7878
}
7979

8080
// prepareClauseEnv prepares the runtime environment for the specified clause.
81-
func (d *Debug) prepareClauseEnv(ctx context.Context, block *block.Block, txID thor.Bytes32, clauseIndex uint32) (*runtime.Runtime, *runtime.TransactionExecutor, thor.Bytes32, error) {
81+
func (d *Debug) prepareClauseEnv(
82+
ctx context.Context,
83+
block *block.Block,
84+
txID thor.Bytes32,
85+
clauseIndex uint32,
86+
) (*runtime.Runtime, *runtime.TransactionExecutor, thor.Bytes32, error) {
8287
rt, err := consensus.New(
8388
d.repo,
8489
d.stater,
@@ -257,7 +262,15 @@ func (d *Debug) createTracer(name string, config json.RawMessage) (tracers.Trace
257262
return nil, errors.New("tracer is not defined")
258263
}
259264

260-
func (d *Debug) traceCall(ctx context.Context, tracer tracers.Tracer, header *block.Header, st *state.State, txCtx *xenv.TransactionContext, gas uint64, clause *tx.Clause) (any, error) {
265+
func (d *Debug) traceCall(
266+
ctx context.Context,
267+
tracer tracers.Tracer,
268+
header *block.Header,
269+
st *state.State,
270+
txCtx *xenv.TransactionContext,
271+
gas uint64,
272+
clause *tx.Clause,
273+
) (any, error) {
261274
signer, _ := header.Signer()
262275

263276
rt := runtime.New(
@@ -301,7 +314,15 @@ func (d *Debug) traceCall(ctx context.Context, tracer tracers.Tracer, header *bl
301314
return tracer.GetResult()
302315
}
303316

304-
func (d *Debug) debugStorage(ctx context.Context, contractAddress thor.Address, block *block.Block, txID thor.Bytes32, clauseIndex uint32, keyStart []byte, maxResult int) (*api.StorageRangeResult, error) {
317+
func (d *Debug) debugStorage(
318+
ctx context.Context,
319+
contractAddress thor.Address,
320+
block *block.Block,
321+
txID thor.Bytes32,
322+
clauseIndex uint32,
323+
keyStart []byte,
324+
maxResult int,
325+
) (*api.StorageRangeResult, error) {
305326
rt, _, _, err := d.prepareClauseEnv(ctx, block, txID, clauseIndex)
306327
if err != nil {
307328
return nil, err

api/debug/debug_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,12 @@ func testHandleTraceCallWithRevisionAsNonExistingID(t *testing.T) {
413413
func testHandleTraceCallWithMalfomredRevision(t *testing.T) {
414414
// Revision is a malformed byte array
415415
traceCallOption := &api.TraceCallOption{}
416-
res := httpPostAndCheckResponseStatus(t, "/debug/tracers/call?revision=012345678901234567890123456789012345678901234567890123456789012345", traceCallOption, 400)
416+
res := httpPostAndCheckResponseStatus(
417+
t,
418+
"/debug/tracers/call?revision=012345678901234567890123456789012345678901234567890123456789012345",
419+
traceCallOption,
420+
400,
421+
)
417422
assert.Equal(t, "revision: invalid prefix", strings.TrimSpace(res))
418423

419424
// Revision is a not accepted string

api/fees/data.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func getBaseFee(baseFee *big.Int) *hexutil.Big {
5858

5959
// resolveRange resolves the base fees, gas used ratios and priority fees for the given block range.
6060
// Assumes that the boundaries (newest block - block count) are correct and validated beforehand.
61-
func (fd *FeesData) resolveRange(newestBlockSummary *chain.BlockSummary, blockCount uint32, rewardPercentiles []float64) (thor.Bytes32, []*hexutil.Big, []float64, [][]*hexutil.Big, error) {
61+
func (fd *FeesData) resolveRange(
62+
newestBlockSummary *chain.BlockSummary,
63+
blockCount uint32,
64+
rewardPercentiles []float64,
65+
) (thor.Bytes32, []*hexutil.Big, []float64, [][]*hexutil.Big, error) {
6266
newestBlockID := newestBlockSummary.Header.ID()
6367

6468
baseFees := make([]*hexutil.Big, blockCount)

api/fees/fees.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ func (f *Fees) validateRewardPercentiles(req *http.Request) ([]float64, error) {
140140
return nil, restutil.BadRequest(errors.New("rewardPercentiles values must be between 0 and 100"))
141141
}
142142
if i > 0 && val < rewardPercentiles[i-1] {
143-
return nil, restutil.BadRequest(errors.New(fmt.Sprintf("reward percentiles must be in ascending order, but %f is less than %f", val, rewardPercentiles[i-1])))
143+
return nil, restutil.BadRequest(
144+
errors.New(fmt.Sprintf("reward percentiles must be in ascending order, but %f is less than %f", val, rewardPercentiles[i-1])),
145+
)
144146
}
145147
rewardPercentiles = append(rewardPercentiles, val)
146148
}

api/fees/fees_test.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ func initFeesServer(t *testing.T, backtraceLimit int, fixedCacheSize int, number
166166
Clause(cla).
167167
BlockRef(tx.NewBlockRef(uint32(i))).
168168
Build()
169-
require.NoError(t, thorChain.MintBlock(genesis.DevAccounts()[0], tx.MustSign(trx1, genesis.DevAccounts()[0].PrivateKey), tx.MustSign(trx2, genesis.DevAccounts()[0].PrivateKey)))
169+
require.NoError(
170+
t,
171+
thorChain.MintBlock(
172+
genesis.DevAccounts()[0],
173+
tx.MustSign(trx1, genesis.DevAccounts()[0].PrivateKey),
174+
tx.MustSign(trx2, genesis.DevAccounts()[0].PrivateKey),
175+
),
176+
)
170177
}
171178

172179
allBlocks, err := thorChain.GetAllBlocks()
@@ -188,9 +195,13 @@ func getFeeHistoryWithSummaries(t *testing.T, tclient *thorclient.Client, bestch
188195
expectedOldestBlock, err := bestchain.GetBlockID(2)
189196
require.NoError(t, err)
190197
expectedFeesHistory := api.FeesHistory{
191-
OldestBlock: expectedOldestBlock,
192-
BaseFeePerGas: []*hexutil.Big{(*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee))},
193-
GasUsedRatio: []float64{expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, expectedGasPriceUsedRatio},
198+
OldestBlock: expectedOldestBlock,
199+
BaseFeePerGas: []*hexutil.Big{
200+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
201+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
202+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
203+
},
204+
GasUsedRatio: []float64{expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, expectedGasPriceUsedRatio},
194205
}
195206
assert.Equal(t, expectedFeesHistory, feesHistory)
196207
}
@@ -233,9 +244,14 @@ func getFeeHistoryBestBlock(t *testing.T, tclient *thorclient.Client, bestchain
233244
expectedOldestBlock, err := bestchain.GetBlockID(6)
234245
require.NoError(t, err)
235246
expectedFeesHistory := api.FeesHistory{
236-
OldestBlock: expectedOldestBlock,
237-
BaseFeePerGas: []*hexutil.Big{(*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee))},
238-
GasUsedRatio: []float64{expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, expectedGasPriceUsedRatio},
247+
OldestBlock: expectedOldestBlock,
248+
BaseFeePerGas: []*hexutil.Big{
249+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
250+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
251+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
252+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
253+
},
254+
GasUsedRatio: []float64{expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, expectedGasPriceUsedRatio},
239255
}
240256

241257
assert.Equal(t, expectedFeesHistory, feesHistory)
@@ -414,9 +430,13 @@ func getFeeHistoryNextBlock(t *testing.T, tclient *thorclient.Client, bestchain
414430
expectedOldestBlock, err := bestchain.GetBlockID(8)
415431
require.NoError(t, err)
416432
expectedFeesHistory := api.FeesHistory{
417-
OldestBlock: expectedOldestBlock,
418-
BaseFeePerGas: []*hexutil.Big{(*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee)), (*hexutil.Big)(big.NewInt(expectedBaseFee))},
419-
GasUsedRatio: []float64{expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, 0},
433+
OldestBlock: expectedOldestBlock,
434+
BaseFeePerGas: []*hexutil.Big{
435+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
436+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
437+
(*hexutil.Big)(big.NewInt(expectedBaseFee)),
438+
},
439+
GasUsedRatio: []float64{expectedGasPriceUsedRatio, expectedGasPriceUsedRatio, 0},
420440
}
421441

422442
assert.Equal(t, expectedFeesHistory, feesHistory)
@@ -453,7 +473,9 @@ func getFeePriority(t *testing.T, tclient *thorclient.Client, bestchain *chain.C
453473
}
454474

455475
expectedFeesPriority := api.FeesPriority{
456-
MaxPriorityFeePerGas: (*hexutil.Big)(new(big.Int).Div(new(big.Int).Mul(big.NewInt(thor.InitialBaseFee), big.NewInt(priorityFeesPercentage)), big.NewInt(100))),
476+
MaxPriorityFeePerGas: (*hexutil.Big)(
477+
new(big.Int).Div(new(big.Int).Mul(big.NewInt(thor.InitialBaseFee), big.NewInt(priorityFeesPercentage)), big.NewInt(100)),
478+
),
457479
}
458480

459481
assert.Equal(t, expectedFeesPriority, feesPriority)

0 commit comments

Comments
 (0)