From 8ee13cc35e7d27639b0c4661eb39cc370af577c7 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 17:58:57 +0300 Subject: [PATCH 1/7] scripts: keep go.mod tidy Signed-off-by: Anna Shaleva --- scripts/go.mod | 18 ++++++++++++++---- scripts/go.sum | 24 ++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/scripts/go.mod b/scripts/go.mod index 4e09e5f95..3645f321b 100644 --- a/scripts/go.mod +++ b/scripts/go.mod @@ -6,7 +6,7 @@ replace github.com/nspcc-dev/neo-go => ../ require ( github.com/davecgh/go-spew v1.1.1 - github.com/nspcc-dev/neo-go v0.0.0-00010101000000-000000000000 + github.com/nspcc-dev/neo-go v0.106.3 github.com/pmezard/go-difflib v1.0.0 github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.27.4 @@ -14,13 +14,15 @@ require ( ) require ( + github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bits-and-blooms/bitset v1.8.0 // indirect + github.com/bits-and-blooms/bitset v1.14.2 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/consensys/bavard v0.1.13 // indirect - github.com/consensys/gnark-crypto v0.13.0 // indirect + github.com/consensys/gnark-crypto v0.14.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.3 // indirect @@ -30,7 +32,11 @@ require ( github.com/mr-tron/base58 v1.2.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nspcc-dev/go-ordered-json v0.0.0-20240830112754-291b000d1f3b // indirect + github.com/nspcc-dev/hrw/v2 v2.0.1 // indirect + github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240305074711-35bc78d84dc4 // indirect + github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.12 // indirect github.com/nspcc-dev/rfc6979 v0.2.3 // indirect + github.com/nspcc-dev/tzhash v1.7.2 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/prometheus/client_golang v1.20.2 // indirect github.com/prometheus/client_model v0.6.1 // indirect @@ -43,12 +49,16 @@ require ( go.etcd.io/bbolt v1.3.11 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect golang.org/x/mod v0.20.0 // indirect + golang.org/x/net v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.23.0 // indirect + golang.org/x/sys v0.24.0 // indirect golang.org/x/term v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect golang.org/x/tools v0.24.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect + google.golang.org/grpc v1.62.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect rsc.io/tmplfunc v0.0.3 // indirect diff --git a/scripts/go.sum b/scripts/go.sum index 4af19abc3..950d3268e 100644 --- a/scripts/go.sum +++ b/scripts/go.sum @@ -2,16 +2,16 @@ github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12 h github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c= -github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/bits-and-blooms/bitset v1.14.2 h1:YXVoyPndbdvcEVcseEovVfp0qjJp7S+i5+xgp/Nfbdc= +github.com/bits-and-blooms/bitset v1.14.2/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= -github.com/consensys/gnark-crypto v0.13.0 h1:VPULb/v6bbYELAPTDFINEVaMTTybV5GLxDdcjnS+4oc= -github.com/consensys/gnark-crypto v0.13.0/go.mod h1:wKqwsieaKPThcFkHe0d0zMsbHEUWFmZcG7KBCse210o= +github.com/consensys/gnark-crypto v0.14.0 h1:DDBdl4HaBtdQsq/wfMwJvZNE80sHidrK3Nfrefatm0E= +github.com/consensys/gnark-crypto v0.14.0/go.mod h1:CU4UijNPsHawiVGNxe9co07FkzCeWHHrb1li/n1XoU0= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -30,6 +30,7 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= @@ -37,6 +38,7 @@ github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= @@ -57,8 +59,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= -github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= +github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzWu4= +github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= @@ -129,8 +131,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= -golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= -golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= +golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -151,8 +153,8 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -176,6 +178,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 949ed4f2ea3af509dd4e6d65a16189ee6e146130 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 17:59:27 +0300 Subject: [PATCH 2/7] workflows: enable linter for example contracts Avoid situations like 9f931233016b1d699ea9ca37228dff1c0917440c. Signed-off-by: Anna Shaleva --- .github/workflows/tests.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 743a08453..aac575036 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,8 +14,21 @@ on: jobs: lint: - name: Lint + name: 'Lint: NeoGo' uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + + lint_examples: + name: 'Lint: examples (${{ matrix.contract }})' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + + strategy: + fail-fast: false + matrix: + contract: [ 'engine', 'events', 'iterator', 'nft-d', 'nft-nd', 'nft-nd-nns', 'oracle', + 'runtime', 'storage', 'timer', 'token', 'zkp/cubic_circuit', 'zkp/xor_compat'] + with: + workdir: examples/${{ matrix.contract }} + gomodcheck: name: Check internal dependencies runs-on: ubuntu-latest From 524ba5fd1bdf0e2fae54e8a010c5efdc80ae3d3b Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 18:17:22 +0300 Subject: [PATCH 3/7] examples: fix linter issues Signed-off-by: Anna Shaleva --- examples/engine/engine.go | 8 ++++---- examples/iterator/iterator.go | 2 +- examples/nft-nd-nns/nns.go | 8 ++++---- examples/nft-nd-nns/nns_test.go | 2 -- examples/nft-nd/nft.go | 2 +- examples/runtime/runtime.go | 4 ++-- examples/storage/storage.go | 4 ++-- examples/timer/timer.go | 10 +++++----- examples/token/nep17/nep17.go | 17 ++++++++--------- examples/token/token.go | 14 +++++++------- examples/zkp/cubic_circuit/main.go | 2 +- examples/zkp/cubic_circuit/main_test.go | 2 +- examples/zkp/xor_compat/verify.go | 6 +++--- 13 files changed, 39 insertions(+), 42 deletions(-) diff --git a/examples/engine/engine.go b/examples/engine/engine.go index f94e29e03..f7178e908 100644 --- a/examples/engine/engine.go +++ b/examples/engine/engine.go @@ -4,25 +4,25 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/runtime" ) -// NotifyScriptContainer sends runtime notification with script container hash +// NotifyScriptContainer sends runtime notification with script container hash. func NotifyScriptContainer() { tx := runtime.GetScriptContainer() runtime.Notify("Tx", tx.Hash) } -// NotifyCallingScriptHash sends runtime notification with calling script hash +// NotifyCallingScriptHash sends runtime notification with calling script hash. func NotifyCallingScriptHash() { callingScriptHash := runtime.GetCallingScriptHash() runtime.Notify("Calling", callingScriptHash) } -// NotifyExecutingScriptHash sends runtime notification about executing script hash +// NotifyExecutingScriptHash sends runtime notification about executing script hash. func NotifyExecutingScriptHash() { execScriptHash := runtime.GetExecutingScriptHash() runtime.Notify("Executing", execScriptHash) } -// NotifyEntryScriptHash sends notification about entry script hash +// NotifyEntryScriptHash sends notification about entry script hash. func NotifyEntryScriptHash() { entryScriptHash := runtime.GetEntryScriptHash() runtime.Notify("Entry", entryScriptHash) diff --git a/examples/iterator/iterator.go b/examples/iterator/iterator.go index f5e91ea37..f18d3ec8f 100644 --- a/examples/iterator/iterator.go +++ b/examples/iterator/iterator.go @@ -7,7 +7,7 @@ import ( ) // _deploy primes contract's storage with some data to be used later. -func _deploy(_ any, _ bool) { +func _deploy(_ any, _ bool) { // nolint: unused ctx := storage.GetContext() // RW context. storage.Put(ctx, "foo1", "1") storage.Put(ctx, "foo2", "2") diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index b1dacb7a5..1f02ebfaf 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -60,7 +60,7 @@ const ( // Other constants. const ( // defaultRegisterPrice is the default price for new domain registration. - defaultRegisterPrice = 10_0000_0000 + defaultRegisterPrice = 10_0000_0000 // nolint: unused // millisecondsInYear is amount of milliseconds per year. millisecondsInYear = 365 * 24 * 3600 * 1000 ) @@ -79,7 +79,7 @@ func Update(nef []byte, manifest string) { } // _deploy initializes defaults (total supply and registration price) on contract deploy. -func _deploy(data any, isUpdate bool) { +func _deploy(data any, isUpdate bool) { // nolint: unused if isUpdate { return } @@ -491,7 +491,7 @@ func getRecordKey(tokenId []byte, name string, typ RecordType) []byte { // isValid returns true if the provided address is a valid Uint160. func isValid(address interop.Hash160) bool { - return address != nil && len(address) == 20 + return address != nil && len(address) == 20 // nolint: gosimple } // checkCommittee panics if the script container is not signed by the committee. @@ -555,7 +555,7 @@ func splitAndCheck(name string, allowMultipleFragments bool) []string { if l > 2 && !allowMultipleFragments { return nil } - for i := 0; i < l; i++ { + for i := range fragments { if !checkFragment(fragments[i], i == l-1) { return nil } diff --git a/examples/nft-nd-nns/nns_test.go b/examples/nft-nd-nns/nns_test.go index 8afc6b9eb..d0d043c7c 100644 --- a/examples/nft-nd-nns/nns_test.go +++ b/examples/nft-nd-nns/nns_test.go @@ -418,11 +418,9 @@ func testTokensOf(t *testing.T, c *neotest.ContractInvoker, result [][]byte, arg } require.NoError(t, err) iter := s.Pop().Interop().Value().(*storage.Iterator) - arr := make([]stackitem.Item, 0, len(result)) for i := range result { require.True(t, iter.Next()) require.Equal(t, result[i], iter.Value().Value()) - arr = append(arr, stackitem.Make(result[i])) } require.False(t, iter.Next()) } diff --git a/examples/nft-nd/nft.go b/examples/nft-nd/nft.go index 96796049d..78a8bc29e 100644 --- a/examples/nft-nd/nft.go +++ b/examples/nft-nd/nft.go @@ -26,7 +26,7 @@ const ( totalSupplyPrefix = "s" // balancePrefix contains map from addresses to balances. balancePrefix = "b" - // accountPrefix contains map from address + token id to tokens + // accountPrefix contains map from address + token id to tokens. accountPrefix = "a" // tokenPrefix contains map from token id to it's owner. tokenPrefix = "t" diff --git a/examples/runtime/runtime.go b/examples/runtime/runtime.go index a98d39d29..2f98e8ecb 100644 --- a/examples/runtime/runtime.go +++ b/examples/runtime/runtime.go @@ -7,7 +7,7 @@ import ( ) var ( - // Check if the invoker of the contract is the specified owner + // Check if the invoker of the contract is the specified owner. owner = address.ToHash160("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB") ) @@ -22,7 +22,7 @@ func init() { // _deploy is called after contract deployment or update, it'll be called // in deployment transaction and if call update method of this contract. -func _deploy(_ any, isUpdate bool) { +func _deploy(_ any, isUpdate bool) { // nolint: unused if isUpdate { Log("_deploy method called after contract update") return diff --git a/examples/storage/storage.go b/examples/storage/storage.go index 2fe5f7305..4f6af2a5d 100644 --- a/examples/storage/storage.go +++ b/examples/storage/storage.go @@ -5,13 +5,13 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -// ctx holds storage context for contract methods +// ctx holds storage context for contract methods. var ctx storage.Context // defaultKey represents the default key. var defaultKey = []byte("default") -// init inits storage context before any other contract method is called +// init inits storage context before any other contract method is called. func init() { ctx = storage.GetContext() } diff --git a/examples/timer/timer.go b/examples/timer/timer.go index fcc37ef46..d8197a443 100644 --- a/examples/timer/timer.go +++ b/examples/timer/timer.go @@ -9,15 +9,15 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -const defaultTicks = 3 +const defaultTicks = 3 // nolint: unused const mgmtKey = "mgmt" var ( - // ctx holds storage context for contract methods + // ctx holds storage context for contract methods. ctx storage.Context - // Check if the invoker of the contract is the specified owner + // Check if the invoker of the contract is the specified owner. owner = address.ToHash160("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB") - // ticksKey is a storage key for ticks counter + // ticksKey is a storage key for ticks counter. ticksKey = []byte("ticks") ) @@ -25,7 +25,7 @@ func init() { ctx = storage.GetContext() } -func _deploy(_ any, isUpdate bool) { +func _deploy(_ any, isUpdate bool) { // nolint: unused if isUpdate { ticksLeft := storage.Get(ctx, ticksKey).(int) + 1 storage.Put(ctx, ticksKey, ticksLeft) diff --git a/examples/token/nep17/nep17.go b/examples/token/nep17/nep17.go index dc4702d5a..4d4ff4e73 100644 --- a/examples/token/nep17/nep17.go +++ b/examples/token/nep17/nep17.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) -// Token holds all token info +// Token holds all token info. type Token struct { // Token name Name string @@ -35,17 +35,17 @@ func getIntFromDB(ctx storage.Context, key []byte) int { return res } -// GetSupply gets the token totalSupply value from VM storage +// GetSupply gets the token totalSupply value from VM storage. func (t Token) GetSupply(ctx storage.Context) int { return getIntFromDB(ctx, []byte(t.CirculationKey)) } -// BalanceOf gets the token balance of a specific address +// BalanceOf gets the token balance of a specific address. func (t Token) BalanceOf(ctx storage.Context, holder []byte) int { return getIntFromDB(ctx, holder) } -// Transfer token from one user to another +// Transfer token from one user to another. func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount int, data any) bool { amountFrom := t.CanTransfer(ctx, from, to, amount) if amountFrom == -1 { @@ -74,7 +74,7 @@ func (t Token) Transfer(ctx storage.Context, from, to interop.Hash160, amount in return true } -// CanTransfer returns the amount it can transfer +// CanTransfer returns the amount it can transfer. func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount int) int { if len(to) != 20 || !IsUsableAddress(from) { return -1 @@ -94,10 +94,9 @@ func (t Token) CanTransfer(ctx storage.Context, from []byte, to []byte, amount i return amountFrom } -// IsUsableAddress checks if the sender is either the correct Neo address or SC address +// IsUsableAddress checks if the sender is either the correct Neo address or SC address. func IsUsableAddress(addr []byte) bool { if len(addr) == 20 { - if runtime.CheckWitness(addr) { return true } @@ -112,13 +111,13 @@ func IsUsableAddress(addr []byte) bool { return false } -// Mint initial supply of tokens +// Mint initial supply of tokens. func (t Token) Mint(ctx storage.Context, to interop.Hash160) bool { if !IsUsableAddress(t.Owner) { return false } minted := storage.Get(ctx, []byte("minted")) - if minted != nil && minted.(bool) == true { + if minted != nil && minted.(bool) { return false } diff --git a/examples/token/token.go b/examples/token/token.go index 47f4308bb..4a6d8daa5 100644 --- a/examples/token/token.go +++ b/examples/token/token.go @@ -19,7 +19,7 @@ var ( ) // init initializes Token Interface and storage context for the Smart -// Contract to operate with +// Contract to operate with. func init() { token = nep17.Token{ Name: "Awesome NEO Token", @@ -32,32 +32,32 @@ func init() { ctx = storage.GetContext() } -// Symbol returns the token symbol +// Symbol returns the token symbol. func Symbol() string { return token.Symbol } -// Decimals returns the token decimals +// Decimals returns the token decimals. func Decimals() int { return token.Decimals } -// TotalSupply returns the token total supply value +// TotalSupply returns the token total supply value. func TotalSupply() int { return token.GetSupply(ctx) } -// BalanceOf returns the amount of token on the specified address +// BalanceOf returns the amount of token on the specified address. func BalanceOf(holder interop.Hash160) int { return token.BalanceOf(ctx, holder) } -// Transfer token from one user to another +// Transfer token from one user to another. func Transfer(from interop.Hash160, to interop.Hash160, amount int, data any) bool { return token.Transfer(ctx, from, to, amount, data) } -// Mint initial supply of tokens +// Mint initial supply of tokens. func Mint(to interop.Hash160) bool { return token.Mint(ctx, to) } diff --git a/examples/zkp/cubic_circuit/main.go b/examples/zkp/cubic_circuit/main.go index 4afb66c86..eb916574c 100644 --- a/examples/zkp/cubic_circuit/main.go +++ b/examples/zkp/cubic_circuit/main.go @@ -51,7 +51,7 @@ func (circuit *CubicCircuit) Define(api frontend.API) error { // main demonstrates how to build the proof and verify it with the help of gnark // library. Error handling omitted intentionally to simplify the example. -func main() { +func main() { // nolint: unused var ( circuit CubicCircuit assignment = CubicCircuit{X: 3, Y: 35} diff --git a/examples/zkp/cubic_circuit/main_test.go b/examples/zkp/cubic_circuit/main_test.go index 1c9518657..babced1ff 100644 --- a/examples/zkp/cubic_circuit/main_test.go +++ b/examples/zkp/cubic_circuit/main_test.go @@ -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 := range nContributionsPhase2 { + for range nContributionsPhase2 { srs2.Contribute() } diff --git a/examples/zkp/xor_compat/verify.go b/examples/zkp/xor_compat/verify.go index 4a9c82d1a..8955cea66 100644 --- a/examples/zkp/xor_compat/verify.go +++ b/examples/zkp/xor_compat/verify.go @@ -43,7 +43,7 @@ var ( // proving system and is taken from the // https://github.com/neo-project/neo/issues/2647#issuecomment-1002893109 without // changes. The verification process checks the following equality: -// A * B = alpha * beta + sum(pub_input[i] * (beta * u_i(x) + alpha * v_i(x) + w_i(x)) / gamma) * gamma + C * delta +// A * B = alpha * beta + sum(pub_input[i] * (beta * u_i(x) + alpha * v_i(x) + w_i(x)) / gamma) * gamma + C * delta. func VerifyProof(a []byte, b []byte, c []byte, publicInput [][]byte) bool { alphaPoint := crypto.Bls12381Deserialize(alpha) betaPoint := crypto.Bls12381Deserialize(beta) @@ -68,11 +68,11 @@ func VerifyProof(a []byte, b []byte, c []byte, publicInput [][]byte) bool { panic("error: inputlen or iclen") } icPoints := make([]crypto.Bls12381Point, iclen) - for i := 0; i < iclen; i++ { + for i := range icPoints { icPoints[i] = crypto.Bls12381Deserialize(ic[i]) } acc := icPoints[0] - for i := 0; i < inputlen; i++ { + for i := range publicInput { scalar := publicInput[i] // 32-bytes LE field element. temp := crypto.Bls12381Mul(icPoints[i+1], scalar, false) acc = crypto.Bls12381Add(acc, temp) From 9fb291d5dff90dc2dbbb3480106c1935af98f7c7 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 18:20:21 +0300 Subject: [PATCH 4/7] workflows: add linter for scripts Signed-off-by: Anna Shaleva --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aac575036..b61d5ea9e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,6 +29,12 @@ jobs: with: workdir: examples/${{ matrix.contract }} + lint_scripts: + name: 'Lint: scripts' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + with: + workdir: scripts + gomodcheck: name: Check internal dependencies runs-on: ubuntu-latest From 25b353c9f8b63956afb479044dc82693d6be119c Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 18:21:53 +0300 Subject: [PATCH 5/7] workflows: enable lint for interop package Signed-off-by: Anna Shaleva --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b61d5ea9e..3d33da487 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,6 +35,12 @@ jobs: with: workdir: scripts + lint_interops: + name: 'Lint: interop' + uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master + with: + workdir: pkg/interop + gomodcheck: name: Check internal dependencies runs-on: ubuntu-latest From c5c64f5f07252aadc476e62382f8d9fc31d73e67 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 9 Oct 2024 18:25:05 +0300 Subject: [PATCH 6/7] interop: fix linter issues Signed-off-by: Anna Shaleva --- pkg/interop/native/ledger/transaction_signer.go | 2 +- pkg/interop/native/neo/neo.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/interop/native/ledger/transaction_signer.go b/pkg/interop/native/ledger/transaction_signer.go index 05270faf6..70f01e1e3 100644 --- a/pkg/interop/native/ledger/transaction_signer.go +++ b/pkg/interop/native/ledger/transaction_signer.go @@ -88,7 +88,7 @@ type WitnessCondition struct { // WitnessConditionType represents the type of rule-based witness condition. type WitnessConditionType byte -// Various witness condition types +// Various witness condition types. const ( // WitnessBoolean is a generic boolean condition. WitnessBoolean WitnessConditionType = 0x00 diff --git a/pkg/interop/native/neo/neo.go b/pkg/interop/native/neo/neo.go index e0031a2db..d536edd74 100644 --- a/pkg/interop/native/neo/neo.go +++ b/pkg/interop/native/neo/neo.go @@ -130,5 +130,4 @@ func GetAccountState(addr interop.Hash160) *AccountState { // GetCommitteeAddress represents `getCommitteeAddress` method of NEO native contract. func GetCommitteeAddress() interop.Hash160 { return neogointernal.CallWithToken(Hash, "getCommitteeAddress", int(contract.ReadStates)).(interop.Hash160) - } From 8bdb8afaf597b7824acabfd359f18e39a5db00cb Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 10 Oct 2024 11:33:07 +0300 Subject: [PATCH 7/7] Makefile: adjust lint target Enable linter for examples, scripts and interop packages. Signed-off-by: Anna Shaleva --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 82194ce04..0dcd98393 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ IMAGE_REPO=nspccdev/neo-go DISABLE_NEOTEST_COVER=1 +ROOT_DIR:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +GOMODDIRS=$(dir $(shell find $(ROOT_DIR) -name go.mod)) + # All of the targets are phony here because we don't really use make dependency # tracking for files .PHONY: build $(BINARY) deps image docker/$(BINARY) image-latest image-push image-push-latest clean-cluster \ @@ -113,7 +116,9 @@ vet: curl -L -o $@ https://github.com/nspcc-dev/.github/raw/master/.golangci.yml lint: .golangci.yml - @golangci-lint run + @for dir in $(GOMODDIRS); do \ + (cd "$$dir" && golangci-lint run --config $(ROOT_DIR)/$< | sed -r "s,^,$$dir," | sed -r "s,^$(ROOT_DIR),,") \ + done fmt: @gofmt -l -w -s $$(find . -type f -name '*.go'| grep -v "/vendor/")