Skip to content

Commit

Permalink
gomod: upgrade yaml package from v2 to v3
Browse files Browse the repository at this point in the history
Close #2085.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
  • Loading branch information
fyrchik authored and AnnaShaleva committed May 30, 2022
1 parent ee82e29 commit ec21c14
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cli/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cli/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cli/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cli/smartcontract/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
31 changes: 17 additions & 14 deletions cli/smartcontract/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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
}

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 @@ -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 (
Expand Down
20 changes: 10 additions & 10 deletions cli/smartcontract/smart_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
})
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 1 addition & 1 deletion pkg/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion pkg/encoding/fixedn/fixed8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/smartcontract/callflag/call_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/uint160_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ec21c14

Please sign in to comment.