From ec21c14ca98cbdce9750fd53ea4d876d180bf3fd Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Sat, 25 Sep 2021 13:09:55 +0300 Subject: [PATCH] gomod: upgrade yaml package from v2 to v3 Close #2085. Signed-off-by: Evgeniy Stratonikov --- cli/dump_test.go | 2 +- cli/server/server_test.go | 2 +- cli/server_test.go | 2 +- cli/smartcontract/generate.go | 2 +- cli/smartcontract/permission.go | 31 ++++++++++--------- cli/smartcontract/smart_contract.go | 2 +- cli/smartcontract/smart_contract_test.go | 20 ++++++------ go.mod | 2 +- go.sum | 3 +- pkg/compiler/compiler.go | 2 +- pkg/config/config.go | 2 +- pkg/encoding/fixedn/fixed8_test.go | 2 +- pkg/smartcontract/callflag/call_flags_test.go | 2 +- pkg/util/uint160_test.go | 2 +- 14 files changed, 40 insertions(+), 36 deletions(-) diff --git a/cli/dump_test.go b/cli/dump_test.go index 5dd9dde74..73dba82b4 100644 --- a/cli/dump_test.go +++ b/cli/dump_test.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) func TestDBRestoreDump(t *testing.T) { diff --git a/cli/server/server_test.go b/cli/server/server_test.go index 4c62ac37c..99d523d03 100644 --- a/cli/server/server_test.go +++ b/cli/server/server_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/urfave/cli" "go.uber.org/zap" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // serverTestWD is the default working directory for server tests. diff --git a/cli/server_test.go b/cli/server_test.go index 5aa28d59a..6c32b837f 100644 --- a/cli/server_test.go +++ b/cli/server_test.go @@ -12,7 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/cli/server" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) func TestServerStart(t *testing.T) { diff --git a/cli/smartcontract/generate.go b/cli/smartcontract/generate.go index 226dfedb1..c033914ac 100644 --- a/cli/smartcontract/generate.go +++ b/cli/smartcontract/generate.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/binding" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/urfave/cli" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) var generateWrapperCmd = cli.Command{ diff --git a/cli/smartcontract/permission.go b/cli/smartcontract/permission.go index 2b53be285..0c4608b84 100644 --- a/cli/smartcontract/permission.go +++ b/cli/smartcontract/permission.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) type permission manifest.Permission @@ -20,20 +20,18 @@ const ( ) func (p permission) MarshalYAML() (interface{}, error) { - m := make(yaml.MapSlice, 0, 2) + m := yaml.Node{Kind: yaml.MappingNode} switch p.Contract.Type { case manifest.PermissionWildcard: case manifest.PermissionHash: - m = append(m, yaml.MapItem{ - Key: permHashKey, - Value: p.Contract.Value.(util.Uint160).StringLE(), - }) + m.Content = append(m.Content, + &yaml.Node{Kind: yaml.ScalarNode, Value: permHashKey}, + &yaml.Node{Kind: yaml.ScalarNode, Value: p.Contract.Value.(util.Uint160).StringLE()}) case manifest.PermissionGroup: bs := p.Contract.Value.(*keys.PublicKey).Bytes() - m = append(m, yaml.MapItem{ - Key: permGroupKey, - Value: hex.EncodeToString(bs), - }) + m.Content = append(m.Content, + &yaml.Node{Kind: yaml.ScalarNode, Value: permGroupKey}, + &yaml.Node{Kind: yaml.ScalarNode, Value: hex.EncodeToString(bs)}) default: return nil, fmt.Errorf("invalid permission type: %d", p.Contract.Type) } @@ -43,10 +41,15 @@ func (p permission) MarshalYAML() (interface{}, error) { val = p.Methods.Value } - m = append(m, yaml.MapItem{ - Key: permMethodKey, - Value: val, - }) + n := &yaml.Node{Kind: yaml.ScalarNode} + err := n.Encode(val) + if err != nil { + return nil, err + } + m.Content = append(m.Content, + &yaml.Node{Kind: yaml.ScalarNode, Value: permMethodKey}, + n) + return m, nil } diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 558fa4ceb..097529b1c 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -29,7 +29,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/urfave/cli" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) var ( diff --git a/cli/smartcontract/smart_contract_test.go b/cli/smartcontract/smart_contract_test.go index 0c4011174..a2b119dfe 100644 --- a/cli/smartcontract/smart_contract_test.go +++ b/cli/smartcontract/smart_contract_test.go @@ -11,7 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/stretchr/testify/require" "github.com/urfave/cli" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) func TestInitSmartContract(t *testing.T) { @@ -57,19 +57,19 @@ func RuntimeNotify(args []interface{}) { manifest, err := os.ReadFile(contractName + "/" + files[2].Name()) require.NoError(t, err) - require.Equal(t, - `name: testContract + expected := `name: testContract sourceurl: http://example.com/ safemethods: [] supportedstandards: [] events: -- name: Hello world! - parameters: - - name: args - type: Array + - name: Hello world! + parameters: + - name: args + type: Array permissions: -- methods: '*' -`, string(manifest)) + - methods: '*' +` + require.Equal(t, expected, string(manifest)) } func testPermissionMarshal(t *testing.T, p *manifest.Permission, expected string) { @@ -110,7 +110,7 @@ func TestPermissionMarshal(t *testing.T) { p.Methods.Add("lamao") testPermissionMarshal(t, p, "group: "+hex.EncodeToString(priv.PublicKey().Bytes())+"\n"+ - "methods:\n- abc\n- lamao\n") + "methods:\n - abc\n - lamao\n") }) } diff --git a/go.mod b/go.mod index 6e557d6c9..5a4c68dfe 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( golang.org/x/term v0.0.0-20210429154555-c04ba851c2a4 golang.org/x/text v0.3.7 golang.org/x/tools v0.1.8 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) go 1.16 diff --git a/go.sum b/go.sum index 5fdfc7005..5a843a007 100644 --- a/go.sum +++ b/go.sum @@ -448,7 +448,8 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 16c0fa114..949230e44 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -19,7 +19,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/util" "golang.org/x/tools/go/packages" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) const fileExt = "nef" diff --git a/pkg/config/config.go b/pkg/config/config.go index 3e187f7bd..f0ee83cad 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -6,7 +6,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/rpc" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) const ( diff --git a/pkg/encoding/fixedn/fixed8_test.go b/pkg/encoding/fixedn/fixed8_test.go index 8498a5793..db94c3062 100644 --- a/pkg/encoding/fixedn/fixed8_test.go +++ b/pkg/encoding/fixedn/fixed8_test.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) func TestFixed8FromInt64(t *testing.T) { diff --git a/pkg/smartcontract/callflag/call_flags_test.go b/pkg/smartcontract/callflag/call_flags_test.go index b1c057e4e..6757afdbf 100644 --- a/pkg/smartcontract/callflag/call_flags_test.go +++ b/pkg/smartcontract/callflag/call_flags_test.go @@ -5,7 +5,7 @@ import ( "github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) func TestCallFlag_Has(t *testing.T) { diff --git a/pkg/util/uint160_test.go b/pkg/util/uint160_test.go index fead28080..4d3cb3a44 100644 --- a/pkg/util/uint160_test.go +++ b/pkg/util/uint160_test.go @@ -8,7 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) func TestUint160UnmarshalJSON(t *testing.T) {