Skip to content

Commit

Permalink
Merge pull request #3567 from nspcc-dev/go-1.22
Browse files Browse the repository at this point in the history
Go 1.22
  • Loading branch information
roman-khimov authored Sep 2, 2024
2 parents ff979e7 + 565f8cf commit d47fe39
Show file tree
Hide file tree
Showing 149 changed files with 384 additions and 406 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cli/nep_test/nep17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"
"math/big"
"path/filepath"
"slices"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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()+"\\)")
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 4 additions & 5 deletions cli/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cli/smartcontract/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 + `
Expand Down
2 changes: 1 addition & 1 deletion cli/vm/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cli/wallet/nep17.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cli/wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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*$")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/engine/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/events/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/iterator/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/nft-d/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/nft-nd-nns/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-nd-nns/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-nd/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/oracle/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/runtime/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/storage/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/timer/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/token/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/zkp/cubic_circuit/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/zkp/cubic_circuit/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/zkp/xor_compat/go.mod
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/basicchain/testdata/storage/storage_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/contracts/oracle_contract/go.mod
Original file line number Diff line number Diff line change
@@ -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
16 changes: 5 additions & 11 deletions internal/random/random_util.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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.
Expand All @@ -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())
}
2 changes: 1 addition & 1 deletion internal/testchain/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/testcli/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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+`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/compiler/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit d47fe39

Please sign in to comment.