Merge pull request #2452 from nspcc-dev/fix-rules

core: consider Rules witness scope as valid
This commit is contained in:
Roman Khimov 2022-04-27 12:54:14 +03:00 committed by GitHub
commit 9ad9700aef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -39,7 +39,7 @@ func (c *Signer) EncodeBinary(bw *io.BinWriter) {
func (c *Signer) DecodeBinary(br *io.BinReader) { func (c *Signer) DecodeBinary(br *io.BinReader) {
br.ReadBytes(c.Account[:]) br.ReadBytes(c.Account[:])
c.Scopes = WitnessScope(br.ReadB()) c.Scopes = WitnessScope(br.ReadB())
if c.Scopes & ^(Global|CalledByEntry|CustomContracts|CustomGroups|None) != 0 { if c.Scopes & ^(Global|CalledByEntry|CustomContracts|CustomGroups|Rules|None) != 0 {
br.Err = errors.New("unknown witness scope") br.Err = errors.New("unknown witness scope")
return return
} }

View file

@ -4,14 +4,20 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/internal/testserdes" "github.com/nspcc-dev/neo-go/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require"
) )
func TestCosignerEncodeDecode(t *testing.T) { func TestCosignerEncodeDecode(t *testing.T) {
pk, err := keys.NewPrivateKey()
require.NoError(t, err)
expected := &Signer{ expected := &Signer{
Account: util.Uint160{1, 2, 3, 4, 5}, Account: util.Uint160{1, 2, 3, 4, 5},
Scopes: CustomContracts, Scopes: CustomContracts | CustomGroups | Rules,
AllowedContracts: []util.Uint160{{1, 2, 3, 4}, {6, 7, 8, 9}}, AllowedContracts: []util.Uint160{{1, 2, 3, 4}, {6, 7, 8, 9}},
AllowedGroups: []*keys.PublicKey{pk.PublicKey()},
Rules: []WitnessRule{{Action: WitnessAllow, Condition: ConditionCalledByEntry{}}},
} }
actual := &Signer{} actual := &Signer{}
testserdes.EncodeDecodeBinary(t, expected, actual) testserdes.EncodeDecodeBinary(t, expected, actual)