Merge pull request #3567 from nspcc-dev/go-1.22

Go 1.22
This commit is contained in:
Roman Khimov 2024-09-02 22:32:40 +03:00 committed by GitHub
commit d47fe392fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
149 changed files with 384 additions and 406 deletions

View file

@ -156,19 +156,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, windows-2022, macos-12, macos-14]
go_versions: [ '1.21', '1.22', '1.23' ]
go_versions: [ '1.22', '1.23' ]
exclude:
# Only latest Go version for Windows and MacOS.
- os: windows-2022
go_versions: '1.21'
- os: windows-2022
go_versions: '1.22'
- os: macos-12
go_versions: '1.21'
- os: macos-12
go_versions: '1.22'
- os: macos-14
go_versions: '1.21'
- os: macos-14
go_versions: '1.22'
# Exclude latest Go version for Ubuntu as Coverage uses it.

View file

@ -51,7 +51,7 @@ NeoGo, `:latest` points to the latest release) or build yourself.
### Building
Building NeoGo requires Go 1.21+ and `make`:
Building NeoGo requires Go 1.22+ and `make`:
```
make

View file

@ -4,6 +4,7 @@ import (
"io"
"math/big"
"path/filepath"
"slices"
"strconv"
"strings"
"testing"
@ -80,7 +81,7 @@ func TestNEP17Balance(t *testing.T) {
e.CheckNextLine(t, "^Account "+testcli.TestWalletMultiAccount1)
// The order of assets is undefined.
for i := 0; i < 2; i++ {
for range 2 {
line := e.GetNextLine(t)
if strings.Contains(line, "GAS") {
e.CheckLine(t, line, "^\\s*GAS:\\s+GasToken \\("+e.Chain.UtilityTokenHash().StringLE()+"\\)")
@ -133,8 +134,7 @@ func TestNEP17Transfer(t *testing.T) {
}
t.Run("missing receiver", func(t *testing.T) {
as := append([]string{}, args[:8]...)
as = append(as, args[10:]...)
as := slices.Concat(args[:8], args[10:])
e.In.WriteString("one\r")
e.RunWithErrorCheck(t, `Required flag "to" not set`, as...)
e.In.Reset()

View file

@ -200,11 +200,10 @@ func queryCandidates(ctx *cli.Context) error {
if !a.Active && b.Active {
return -1
}
res := cmp.Compare(a.Votes, b.Votes)
if res != 0 {
return res
}
return a.PublicKey.Cmp(&b.PublicKey)
return cmp.Or(
cmp.Compare(a.Votes, b.Votes),
a.PublicKey.Cmp(&b.PublicKey),
)
})
var res []byte
res = fmt.Appendf(res, "Key\tVotes\tCommittee\tConsensus\n")

View file

@ -417,7 +417,7 @@ func initSmartContract(ctx *cli.Context) error {
gm := []byte("module " + contractName + `
go 1.21
go 1.22
require (
github.com/nspcc-dev/neo-go/pkg/interop ` + ver + `

View file

@ -353,7 +353,7 @@ require (
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0
)
replace github.com/nspcc-dev/neo-go/pkg/interop => ` + filepath.Join(wd, "../../pkg/interop") + `
go 1.21`)
go 1.22`)
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
return filename
}

View file

@ -362,7 +362,7 @@ func getMatchingTokenRPC(ctx *cli.Context, c *rpcclient.Client, addr util.Uint16
func getMatchingTokenAux(ctx *cli.Context, get func(i int) *wallet.Token, n int, name string, standard string) (*wallet.Token, error) {
var token *wallet.Token
var count int
for i := 0; i < n; i++ {
for i := range n {
t := get(i)
if t != nil && (t.Hash.StringLE() == name || t.Address() == name || t.Symbol == name || t.Name == name) && t.Standard == standard {
if count == 1 {
@ -540,7 +540,7 @@ func multiTransferNEP17(ctx *cli.Context) error {
recipients []transferTarget
cosignersSepPos = ctx.NArg() // `--` position.
)
for i := 0; i < ctx.NArg(); i++ {
for i := range ctx.NArg() {
arg := ctx.Args().Get(i)
if arg == cmdargs.CosignersSeparator {
cosignersSepPos = i
@ -561,7 +561,7 @@ func multiTransferNEP17(ctx *cli.Context) error {
}
cache := make(map[string]*wallet.Token)
for i := 0; i < cosignersSepPos; i++ {
for i := range cosignersSepPos {
arg := ctx.Args().Get(i)
ss := strings.SplitN(arg, ":", 3)
if len(ss) != 3 {

View file

@ -1062,7 +1062,7 @@ func TestWalletDumpKeys(t *testing.T) {
e.CheckNextLine(t, pubRegex)
e.CheckNextLine(t, "^\\s*$")
e.CheckNextLine(t, "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq")
for i := 0; i < 4; i++ {
for range 4 {
e.CheckNextLine(t, pubRegex)
}
e.CheckNextLine(t, "^\\s*$")
@ -1085,7 +1085,7 @@ func TestWalletDumpKeys(t *testing.T) {
cmd := append(cmd, "-a", "NVTiAjNgagDkTr5HTzDmQP9kPwPHN5BgVq")
e.Run(t, cmd...)
e.CheckNextLine(t, "3 out of 4 multisig contract")
for i := 0; i < 4; i++ {
for range 4 {
e.CheckNextLine(t, pubRegex)
}
e.CheckEOF(t)

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/engine
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/events
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/iterator
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/nft
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,6 +1,6 @@
module github.com/nspcc-dev/neo-go/examples/nft-nd-nns
go 1.21
go 1.22
require (
github.com/nspcc-dev/neo-go v0.102.1-0.20231020181554-d89c8801d689

View file

@ -158,7 +158,7 @@ func TestRegisterAndRenew(t *testing.T) {
c.InvokeWithFeeFail(t, "GAS limit exceeded", defaultNameServiceSysfee, "register", "neo.org", e.CommitteeHash)
c.InvokeWithFeeFail(t, "GAS limit exceeded", defaultNameServiceDomainPrice, "register", "neo.com", e.CommitteeHash)
var maxLenFragment string
for i := 0; i < maxDomainNameFragmentLength; i++ {
for i := range maxDomainNameFragmentLength {
maxLenFragment += "q"
}
c.Invoke(t, true, "isAvailable", maxLenFragment+".com")

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/nft-nd
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/oracle
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/runtime
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/storage
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/timer
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/token
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,6 +1,6 @@
module github.com/nspcc-dev/neo-go/examples/zkp/cubic
go 1.21
go 1.22
require (
github.com/consensys/gnark v0.10.0

View file

@ -315,7 +315,7 @@ func setup(t *testing.T, ccs constraint.ConstraintSystem, phase1ResponsePath str
// receive a []byte, deserialize it, add his contribution and send back to
// coordinator, like it is done in https://github.com/bnb-chain/zkbnb-setup
// for BN254 elliptic curve.
for i := 0; i < nContributionsPhase2; i++ {
for i := range nContributionsPhase2 {
srs2.Contribute()
}

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/examples/zkp/xor
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/nspcc-dev/neo-go
go 1.21
go 1.22
require (
github.com/chzyer/readline v1.5.1

View file

@ -19,7 +19,7 @@ var valuesPrefix = []byte{0x01}
func _deploy(data any, isUpdate bool) {
if !isUpdate {
ctx := storage.GetContext()
for i := 0; i < valuesCount; i++ {
for i := range valuesCount {
key := append(valuesPrefix, byte(i))
storage.Put(ctx, key, i)
}

View file

@ -1,5 +1,5 @@
module github.com/nspcc-dev/neo-go/internal/examples/oracle
go 1.21
go 1.22
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240727093519-1a48f1ce43ec

View file

@ -1,8 +1,7 @@
package random
import (
"math/rand"
"time"
"math/rand/v2"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -27,14 +26,14 @@ func Bytes(n int) []byte {
// Fill fills buffer with random bytes.
func Fill(buf []byte) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
// Rand reader returns no errors
r.Read(buf)
for i := range buf {
buf[i] = byte(rand.Int())
}
}
// Int returns a random integer in [minI,maxI).
func Int(minI, maxI int) int {
return minI + rand.Intn(maxI-minI)
return minI + rand.IntN(maxI-minI)
}
// Uint256 returns a random Uint256.
@ -48,8 +47,3 @@ func Uint160() util.Uint160 {
str := String(20)
return hash.RipeMD160([]byte(str))
}
func init() {
//nolint:staticcheck
rand.Seed(time.Now().UTC().UnixNano())
}

View file

@ -128,7 +128,7 @@ func CommitteeAddress() string {
// Sign signs data by all consensus nodes and returns invocation script.
func Sign(h hash.Hashable) []byte {
buf := io.NewBufBinWriter()
for i := 0; i < 3; i++ {
for i := range 3 {
pKey := PrivateKey(i)
sig := pKey.SignHashable(uint32(Network()), h)
if len(sig) != 64 {

View file

@ -377,7 +377,7 @@ func (e *Executor) CheckTxTestInvokeOutput(t *testing.T, scriptSize int) {
func (e *Executor) CheckScriptDump(t *testing.T, scriptSize int) {
e.CheckNextLine(t, `INDEX\s+`)
for i := 0; i < scriptSize; i++ {
for range scriptSize {
e.CheckNextLine(t, `\d+\s+\w+`)
}
}

View file

@ -229,7 +229,7 @@ func isExprNil(e ast.Expr) bool {
// indexOfStruct returns the index of the given field inside that struct.
// If the struct does not contain that field, it will return -1.
func indexOfStruct(strct *types.Struct, fldName string) int {
for i := 0; i < strct.NumFields(); i++ {
for i := range strct.NumFields() {
if strct.Field(i).Name() == fldName {
return i
}

View file

@ -383,7 +383,7 @@ func (c *codegen) isVerifyFunc(decl *ast.FuncDecl) bool {
}
func (c *codegen) clearSlots(n int) {
for i := 0; i < n; i++ {
for i := range n {
emit.Opcodes(c.prog.BinWriter, opcode.PUSHNULL)
c.emitStoreByIndex(varLocal, i)
}
@ -680,7 +680,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
ast.Walk(c, n.Rhs[0])
c.emitToken(n.Tok, c.typeOf(n.Rhs[0]))
}
for i := 0; i < len(n.Lhs); i++ {
for i := range n.Lhs {
switch t := n.Lhs[i].(type) {
case *ast.Ident:
if n.Tok == token.DEFINE {
@ -1099,7 +1099,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
f := c.typeOf(n.Fun).Underlying().(*types.Signature)
sz = f.Results().Len()
}
for i := 0; i < sz; i++ {
for range sz {
emit.Opcodes(c.prog.BinWriter, opcode.DROP)
}
}
@ -1662,7 +1662,7 @@ func (c *codegen) dropStackLabel() {
func (c *codegen) dropItems(n int) {
if n < 4 {
for i := 0; i < n; i++ {
for range n {
emit.Opcodes(c.prog.BinWriter, opcode.DROP)
}
return
@ -1930,7 +1930,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
opcode.INC) // x y cnt+1
emit.Jmp(c.prog.BinWriter, opcode.JMPL, start)
c.setLabel(after)
for i := 0; i < 4; i++ { // leave x on stack
for range 4 { // leave x on stack
emit.Opcodes(c.prog.BinWriter, opcode.DROP)
}
} else {
@ -2012,7 +2012,7 @@ func (c *codegen) emitConvert(typ stackitem.Type) {
func (c *codegen) convertByteArray(elems []ast.Expr) {
buf := make([]byte, len(elems))
varIndices := []int{}
for i := 0; i < len(elems); i++ {
for i := range elems {
t := c.typeAndValueOf(elems[i])
if t.Value != nil {
val, _ := constant.Int64Val(t.Value)
@ -2508,7 +2508,7 @@ func removeNOPs(b []byte, nopOffsets []int, sequencePoints map[string][]DebugSeq
// 2. Convert instructions.
copyOffset := 0
l := len(nopOffsets)
for i := 0; i < l; i++ {
for i := range l {
start := nopOffsets[i]
end := len(b)
if i != l-1 {

View file

@ -883,11 +883,11 @@ func TestMultipleFuncSameName(t *testing.T) {
func TestConstDontUseSlots(t *testing.T) {
const count = 256
buf := bytes.NewBufferString("package foo\n")
for i := 0; i < count; i++ {
for i := range count {
buf.WriteString(fmt.Sprintf("const n%d = 1\n", i))
}
buf.WriteString("func Main() int { sum := 0\n")
for i := 0; i < count; i++ {
for i := range count {
buf.WriteString(fmt.Sprintf("sum += n%d\n", i))
}
buf.WriteString("return sum }")
@ -899,11 +899,11 @@ func TestConstDontUseSlots(t *testing.T) {
func TestUnderscoreVarsDontUseSlots(t *testing.T) {
const count = 128
buf := bytes.NewBufferString("package foo\n")
for i := 0; i < count; i++ {
for i := range count {
buf.WriteString(fmt.Sprintf("var _, n%d = 1, 1\n", i))
}
buf.WriteString("func Main() int { sum := 0\n")
for i := 0; i < count; i++ {
for i := range count {
buf.WriteString(fmt.Sprintf("sum += n%d\n", i))
}
buf.WriteString("return sum }")

View file

@ -124,7 +124,7 @@ func (c *codegen) inlineCall(f *funcScope, n *ast.CallExpr) {
ast.Walk(c, f.decl.Body)
c.setLabel(c.inlineContext[offSz].returnLabel)
if c.scope.voidCalls[n] {
for i := 0; i < f.decl.Type.Results.NumFields(); i++ {
for range f.decl.Type.Results.NumFields() {
emit.Opcodes(c.prog.BinWriter, opcode.DROP)
}
}

View file

@ -15,7 +15,7 @@ func TestManyVariables(t *testing.T) {
const count = 155
buf := bytes.NewBufferString("package main\n")
for i := 0; i < count; i++ {
for i := range count {
buf.WriteString(fmt.Sprintf("var a%d = %d\n", i, i))
}
buf.WriteString("func Main() int {\nreturn 7\n}\n")

View file

@ -361,7 +361,7 @@ func runNativeTestCase(t *testing.T, b *nef.File, di *compiler.DebugInfo, ctr in
if t.CallFlag != md.RequiredFlags {
return fmt.Errorf("wrong flags %v", t.CallFlag)
}
for i := 0; i < int(t.ParamCount); i++ {
for range t.ParamCount {
_ = v.Estack().Pop()
}
if v.Estack().Len() != 0 {

View file

@ -151,7 +151,7 @@ func runSyscallTestCase(t *testing.T, ic *interop.Context, realName string,
if ic.VM.Estack().Len() < f.ParamCount {
return errors.New("not enough parameters")
}
for i := 0; i < f.ParamCount; i++ {
for range f.ParamCount {
ic.VM.Estack().Pop()
}
if !tc.isVoid {
@ -385,7 +385,7 @@ func TestInteropTypesComparison(t *testing.T) {
typeCheck := func(t *testing.T, typeName string, typeLen int) {
t.Run(typeName, func(t *testing.T) {
var ha, hb string
for i := 0; i < typeLen; i++ {
for i := range typeLen {
if i == typeLen-1 {
ha += "2"
hb += "3"

View file

@ -195,7 +195,7 @@ func TestService_GetVerified(t *testing.T) {
srv := newTestService(t)
srv.dbft.Start(0)
var txs []*transaction.Transaction
for i := 0; i < 4; i++ {
for i := range 4 {
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 100000)
tx.Nonce = 123 + uint32(i)
tx.ValidUntilBlock = 1
@ -208,7 +208,7 @@ func TestService_GetVerified(t *testing.T) {
hashes := []util.Uint256{txs[0].Hash(), txs[1].Hash(), txs[2].Hash()}
// Everyone sends a message.
for i := 0; i < 4; i++ {
for i := range 4 {
p := new(Payload)
// One PrepareRequest and three ChangeViews.
if i == 1 {
@ -578,7 +578,7 @@ func addSender(t *testing.T, txs ...*transaction.Transaction) {
func signTx(t *testing.T, bc Ledger, txs ...*transaction.Transaction) {
validators := make([]*keys.PublicKey, 4)
privNetKeys := make([]*keys.PrivateKey, 4)
for i := 0; i < 4; i++ {
for i := range 4 {
privNetKeys[i] = testchain.PrivateKey(i)
validators[i] = privNetKeys[i].PublicKey()
}

View file

@ -3,7 +3,7 @@ package consensus
import (
"encoding/hex"
gio "io"
"math/rand"
"math/rand/v2"
"testing"
"github.com/nspcc-dev/dbft"
@ -200,7 +200,7 @@ func randomPrepareRequest(t *testing.T) *prepareRequest {
transactionHashes: make([]util.Uint256, txCount),
}
for i := 0; i < txCount; i++ {
for i := range txCount {
req.transactionHashes[i] = random.Uint256()
}

View file

@ -23,7 +23,7 @@ func testRecoveryMessageSetters(t *testing.T, enableStateRoot bool) {
srv := newTestServiceWithState(t, enableStateRoot)
privs := make([]*privateKey, testchain.Size())
pubs := make([]dbft.PublicKey, testchain.Size())
for i := 0; i < testchain.Size(); i++ {
for i := range testchain.Size() {
privs[i], pubs[i] = getTestValidator(i)
}

View file

@ -27,7 +27,7 @@ func BenchmarkBlockchain_VerifyWitness(t *testing.B) {
tx := e.NewTx(t, []neotest.Signer{acc}, e.NativeHash(t, nativenames.Gas), "transfer", acc.ScriptHash(), acc.Script(), 1, nil)
t.ResetTimer()
for n := 0; n < t.N; n++ {
for range t.N {
_, err := bc.VerifyWitness(tx.Signers[0].Account, tx, &tx.Scripts[0], 100000000)
require.NoError(t, err)
}
@ -92,9 +92,9 @@ func benchmarkForEachNEP17Transfer(t *testing.B, ps storage.Store, startFromBloc
acc := random.Uint160()
from := e.Validator.ScriptHash()
for j := 0; j < chainHeight; j++ {
for range chainHeight {
b := smartcontract.NewBuilder()
for i := 0; i < transfersPerBlock; i++ {
for range transfersPerBlock {
b.InvokeWithAssert(gasHash, "transfer", from, acc, 1, nil)
}
script, err := b.Script()
@ -119,7 +119,7 @@ func benchmarkForEachNEP17Transfer(t *testing.B, ps storage.Store, startFromBloc
t.ResetTimer()
t.ReportAllocs()
t.StartTimer()
for i := 0; i < t.N; i++ {
for range t.N {
require.NoError(t, bc.ForEachNEP17Transfer(acc, newestTimestamp, func(t *state.NEP17Transfer) (bool, error) {
if t.Timestamp < oldestTimestamp {
// iterating from newest to oldest, already have reached the needed height
@ -165,7 +165,7 @@ func benchmarkGasPerVote(t *testing.B, ps storage.Store, nRewardRecords int, rew
voters := make([]*wallet.Account, sz)
candidates := make(keys.PublicKeys, sz)
txs := make([]*transaction.Transaction, 0, len(voters)*3)
for i := 0; i < sz; i++ {
for i := range sz {
priv, err := keys.NewPrivateKey()
require.NoError(t, err)
candidates[i] = priv.PublicKey()
@ -186,7 +186,7 @@ func benchmarkGasPerVote(t *testing.B, ps storage.Store, nRewardRecords int, rew
e.CheckHalt(t, tx.Hash())
}
voteTxs := make([]*transaction.Transaction, 0, sz)
for i := 0; i < sz; i++ {
for i := range sz {
priv := voters[i].PrivateKey()
h := priv.GetScriptHash()
voteTx := e.NewTx(t, []neotest.Signer{neotest.NewSingleSigner(voters[i])}, neoHash, "vote", h, candidates[i].Bytes())
@ -211,7 +211,7 @@ func benchmarkGasPerVote(t *testing.B, ps storage.Store, nRewardRecords int, rew
t.ResetTimer()
t.ReportAllocs()
t.StartTimer()
for i := 0; i < t.N; i++ {
for range t.N {
_, err := bc.CalculateClaimable(to, end)
require.NoError(t, err)
}

View file

@ -83,7 +83,7 @@ func NewTrimmedFromReader(stateRootEnabled bool, br *io.BinReader) (*Block, erro
}
if lenHashes > 0 {
block.Transactions = make([]*transaction.Transaction, lenHashes)
for i := 0; i < int(lenHashes); i++ {
for i := range lenHashes {
var hash util.Uint256
hash.DecodeBinary(br)
block.Transactions[i] = transaction.NewTrimmedTX(hash)
@ -124,7 +124,7 @@ func (b *Block) DecodeBinary(br *io.BinReader) {
return
}
txes := make([]*transaction.Transaction, contentsCount)
for i := 0; i < int(contentsCount); i++ {
for i := range txes {
tx := &transaction.Transaction{}
tx.DecodeBinary(br)
txes[i] = tx
@ -140,7 +140,7 @@ func (b *Block) DecodeBinary(br *io.BinReader) {
func (b *Block) EncodeBinary(bw *io.BinWriter) {
b.Header.EncodeBinary(bw)
bw.WriteVarUint(uint64(len(b.Transactions)))
for i := 0; i < len(b.Transactions); i++ {
for i := range b.Transactions {
b.Transactions[i].EncodeBinary(bw)
}
}

View file

@ -73,7 +73,7 @@ func TestTrimmedBlock(t *testing.T) {
assert.Equal(t, block.Script, trimmedBlock.Script)
assert.Equal(t, len(block.Transactions), len(trimmedBlock.Transactions))
for i := 0; i < len(block.Transactions); i++ {
for i := range block.Transactions {
assert.Equal(t, block.Transactions[i].Hash(), trimmedBlock.Transactions[i].Hash())
assert.True(t, trimmedBlock.Transactions[i].Trimmed)
}

View file

@ -1203,7 +1203,7 @@ func (bc *Blockchain) resetTransfers(cache *dao.Simple, height uint32) error {
oldBatchSize = v[0]
newBatchSize byte
)
for i := byte(0); i < v[0]; i++ { // From oldest to newest transfer of the batch.
for range v[0] { // From oldest to newest transfer of the batch.
var t *state.NEP17Transfer
if k[0] == byte(storage.STNEP11Transfers) {
tr := new(state.NEP11Transfer)

View file

@ -89,16 +89,16 @@ func TestRemoveOldTransfers(t *testing.T) {
acc3 := util.Uint160{3}
ttl := state.TokenTransferLog{Raw: []byte{1}} // It's incorrect, but who cares.
for i := uint32(0); i < 3; i++ {
for i := range uint32(3) {
bc.dao.PutTokenTransferLog(acc1, older, i, false, &ttl)
}
for i := uint32(0); i < 3; i++ {
for i := range uint32(3) {
bc.dao.PutTokenTransferLog(acc2, newer, i, false, &ttl)
}
for i := uint32(0); i < 2; i++ {
for i := range uint32(2) {
bc.dao.PutTokenTransferLog(acc3, older, i, true, &ttl)
}
for i := uint32(0); i < 2; i++ {
for i := range uint32(2) {
bc.dao.PutTokenTransferLog(acc3, newer, i, true, &ttl)
}
@ -106,7 +106,7 @@ func TestRemoveOldTransfers(t *testing.T) {
require.NoError(t, err)
_ = bc.removeOldTransfers(0)
for i := uint32(0); i < 2; i++ {
for i := range uint32(2) {
log, err := bc.dao.GetTokenTransferLog(acc1, older, i, false)
require.NoError(t, err)
require.Equal(t, 0, len(log.Raw))
@ -153,7 +153,7 @@ func TestBlockchain_InitWithIncompleteStateJump(t *testing.T) {
bcSpout := newTestChainWithCustomCfg(t, spountCfg)
// Generate some content.
for i := 0; i < len(bcSpout.GetConfig().StandbyCommittee); i++ {
for range bcSpout.GetConfig().StandbyCommittee {
require.NoError(t, bcSpout.AddBlock(bcSpout.newBlock()))
}

View file

@ -299,7 +299,7 @@ func TestBlockchain_InitializeNeoCache_Bug3181(t *testing.T) {
// Put some empty blocks to reach N-1 block height, so that newEpoch cached
// values of native Neo contract require an update on the subsequent cache
// initialization.
for i := 0; i < len(bc.GetConfig().StandbyCommittee)-1-2; i++ {
for range len(bc.GetConfig().StandbyCommittee) - 1 - 2 {
e.AddNewBlock(t)
}
bc.Close() // Ensure persist is done and persistent store is properly closed.
@ -358,12 +358,12 @@ func TestBlockchain_InitializeNeoCache_Bug3424(t *testing.T) {
// voters vote for candidates.
voters := make([]neotest.Signer, committeeSize+1)
candidates := make([]neotest.Signer, committeeSize+1)
for i := 0; i < committeeSize+1; i++ {
for i := range committeeSize + 1 {
voters[i] = e.NewAccount(t, 10_0000_0000)
candidates[i] = e.NewAccount(t, 2000_0000_0000) // enough for one registration
}
txes := make([]*transaction.Transaction, 0, committeeSize*3)
for i := 0; i < committeeSize+1; i++ {
for i := range committeeSize + 1 {
transferTx := neoValidatorsInvoker.PrepareInvoke(t, "transfer", e.Validator.ScriptHash(), voters[i].(neotest.SingleSigner).Account().PrivateKey().GetScriptHash(), int64(committeeSize+1-i)*1000000, nil)
txes = append(txes, transferTx)
registerTx := neoValidatorsInvoker.WithSigners(candidates[i]).PrepareInvoke(t, "registerCandidate", candidates[i].(neotest.SingleSigner).Account().PublicKey().Bytes())
@ -458,7 +458,7 @@ func TestBlockchain_InitializeNativeCacheWrtNativeActivations(t *testing.T) {
// Ensure Notary will be properly initialized and accessing Notary cache works
// as expected.
for i := 0; i < notaryEnabledHeight; i++ {
for i := range notaryEnabledHeight {
require.NotPanics(t, func() {
e.AddNewBlock(t)
}, h+uint32(i)+1)
@ -641,7 +641,7 @@ func TestBlockchain_GetBlock(t *testing.T) {
blocks := e.GenerateNewBlocks(t, 10)
neoValidatorInvoker := e.ValidatorInvoker(e.NativeHash(t, nativenames.Neo))
for i := 0; i < len(blocks); i++ {
for i := range blocks {
block, err := bc.GetBlock(blocks[i].Hash())
require.NoErrorf(t, err, "can't get block %d: %s", i, err)
assert.Equal(t, blocks[i].Index, block.Index)
@ -881,7 +881,7 @@ func TestBlockchain_HasBlock(t *testing.T) {
blocks := e.GenerateNewBlocks(t, 10)
for i := 0; i < len(blocks); i++ {
for i := range blocks {
assert.True(t, bc.HasBlock(blocks[i].Hash()))
}
newBlock := e.NewUnsignedBlock(t)
@ -1008,7 +1008,7 @@ func TestBlockchain_Subscriptions(t *testing.T) {
// 3 burn events for every tx and 1 mint for primary node
require.True(t, len(notificationCh) >= 4)
for i := 0; i < 4; i++ {
for range 4 {
notif := <-notificationCh
require.Equal(t, nativeGASHash, notif.ScriptHash)
}
@ -2327,7 +2327,7 @@ func TestBlockchain_ResetStateErrors(t *testing.T) {
bc, validators, committee := chain.NewMultiWithCustomConfigAndStore(t, cfg, db, false)
e := neotest.NewExecutor(t, bc, validators, committee)
go bc.Run()
for i := 0; i < chainHeight; i++ {
for range chainHeight {
e.AddNewBlock(t) // get some height
}
bc.Close()

View file

@ -388,7 +388,7 @@ func BenchmarkStoreAsTransaction(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for n := 0; n < b.N; n++ {
for range b.N {
err := dao.StoreAsTransaction(tx, 1, aer)
if err != nil {
b.FailNow()

View file

@ -13,7 +13,7 @@ func BenchmarkOpcode1(t *testing.B) {
// Just so that we don't always test the same opcode.
script := []opcode.Opcode{opcode.NOP, opcode.ADD, opcode.SYSCALL, opcode.APPEND}
l := len(script)
for n := 0; n < t.N; n++ {
for n := range t.N {
_ = Opcode(feeFactor, script[n%l])
}
}

View file

@ -117,7 +117,7 @@ func (bc *Blockchain) genBlocks(n int) ([]*block.Block, error) {
blocks := make([]*block.Block, n)
lastHash := bc.topBlock.Load().(*block.Block).Hash()
lastIndex := bc.topBlock.Load().(*block.Block).Index
for i := 0; i < n; i++ {
for i := range n {
blocks[i] = newBlock(bc.config.ProtocolConfiguration, uint32(i)+lastIndex+1, lastHash)
if err := bc.AddBlock(blocks[i]); err != nil {
return blocks, err

View file

@ -363,11 +363,10 @@ func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0
index, _ := slices.BinarySearchFunc(c.methods, *md, func(e, t MethodAndPrice) int {
res := cmp.Compare(e.MD.Name, t.MD.Name)
if res != 0 {
return res
}
return cmp.Compare(len(e.MD.Parameters), len(t.MD.Parameters))
return cmp.Or(
cmp.Compare(e.MD.Name, t.MD.Name),
cmp.Compare(len(e.MD.Parameters), len(t.MD.Parameters)),
)
})
c.methods = slices.Insert(c.methods, index, *md)

View file

@ -192,7 +192,7 @@ func TestSystemContractCall_Permissions(t *testing.T) {
e.DeployContract(t, ctrA, nil)
var hashAStr string
for i := 0; i < util.Uint160Size; i++ {
for i := range util.Uint160Size {
hashAStr += fmt.Sprintf("%#x", ctrA.Hash[i])
if i != util.Uint160Size-1 {
hashAStr += ", "
@ -367,7 +367,7 @@ func TestSnapshotIsolation_Exceptions(t *testing.T) {
e.DeployContract(t, ctrA, nil)
var hashAStr string
for i := 0; i < util.Uint160Size; i++ {
for i := range util.Uint160Size {
hashAStr += fmt.Sprintf("%#x", ctrA.Hash[i])
if i != util.Uint160Size-1 {
hashAStr += ", "
@ -599,7 +599,7 @@ func TestRET_after_FINALLY_PanicInsideVoidMethod(t *testing.T) {
e.DeployContract(t, ctrA, nil)
var hashAStr string
for i := 0; i < util.Uint160Size; i++ {
for i := range util.Uint160Size {
hashAStr += fmt.Sprintf("%#x", ctrA.Hash[i])
if i != util.Uint160Size-1 {
hashAStr += ", "
@ -659,7 +659,7 @@ func TestRET_after_FINALLY_CallNonVoidAfterVoidMethod(t *testing.T) {
e.DeployContract(t, ctrA, nil)
var hashAStr string
for i := 0; i < util.Uint160Size; i++ {
for i := range util.Uint160Size {
hashAStr += fmt.Sprintf("%#x", ctrA.Hash[i])
if i != util.Uint160Size-1 {
hashAStr += ", "

View file

@ -32,7 +32,7 @@ func ECDSASecp256r1CheckMultisig(ic *interop.Context) error {
if len(pkeys) < len(sigs) {
return errors.New("more signatures than there are keys")
}
sigok := vm.CheckMultisigPar(ic.VM, elliptic.P256(), hash.NetSha256(ic.Network, ic.Container).BytesBE(), pkeys, sigs)
sigok := vm.CheckMultisigPar(elliptic.P256(), hash.NetSha256(ic.Network, ic.Container).BytesBE(), pkeys, sigs)
ic.VM.Estack().PushItem(stackitem.Bool(sigok))
return nil
}

View file

@ -3,7 +3,6 @@ package runtime
import (
"encoding/json"
"math/big"
"math/rand"
"testing"
"github.com/nspcc-dev/neo-go/internal/random"
@ -46,10 +45,10 @@ func TestPlatform(t *testing.T) {
func TestGetTime(t *testing.T) {
b := block.New(false)
b.Timestamp = rand.Uint64()
b.Timestamp = 1725021259
ic := &interop.Context{VM: vm.New(), Block: b}
require.NoError(t, GetTime(ic))
checkStack(t, ic.VM, new(big.Int).SetUint64(b.Timestamp))
checkStack(t, ic.VM, new(big.Int).SetUint64(1725021259))
}
func TestGetScriptHash(t *testing.T) {

View file

@ -84,7 +84,7 @@ func TestRuntimeGetNotifications(t *testing.T) {
require.Error(t, GetNotifications(ic))
})
t.Run("too many notifications", func(t *testing.T) {
for i := 0; i <= vm.MaxStackSize; i++ {
for range vm.MaxStackSize + 1 {
ic.Notifications = append(ic.Notifications, state.NotificationEvent{
ScriptHash: util.Uint160{3},
Name: "Event3",

View file

@ -20,7 +20,7 @@ func BenchmarkStorageFind(b *testing.B) {
require.NoError(b, native.PutContractState(context.DAO, contractState))
items := make(map[string]state.StorageItem)
for i := 0; i < count; i++ {
for range count {
items["abc"+random.String(10)] = random.Bytes(10)
}
for k, v := range items {
@ -33,7 +33,7 @@ func BenchmarkStorageFind(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
b.StopTimer()
v.Estack().PushVal(istorage.FindDefault)
v.Estack().PushVal("abc")
@ -64,7 +64,7 @@ func BenchmarkStorageFindIteratorNext(b *testing.B) {
require.NoError(b, native.PutContractState(context.DAO, contractState))
items := make(map[string]state.StorageItem)
for i := 0; i < count; i++ {
for range count {
items["abc"+random.String(10)] = random.Bytes(10)
}
for k, v := range items {
@ -76,7 +76,7 @@ func BenchmarkStorageFindIteratorNext(b *testing.B) {
require.NotEqual(b, 0, changes)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
b.StopTimer()
v.Estack().PushVal(istorage.FindDefault)
v.Estack().PushVal("abc")
@ -88,7 +88,7 @@ func BenchmarkStorageFindIteratorNext(b *testing.B) {
b.FailNow()
}
res := context.VM.Estack().Pop().Item()
for i := 0; i < last; i++ {
for range last {
context.VM.Estack().PushVal(res)
b.StartTimer()
require.NoError(b, iterator.Next(context))

View file

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"slices"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
@ -61,7 +62,7 @@ func (s *Iterator) Value() stackitem.Item {
}
key := s.curr.Key
if s.opts&FindRemovePrefix == 0 {
key = append(bytes.Clone(s.prefix), key...)
key = slices.Concat(s.prefix, key)
}
if s.opts&FindKeysOnly != 0 {
return stackitem.NewByteArray(key)

View file

@ -49,7 +49,7 @@ func BenchmarkPool(b *testing.B) {
b.Run(name, func(b *testing.B) {
p := New(poolSize, 0, false, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
for j := range txes {
if p.Add(txes[j], fe) != nil {
b.Fail()

View file

@ -120,7 +120,7 @@ func TestOverCapacity(t *testing.T) {
require.True(t, slices.IsSortedFunc(mp.verifiedTxes, func(a, b item) int { return -a.Compare(b) }))
}
for i := 0; i < mempoolSize; i++ {
for i := range mempoolSize {
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
tx.Nonce = uint32(i)
tx.Signers = []transaction.Signer{{Account: acc}}
@ -135,7 +135,7 @@ func TestOverCapacity(t *testing.T) {
bigScript[0] = byte(opcode.PUSH1)
bigScript[1] = byte(opcode.RET)
// Fees are also prioritized.
for i := 0; i < mempoolSize; i++ {
for range mempoolSize {
tx := transaction.New(bigScript, 0)
tx.NetworkFee = 10000
tx.Nonce = txcnt
@ -176,7 +176,7 @@ func TestOverCapacity(t *testing.T) {
require.Equal(t, *uint256.NewInt(9*10000 + 7000), mp.fees[acc].feeSum)
// High priority always wins over low priority.
for i := 0; i < mempoolSize; i++ {
for range mempoolSize {
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
tx.NetworkFee = 8000
tx.Nonce = txcnt
@ -203,7 +203,7 @@ func TestGetVerified(t *testing.T) {
mp := New(mempoolSize, 0, false, nil)
txes := make([]*transaction.Transaction, 0, mempoolSize)
for i := 0; i < mempoolSize; i++ {
for i := range mempoolSize {
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
tx.Nonce = uint32(i)
tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}
@ -228,7 +228,7 @@ func TestRemoveStale(t *testing.T) {
txes1 := make([]*transaction.Transaction, 0, mempoolSize/2)
txes2 := make([]*transaction.Transaction, 0, mempoolSize/2)
for i := 0; i < mempoolSize; i++ {
for i := range mempoolSize {
tx := transaction.New([]byte{byte(opcode.PUSH1)}, 0)
tx.Nonce = uint32(i)
tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}

View file

@ -10,7 +10,7 @@ func benchmarkBytes(b *testing.B, n Node) {
inv := n.(interface{ invalidateCache() })
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
inv.invalidateCache()
_ = n.Bytes()
}

View file

@ -318,7 +318,7 @@ func (b *Billet) tryCollapseExtension(curr *ExtensionNode) Node {
func (b *Billet) tryCollapseBranch(curr *BranchNode) Node {
canCollapse := true
for i := 0; i < childrenCount; i++ {
for i := range childrenCount {
if curr.Children[i].Type() == EmptyT {
continue
}

View file

@ -26,7 +26,7 @@ var _ Node = (*BranchNode)(nil)
// NewBranchNode returns a new branch node.
func NewBranchNode() *BranchNode {
b := new(BranchNode)
for i := 0; i < childrenCount; i++ {
for i := range childrenCount {
b.Children[i] = EmptyNode{}
}
return b
@ -58,14 +58,14 @@ func (b *BranchNode) Size() int {
// EncodeBinary implements io.Serializable.
func (b *BranchNode) EncodeBinary(w *io.BinWriter) {
for i := 0; i < childrenCount; i++ {
for i := range childrenCount {
encodeBinaryAsChild(b.Children[i], w)
}
}
// DecodeBinary implements io.Serializable.
func (b *BranchNode) DecodeBinary(r *io.BinReader) {
for i := 0; i < childrenCount; i++ {
for i := range childrenCount {
no := new(NodeObject)
no.DecodeBinary(r)
b.Children[i] = no.Node

View file

@ -1,6 +1,10 @@
package mpt
import "github.com/nspcc-dev/neo-go/pkg/util"
import (
"slices"
"github.com/nspcc-dev/neo-go/pkg/util"
)
// lcp returns the longest common prefix of a and b.
// Note: it does no allocations.
@ -47,7 +51,7 @@ func toNibbles(path []byte) []byte {
// ignoring the first byte (prefix).
func strToNibbles(path string) []byte {
result := make([]byte, (len(path)-1)*2)
for i := 0; i < len(path)-1; i++ {
for i := range len(path) - 1 {
result[i*2] = path[i+1] >> 4
result[i*2+1] = path[i+1] & 0x0F
}
@ -85,9 +89,7 @@ func GetChildrenPaths(path []byte, node Node) map[util.Uint256][][]byte {
}
case *ExtensionNode:
if n.next.Type() == HashT {
cPath := make([]byte, len(path)+len(n.key))
copy(cPath, path)
copy(cPath[len(path):], n.key)
cPath := slices.Concat(path, n.key)
res[n.next.Hash()] = [][]byte{cPath}
}
default:

View file

@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"slices"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/io"
@ -616,7 +617,7 @@ func (t *Trie) Find(prefix, from []byte, maxNum int) ([]storage.KeyValue, error)
if leaf, ok := node.(*LeafNode); ok {
if from == nil || !bytes.Equal(pathToNode, from) { // (*Billet).traverse includes `from` path into result if so. Need to filter out manually.
res = append(res, storage.KeyValue{
Key: append(bytes.Clone(prefix), pathToNode...),
Key: slices.Concat(prefix, pathToNode),
Value: bytes.Clone(leaf.value),
})
count++

View file

@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"slices"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -98,7 +99,7 @@ func (m *TrieStore) Seek(rng storage.SeekRange, f func(k, v []byte) bool) {
if leaf, ok := node.(*LeafNode); ok {
// (*Billet).traverse includes `from` path into the result if so. It's OK for Seek, so shouldn't be filtered out.
kv := storage.KeyValue{
Key: append(bytes.Clone(rng.Prefix), pathToNode...), // Do not cut prefix.
Key: slices.Concat(rng.Prefix, pathToNode), // Do not cut prefix.
Value: bytes.Clone(leaf.value),
}
return !f(kv.Key, kv.Value) // Should return whether to stop.

View file

@ -50,7 +50,7 @@ func TestTrieStore_TestTrieOperations(t *testing.T) {
return true
})
require.Equal(t, 4, len(res))
for i := 0; i < len(res); i++ {
for i := range res {
require.Equal(t, byte(storage.STStorage), res[i][0])
if i < len(res)-1 {
cmp := bytes.Compare(res[i], res[i+1])

View file

@ -27,7 +27,7 @@ func TestNamesASCII(t *testing.T) {
func isASCII(s string) bool {
ok := true
for i := 0; i < len(s); i++ {
for i := range s {
ok = ok && s[i] <= unicode.MaxASCII
}
return ok

View file

@ -442,7 +442,7 @@ func (n *NEO) OnPersist(ic *interop.Context) error {
// during the last epoch block handling or by initialization code).
var oldCommittee, newCommittee stackitem.Item
for i := 0; i < len(cache.committee); i++ {
for i := range cache.committee {
if cache.newEpochCommittee[i].Key != cache.committee[i].Key ||
(i == 0 && len(cache.newEpochCommittee) != len(cache.committee)) {
oldCommittee, newCommittee = cache.committee.toNotificationItem(), cache.newEpochCommittee.toNotificationItem()

View file

@ -238,13 +238,13 @@ func TestLedger_GetTransactionSignersInteropAPI(t *testing.T) {
txHash = tx.Hash().BytesBE()
acc = c.Committee.ScriptHash().BytesBE()
)
for i := 0; i < util.Uint256Size; i++ {
for i := range util.Uint256Size {
hashStr += fmt.Sprintf("%#x", txHash[i])
if i != util.Uint256Size-1 {
hashStr += ", "
}
}
for i := 0; i < util.Uint160Size; i++ {
for i := range util.Uint160Size {
accStr += fmt.Sprintf("%#x", acc[i])
if i != util.Uint160Size-1 {
accStr += ", "

View file

@ -231,7 +231,7 @@ func TestManagement_NativeUpdate(t *testing.T) {
})
// Add some blocks up to the Cockatrice enabling height and check the default natives state.
for i := 0; i < cockatriceHeight-1; i++ {
for range cockatriceHeight - 1 {
c.AddNewBlock(t)
for _, name := range nativenames.All {
h := state.CreateNativeContractHash(name)
@ -275,7 +275,7 @@ func TestManagement_NativeUpdate_Call(t *testing.T) {
})
// Invoke Cockatrice-dependant method before Cockatrice should fail.
for i := 0; i < cockatriceHeight-1; i++ {
for range cockatriceHeight - 1 {
c.InvokeFail(t, "at instruction 45 (SYSCALL): System.Contract.Call failed: method not found: getCommitteeAddress/0", method)
}

View file

@ -131,12 +131,12 @@ func TestNEO_CommitteeEvents(t *testing.T) {
voters := make([]neotest.Signer, committeeSize)
candidates := make([]neotest.Signer, committeeSize)
for i := 0; i < committeeSize; i++ {
for i := range committeeSize {
voters[i] = e.NewAccount(t, 10_0000_0000)
candidates[i] = e.NewAccount(t, 2000_0000_0000) // enough for one registration
}
txes := make([]*transaction.Transaction, 0, committeeSize*3)
for i := 0; i < committeeSize; i++ {
for i := range committeeSize {
transferTx := neoValidatorsInvoker.PrepareInvoke(t, "transfer", e.Validator.ScriptHash(), voters[i].(neotest.SingleSigner).Account().PrivateKey().GetScriptHash(), int64(committeeSize-i)*1000000, nil)
txes = append(txes, transferTx)
@ -196,7 +196,7 @@ func TestNEO_Vote(t *testing.T) {
validatorsCount := cfg.GetNumOfCNs(0)
freq := validatorsCount + committeeSize
advanceChain := func(t *testing.T) {
for i := 0; i < freq; i++ {
for range freq {
neoCommitteeInvoker.AddNewBlock(t)
}
}
@ -217,13 +217,13 @@ func TestNEO_Vote(t *testing.T) {
// how much GAS voters receive for NEO ownership.
referenceAccounts := make([]neotest.Signer, committeeSize+1)
candidates := make([]neotest.Signer, committeeSize+1)
for i := 0; i < committeeSize+1; i++ {
for i := range committeeSize + 1 {
voters[i] = e.NewAccount(t, 10_0000_0000)
referenceAccounts[i] = e.NewAccount(t, 10_0000_0000)
candidates[i] = e.NewAccount(t, 2000_0000_0000) // enough for one registration
}
txes := make([]*transaction.Transaction, 0, committeeSize*4-2)
for i := 0; i < committeeSize+1; i++ {
for i := range committeeSize + 1 {
transferTx := neoValidatorsInvoker.PrepareInvoke(t, "transfer", e.Validator.ScriptHash(), voters[i].(neotest.SingleSigner).Account().PrivateKey().GetScriptHash(), int64(committeeSize+1-i)*1000000, nil)
txes = append(txes, transferTx)
transferTx = neoValidatorsInvoker.PrepareInvoke(t, "transfer", e.Validator.ScriptHash(), referenceAccounts[i].(neotest.SingleSigner).Account().PrivateKey().GetScriptHash(), int64(committeeSize+1-i)*1000000, nil)
@ -419,7 +419,7 @@ func TestNEO_GetAccountState(t *testing.T) {
committeeSize := cfg.GetCommitteeSize(0)
validatorSize := cfg.GetNumOfCNs(0)
advanceChain := func(t *testing.T) {
for i := 0; i < committeeSize; i++ {
for range committeeSize {
neoValidatorInvoker.AddNewBlock(t)
}
}
@ -485,7 +485,7 @@ func TestNEO_GetAccountStateInteropAPI(t *testing.T) {
committeeSize := cfg.GetCommitteeSize(0)
validatorSize := cfg.GetNumOfCNs(0)
advanceChain := func(t *testing.T) {
for i := 0; i < committeeSize; i++ {
for range committeeSize {
neoValidatorInvoker.AddNewBlock(t)
}
}
@ -500,7 +500,7 @@ func TestNEO_GetAccountStateInteropAPI(t *testing.T) {
neoValidatorInvoker.WithSigners(acc).Invoke(t, true, "transfer", acc.ScriptHash(), acc.ScriptHash(), amount, nil)
var hashAStr string
for i := 0; i < util.Uint160Size; i++ {
for i := range util.Uint160Size {
hashAStr += fmt.Sprintf("%#x", acc.ScriptHash()[i])
if i != util.Uint160Size-1 {
hashAStr += ", "
@ -544,11 +544,11 @@ func TestNEO_CommitteeBountyOnPersist(t *testing.T) {
const singleBounty = 50000000
bs := map[int]int64{0: singleBounty}
checkBalances := func() {
for i := 0; i < committeeSize; i++ {
for i := range committeeSize {
require.EqualValues(t, bs[i], e.Chain.GetUtilityTokenBalance(hs[i].GetScriptHash()).Int64(), i)
}
}
for i := 0; i < committeeSize*2; i++ {
for i := range committeeSize * 2 {
e.AddNewBlock(t)
bs[(i+1)%committeeSize] += singleBounty
checkBalances()
@ -731,7 +731,7 @@ func TestNEO_CalculateBonus(t *testing.T) {
t.Run("Zero", func(t *testing.T) {
initialGASBalance := e.Chain.GetUtilityTokenBalance(accH)
for i := 0; i < rewardDistance; i++ {
for range rewardDistance {
e.AddNewBlock(t)
}
// Claim GAS, but there's no NEO on the account, so no GAS should be earned.
@ -750,13 +750,13 @@ func TestNEO_CalculateBonus(t *testing.T) {
// Five blocks of NEO owning with default GasPerBlockValue.
neoValidatorsInvoker.Invoke(t, true, "transfer", e.Validator.ScriptHash(), accH, amount, nil)
for i := 0; i < rewardDistance/2-2; i++ {
for range rewardDistance/2 - 2 {
e.AddNewBlock(t)
}
neoCommitteeInvoker.Invoke(t, stackitem.Null{}, "setGasPerBlock", newGASPerBlock*native.GASFactor)
// Five blocks more with modified GasPerBlock value.
for i := 0; i < rewardDistance/2; i++ {
for range rewardDistance / 2 {
e.AddNewBlock(t)
}
@ -783,12 +783,12 @@ func TestNEO_GetCandidates(t *testing.T) {
// Register a set of candidates and vote for them.
voters := make([]neotest.Signer, candidatesCount)
candidates := make([]neotest.Signer, candidatesCount)
for i := 0; i < candidatesCount; i++ {
for i := range candidatesCount {
voters[i] = e.NewAccount(t, 10_0000_0000)
candidates[i] = e.NewAccount(t, 2000_0000_0000) // enough for one registration
}
txes := make([]*transaction.Transaction, 0, candidatesCount*3)
for i := 0; i < candidatesCount; i++ {
for i := range candidatesCount {
transferTx := neoValidatorsInvoker.PrepareInvoke(t, "transfer", e.Validator.ScriptHash(), voters[i].(neotest.SingleSigner).Account().PrivateKey().GetScriptHash(), int64(candidatesCount+1-i)*1000000, nil)
txes = append(txes, transferTx)
registerTx := neoValidatorsInvoker.WithSigners(candidates[i]).PrepareInvoke(t, "registerCandidate", candidates[i].(neotest.SingleSigner).Account().PublicKey().Bytes())
@ -818,7 +818,7 @@ func TestNEO_GetCandidates(t *testing.T) {
// Check that GetAllCandidates works the same way as GetCandidates.
checkGetAllCandidates := func(t *testing.T, expected []stackitem.Item) {
for i := 0; i < len(expected)+1; i++ {
for i := range len(expected) + 1 {
w := io.NewBufBinWriter()
emit.AppCall(w.BinWriter, neoCommitteeInvoker.Hash, "getAllCandidates", callflag.All)
for j := 0; j < i+1; j++ {

View file

@ -183,7 +183,7 @@ func TestNotary_MaliciousWithdrawal(t *testing.T) {
// Perform several deposits to a set of different accounts.
count := 3
for i := 0; i < count; i++ {
for range count {
h := random.Uint160()
gasCommitteeInvoker.Invoke(t, true, "transfer", multisigHash, notaryHash, 2*feePerKey, &notary.OnNEP17PaymentData{Account: &h, Till: e.Chain.BlockHeight() + 2})
}

View file

@ -2,7 +2,7 @@ package state
import (
"encoding/json"
"math/rand"
"math/rand/v2"
"testing"
"github.com/nspcc-dev/neo-go/internal/random"

View file

@ -85,13 +85,13 @@ func BenchmarkNEP17BalanceBytes(b *testing.B) {
b.Run("stackitem", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
_, _ = stackitem.SerializeConvertible(&bl)
}
})
b.Run("bytes", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
_ = bl.Bytes(nil)
}
})
@ -100,7 +100,7 @@ func BenchmarkNEP17BalanceBytes(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
_ = bl.Bytes(bs[:0])
}
})
@ -114,13 +114,13 @@ func BenchmarkNEP17BalanceFromBytes(b *testing.B) {
b.Run("stackitem", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
_ = stackitem.DeserializeConvertible(buf, new(NEP17Balance))
}
})
b.Run("from bytes", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
_, _ = NEP17BalanceFromBytes(buf)
}
})

View file

@ -111,7 +111,7 @@ func (aer *AppExecResult) DecodeBinary(r *io.BinReader) {
return
}
arr := make([]stackitem.Item, sz)
for i := 0; i < int(sz); i++ {
for i := range arr {
arr[i] = stackitem.DecodeBinaryProtected(r)
if r.Err != nil {
return

View file

@ -33,7 +33,7 @@ func BenchmarkAppExecResult_EncodeBinary(b *testing.B) {
w := io.NewBufBinWriter()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
w.Reset()
aer.EncodeBinary(w.BinWriter)
}

View file

@ -82,7 +82,7 @@ func (bs *TokenTransferInfo) DecodeBinary(r *io.BinReader) {
bs.NewNEP17Batch = r.ReadBool()
lenBalances := r.ReadVarUint()
m := make(map[int32]uint32, lenBalances)
for i := 0; i < int(lenBalances); i++ {
for range lenBalances {
key := int32(r.ReadU32LE())
m[key] = r.ReadU32LE()
}
@ -142,7 +142,7 @@ func (lg *TokenTransferLog) ForEachNEP11(f func(*NEP11Transfer) (bool, error)) (
}
transfers := make([]NEP11Transfer, lg.Size())
r := io.NewBinReaderFromBuf(lg.Raw[1:])
for i := 0; i < lg.Size(); i++ {
for i := range transfers {
transfers[i].DecodeBinary(r)
}
if r.Err != nil {
@ -164,7 +164,7 @@ func (lg *TokenTransferLog) ForEachNEP17(f func(*NEP17Transfer) (bool, error)) (
}
transfers := make([]NEP17Transfer, lg.Size())
r := io.NewBinReaderFromBuf(lg.Raw[1:])
for i := 0; i < lg.Size(); i++ {
for i := range transfers {
transfers[i].DecodeBinary(r)
}
if r.Err != nil {

View file

@ -2,9 +2,8 @@ package state
import (
"math/big"
"math/rand"
"math/rand/v2"
"testing"
"time"
"github.com/nspcc-dev/neo-go/internal/random"
"github.com/nspcc-dev/neo-go/internal/testserdes"
@ -13,7 +12,7 @@ import (
)
func TestTokenTransferLog_Append17(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
r := rand.New(rand.NewPCG(42, 100500))
expected := []*NEP17Transfer{
random17Transfer(r),
random17Transfer(r),
@ -39,7 +38,7 @@ func TestTokenTransferLog_Append17(t *testing.T) {
}
func TestTokenTransferLog_Append(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
r := rand.New(rand.NewPCG(42, 100500))
expected := []*NEP11Transfer{
random11Transfer(r),
random11Transfer(r),
@ -65,7 +64,7 @@ func TestTokenTransferLog_Append(t *testing.T) {
}
func BenchmarkTokenTransferLog_Append(b *testing.B) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
r := rand.New(rand.NewPCG(42, 100500))
ts := make([]*NEP17Transfer, TokenTransferBatchSize)
for i := range ts {
ts[i] = random17Transfer(r)
@ -74,7 +73,7 @@ func BenchmarkTokenTransferLog_Append(b *testing.B) {
lg := new(TokenTransferLog)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
for _, tr := range ts {
err := lg.Append(tr)
if err != nil {

View file

@ -82,7 +82,7 @@ func TestPool_AddRemoveUpdate(t *testing.T) {
func TestPool_GetBatch(t *testing.T) {
check := func(t *testing.T, limit int, itemsCount int) {
mp := NewPool()
for i := 0; i < itemsCount; i++ {
for range itemsCount {
mp.Add(random.Uint256(), []byte{0x01})
}
batch := mp.GetBatch(limit)

View file

@ -28,7 +28,7 @@ func TestStateSyncModule_Init(t *testing.T) {
}
bcSpout, validators, committee := chain.NewMultiWithCustomConfig(t, spoutCfg)
e := neotest.NewExecutor(t, bcSpout, validators, committee)
for i := 0; i <= 2*stateSyncInterval+int(maxTraceable)+1; i++ {
for range 2*stateSyncInterval + int(maxTraceable) + 2 {
e.AddNewBlock(t)
}

View file

@ -229,7 +229,7 @@ func benchmarkCachedSeek(t *testing.B, ps Store, psElementsCount, tsElementsCoun
ts = NewMemCachedStore(ps)
)
for i := 0; i < psElementsCount; i++ {
for i := range psElementsCount {
// lower KVs with matching prefix that should be found
ts.Put(append(lowerPrefixGood, random.Bytes(10)...), []byte("value"))
// lower KVs with non-matching prefix that shouldn't be found
@ -266,7 +266,7 @@ func benchmarkCachedSeek(t *testing.B, ps Store, psElementsCount, tsElementsCoun
t.ReportAllocs()
t.ResetTimer()
for n := 0; n < t.N; n++ {
for range t.N {
ts.Seek(SeekRange{Prefix: searchPrefix}, func(k, v []byte) bool { return true })
}
t.StopTimer()

View file

@ -21,7 +21,7 @@ func BenchmarkMemorySeek(t *testing.B) {
badPrefix = []byte{2}
)
ts := NewMemCachedStore(ms)
for i := 0; i < count; i++ {
for range count {
ts.Put(append(searchPrefix, random.Bytes(10)...), random.Bytes(10))
ts.Put(append(badPrefix, random.Bytes(10)...), random.Bytes(10))
}
@ -30,7 +30,7 @@ func BenchmarkMemorySeek(t *testing.B) {
t.ReportAllocs()
t.ResetTimer()
for n := 0; n < t.N; n++ {
for range t.N {
ms.Seek(SeekRange{Prefix: searchPrefix}, func(k, v []byte) bool { return false })
}
})

View file

@ -3,6 +3,7 @@ package storage
import (
"errors"
"fmt"
"slices"
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
@ -105,10 +106,8 @@ type (
func seekRangeToPrefixes(sr SeekRange) *util.Range {
var (
rang *util.Range
start = make([]byte, len(sr.Prefix)+len(sr.Start))
start = slices.Concat(sr.Prefix, sr.Start)
)
copy(start, sr.Prefix)
copy(start[len(sr.Prefix):], sr.Start)
if !sr.Backwards {
rang = util.BytesPrefix(sr.Prefix)

View file

@ -32,7 +32,7 @@ func init() {
}
func BenchmarkDecodeBinary(t *testing.B) {
for n := 0; n < t.N; n++ {
for range t.N {
r := io.NewBinReaderFromBuf(benchTx)
tx := &Transaction{}
tx.DecodeBinary(r)
@ -41,14 +41,14 @@ func BenchmarkDecodeBinary(t *testing.B) {
}
func BenchmarkDecodeJSON(t *testing.B) {
for n := 0; n < t.N; n++ {
for range t.N {
tx := &Transaction{}
require.NoError(t, tx.UnmarshalJSON(benchTxJSON))
}
}
func BenchmarkDecodeFromBytes(t *testing.B) {
for n := 0; n < t.N; n++ {
for range t.N {
_, err := NewTransactionFromBytes(benchTx)
require.NoError(t, err)
}
@ -60,7 +60,7 @@ func BenchmarkTransaction_Bytes(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range b.N {
_ = tx.Bytes()
}
}
@ -71,7 +71,7 @@ func BenchmarkGetVarSize(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for range b.N {
_ = io.GetVarSize(tx)
}
}

View file

@ -2,7 +2,7 @@ package transaction
import (
"encoding/json"
"math/rand"
"math/rand/v2"
"testing"
"github.com/nspcc-dev/neo-go/internal/testserdes"

View file

@ -8,7 +8,7 @@ import (
"fmt"
"math"
"math/big"
"math/rand"
"math/rand/v2"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
@ -160,7 +160,7 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader, buf []byte) {
return
}
t.Signers = make([]Signer, nsigners)
for i := 0; i < int(nsigners); i++ {
for i := range t.Signers {
t.Signers[i].DecodeBinary(br)
}
nattrs := br.ReadVarUint()
@ -169,7 +169,7 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader, buf []byte) {
return
}
t.Attributes = make([]Attribute, nattrs)
for i := 0; i < int(nattrs); i++ {
for i := range t.Attributes {
t.Attributes[i].DecodeBinary(br)
}
t.Script = br.ReadVarBytes(MaxScriptLength)
@ -197,7 +197,7 @@ func (t *Transaction) decodeBinaryNoSize(br *io.BinReader, buf []byte) {
return
}
t.Scripts = make([]Witness, nscripts)
for i := 0; i < int(nscripts); i++ {
for i := range t.Scripts {
t.Scripts[i].DecodeBinary(br)
}
@ -422,7 +422,7 @@ func (t *Transaction) isValid() error {
if len(t.Signers) == 0 {
return ErrEmptySigners
}
for i := 0; i < len(t.Signers); i++ {
for i := range t.Signers {
for j := i + 1; j < len(t.Signers); j++ {
if t.Signers[i].Account.Equals(t.Signers[j].Account) {
return ErrNonUniqueSigners

View file

@ -318,7 +318,7 @@ func BenchmarkTxHash(b *testing.B) {
// Prime cache.
tx.Hash()
for i := 0; i < b.N; i++ {
for range b.N {
_ = tx.Hash()
}
}

View file

@ -233,7 +233,7 @@ func readArrayOfConditions(r *io.BinReader, maxDepth int) []WitnessCondition {
return nil
}
a := make([]WitnessCondition, l)
for i := 0; i < int(l); i++ {
for i := range a {
a[i] = decodeBinaryCondition(r, maxDepth-1)
}
if r.Err != nil {
@ -253,7 +253,7 @@ func (c *ConditionAnd) DecodeBinarySpecific(r *io.BinReader, maxDepth int) {
func arrayToJSON(c WitnessCondition, a []WitnessCondition) ([]byte, error) {
exprs := make([]json.RawMessage, len(a))
for i := 0; i < len(a); i++ {
for i := range a {
b, err := a[i].MarshalJSON()
if err != nil {
return nil, err

View file

@ -74,7 +74,7 @@ func TestWitnessConditionSerDes(t *testing.T) {
}
var maxSubCondAnd = &ConditionAnd{}
var maxSubCondOr = &ConditionAnd{}
for i := 0; i < maxSubitems+1; i++ {
for range maxSubitems + 1 {
*maxSubCondAnd = append(*maxSubCondAnd, (*ConditionBoolean)(&someBool))
*maxSubCondOr = append(*maxSubCondOr, (*ConditionBoolean)(&someBool))
}

View file

@ -1,37 +1,32 @@
package hash
package hash_test
import (
"math/rand"
"testing"
"time"
"github.com/nspcc-dev/neo-go/internal/random"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require"
)
func BenchmarkMerkle(t *testing.B) {
var err error
var hashes = make([]util.Uint256, 100000)
var h = make([]byte, 32)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := range hashes {
r.Read(h)
hashes[i], err = util.Uint256DecodeBytesBE(h)
require.NoError(t, err)
hashes[i] = random.Uint256()
}
t.Run("NewMerkleTree", func(t *testing.B) {
t.ResetTimer()
for n := 0; n < t.N; n++ {
tr, err := NewMerkleTree(hashes)
for range t.N {
tr, err := hash.NewMerkleTree(hashes)
require.NoError(t, err)
_ = tr.Root()
}
})
t.Run("CalcMerkleRoot", func(t *testing.B) {
t.ResetTimer()
for n := 0; n < t.N; n++ {
_ = CalcMerkleRoot(hashes)
for range t.N {
_ = hash.CalcMerkleRoot(hashes)
}
})
}

View file

@ -19,7 +19,7 @@ func NewMerkleTree(hashes []util.Uint256) (*MerkleTree, error) {
}
nodes := make([]*MerkleTreeNode, len(hashes))
for i := 0; i < len(hashes); i++ {
for i := range hashes {
nodes[i] = &MerkleTreeNode{
hash: hashes[i],
}
@ -45,7 +45,7 @@ func buildMerkleTree(leaves []*MerkleTreeNode) *MerkleTreeNode {
}
parents := make([]*MerkleTreeNode, (len(leaves)+1)/2)
for i := 0; i < len(parents); i++ {
for i := range parents {
parents[i] = &MerkleTreeNode{}
parents[i].leftChild = leaves[i*2]
leaves[i*2].parent = parents[i]
@ -81,7 +81,7 @@ func CalcMerkleRoot(hashes []util.Uint256) util.Uint256 {
scratch := make([]byte, 64)
parents := hashes[:(len(hashes)+1)/2]
for i := 0; i < len(parents); i++ {
for i := range parents {
copy(scratch, hashes[i*2].BytesBE())
if i*2+1 == len(hashes) {

View file

@ -149,7 +149,7 @@ func xor(a, b []byte) []byte {
panic("cannot XOR non equal length arrays")
}
dst := make([]byte, len(a))
for i := 0; i < len(dst); i++ {
for i := range dst {
dst[i] = a[i] ^ b[i]
}
return dst

View file

@ -26,7 +26,7 @@ func TestEncodeDecodeInfinity(t *testing.T) {
}
func TestEncodeDecodePublicKey(t *testing.T) {
for i := 0; i < 4; i++ {
for range 4 {
k, err := NewPrivateKey()
require.NoError(t, err)
p := k.PublicKey()
@ -225,7 +225,7 @@ func BenchmarkPublicEqual(t *testing.B) {
k12 := getPubKey(t)
k2, err := NewPublicKeyFromString("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c")
require.NoError(t, err)
for n := 0; n < t.N; n++ {
for range t.N {
_ = k11.Equal(k12)
_ = k11.Equal(k2)
}
@ -233,14 +233,14 @@ func BenchmarkPublicEqual(t *testing.B) {
func BenchmarkPublicBytes(t *testing.B) {
k := getPubKey(t)
for n := 0; n < t.N; n++ {
for range t.N {
_ = k.Bytes()
}
}
func BenchmarkPublicUncompressedBytes(t *testing.B) {
k := getPubKey(t)
for n := 0; n < t.N; n++ {
for range t.N {
_ = k.Bytes()
}
}
@ -249,7 +249,7 @@ func BenchmarkPublicDecodeBytes(t *testing.B) {
keyBytes, err := hex.DecodeString("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c")
require.NoError(t, err)
k := new(PublicKey)
for n := 0; n < t.N; n++ {
for range t.N {
require.NoError(t, k.DecodeBytes(keyBytes))
}
}

View file

@ -10,7 +10,7 @@ func BenchmarkToPreallocatedBytes(b *testing.B) {
vn := big.NewInt(-100500)
buf := make([]byte, 4)
for i := 0; i < b.N; i++ {
for range b.N {
_ = ToPreallocatedBytes(v, buf[:0])
_ = ToPreallocatedBytes(vn, buf[:0])
}

View file

@ -41,7 +41,7 @@ func FromBytes(data []byte) *big.Int {
lw := size / wordSizeBytes
ws := make([]big.Word, lw+1)
for i := 0; i < lw; i++ {
for i := range lw {
base := i * wordSizeBytes
for j := base + 7; j >= base; j-- {
ws[i] <<= 8

View file

@ -13,7 +13,7 @@ func FuzzFromBytes(f *testing.F) {
for _, tc := range testCases {
f.Add(tc.buf)
}
for i := 0; i < 50; i++ {
for range 50 {
for j := 1; j < MaxBytesLen; j++ {
b := make([]byte, j)
_, err := rand.Read(b)

View file

@ -17,7 +17,7 @@ var _pow10 []*big.Int
func init() {
var p = int64(1)
for i := 0; i <= maxAllowedPrecision; i++ {
for range maxAllowedPrecision + 1 {
_pow10 = append(_pow10, big.NewInt(p))
p *= 10
}

View file

@ -1,3 +1,3 @@
module github.com/nspcc-dev/neo-go/pkg/interop
go 1.21
go 1.22

View file

@ -128,7 +128,7 @@ func (r *BinReader) ReadArray(t any, maxSize ...int) {
l := int(lu)
arr := reflect.MakeSlice(sliceType, l, l)
for i := 0; i < l; i++ {
for i := range l {
var elem reflect.Value
if isPtr {
elem = reflect.New(elemType.Elem())

View file

@ -78,7 +78,7 @@ func (w *BinWriter) WriteArray(arr any) {
typ := val.Type().Elem()
w.WriteVarUint(uint64(val.Len()))
for i := 0; i < val.Len(); i++ {
for i := range val.Len() {
el, ok := val.Index(i).Interface().(encodable)
if !ok {
el, ok = val.Index(i).Addr().Interface().(encodable)

View file

@ -218,7 +218,7 @@ func TestBufBinWriterErr(t *testing.T) {
func TestBufBinWriterReset(t *testing.T) {
bw := NewBufBinWriter()
for i := 0; i < 3; i++ {
for i := range 3 {
bw.WriteU32LE(uint32(i))
assert.Nil(t, bw.Err)
_ = bw.Bytes()

View file

@ -75,7 +75,7 @@ func GetVarSize(value any) int {
if valueLength != 0 {
switch reflect.ValueOf(value).Index(0).Interface().(type) {
case Serializable:
for i := 0; i < valueLength; i++ {
for i := range valueLength {
valueSize += GetVarSize(v.Index(i).Interface())
}
case uint8, int8:

Some files were not shown because too many files have changed in this diff Show more