core: remove description from NFT state

This commit is contained in:
Anna Shaleva 2021-02-16 16:24:05 +03:00
parent 9a8a19d2f2
commit 1e108f20a7
4 changed files with 11 additions and 31 deletions

View file

@ -604,17 +604,17 @@ func (s *nameState) FromStackItem(item stackitem.Item) error {
return err return err
} }
elems := item.Value().([]stackitem.Item) elems := item.Value().([]stackitem.Item)
if len(elems) < 5 { if len(elems) < 4 {
return errors.New("invalid stack item") return errors.New("invalid stack item")
} }
bi, err := elems[3].TryInteger() bi, err := elems[2].TryInteger()
if err != nil || !bi.IsUint64() { if err != nil || !bi.IsUint64() {
return errors.New("invalid stack item") return errors.New("invalid stack item")
} }
_, isNull := elems[4].(stackitem.Null) _, isNull := elems[3].(stackitem.Null)
if !isNull { if !isNull {
bs, err := elems[4].TryBytes() bs, err := elems[3].TryBytes()
if err != nil { if err != nil {
return err return err
} }

View file

@ -159,7 +159,6 @@ func TestRegisterAndRenew(t *testing.T) {
props := stackitem.NewMap() props := stackitem.NewMap()
props.Add(stackitem.Make("name"), stackitem.Make("neo.com")) props.Add(stackitem.Make("name"), stackitem.Make("neo.com"))
props.Add(stackitem.Make("description"), stackitem.Make(""))
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration)) props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
testNameServiceInvoke(t, bc, "properties", props, "neo.com") testNameServiceInvoke(t, bc, "properties", props, "neo.com")
testNameServiceInvoke(t, bc, "balanceOf", 1, testchain.CommitteeScriptHash()) testNameServiceInvoke(t, bc, "balanceOf", 1, testchain.CommitteeScriptHash())

View file

@ -13,9 +13,8 @@ import (
// NFTTokenState represents state of nonfungible token. // NFTTokenState represents state of nonfungible token.
type NFTTokenState struct { type NFTTokenState struct {
Owner util.Uint160 Owner util.Uint160
Name string Name string
Description string
} }
// NFTAccountState represents state of nonfunglible account. // NFTAccountState represents state of nonfunglible account.
@ -35,7 +34,6 @@ func (s *NFTTokenState) ToStackItem() stackitem.Item {
return stackitem.NewStruct([]stackitem.Item{ return stackitem.NewStruct([]stackitem.Item{
stackitem.NewByteArray(owner.BytesBE()), stackitem.NewByteArray(owner.BytesBE()),
stackitem.NewByteArray([]byte(s.Name)), stackitem.NewByteArray([]byte(s.Name)),
stackitem.NewByteArray([]byte(s.Description)),
}) })
} }
@ -47,7 +45,7 @@ func (s *NFTTokenState) EncodeBinary(w *io.BinWriter) {
// FromStackItem converts stackitem to NFTTokenState. // FromStackItem converts stackitem to NFTTokenState.
func (s *NFTTokenState) FromStackItem(item stackitem.Item) error { func (s *NFTTokenState) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item) arr, ok := item.Value().([]stackitem.Item)
if !ok || len(arr) < 3 { if !ok || len(arr) < 2 {
return errors.New("invalid stack item") return errors.New("invalid stack item")
} }
@ -63,14 +61,9 @@ func (s *NFTTokenState) FromStackItem(item stackitem.Item) error {
if err != nil { if err != nil {
return err return err
} }
desc, err := stackitem.ToString(arr[2])
if err != nil {
return err
}
s.Owner = owner s.Owner = owner
s.Name = name s.Name = name
s.Description = desc
return nil return nil
} }
@ -89,10 +82,6 @@ func (s *NFTTokenState) ToMap() *stackitem.Map {
Key: stackitem.NewByteArray([]byte("name")), Key: stackitem.NewByteArray([]byte("name")),
Value: stackitem.NewByteArray([]byte(s.Name)), Value: stackitem.NewByteArray([]byte(s.Name)),
}, },
{
Key: stackitem.NewByteArray([]byte("description")),
Value: stackitem.NewByteArray([]byte(s.Description)),
},
}) })
} }

View file

@ -22,9 +22,8 @@ func newStruct(args ...interface{}) *stackitem.Struct {
func TestNFTTokenState_Serializable(t *testing.T) { func TestNFTTokenState_Serializable(t *testing.T) {
t.Run("valid", func(t *testing.T) { t.Run("valid", func(t *testing.T) {
s := &NFTTokenState{ s := &NFTTokenState{
Owner: random.Uint160(), Owner: random.Uint160(),
Name: "random name", Name: "random name",
Description: "random description",
} }
id := s.ID() id := s.ID()
actual := new(NFTTokenState) actual := new(NFTTokenState)
@ -42,8 +41,6 @@ func TestNFTTokenState_Serializable(t *testing.T) {
{"invalid owner uint160", newStruct("123", "name", "desc")}, {"invalid owner uint160", newStruct("123", "name", "desc")},
{"invalid name", {"invalid name",
newStruct(random.Uint160().BytesBE(), []byte{0x80}, "desc")}, newStruct(random.Uint160().BytesBE(), []byte{0x80}, "desc")},
{"invalid description",
newStruct(random.Uint160().BytesBE(), "name", []byte{0x80})},
} }
for _, tc := range errCases { for _, tc := range errCases {
@ -59,9 +56,8 @@ func TestNFTTokenState_Serializable(t *testing.T) {
func TestNFTTokenState_ToMap(t *testing.T) { func TestNFTTokenState_ToMap(t *testing.T) {
s := &NFTTokenState{ s := &NFTTokenState{
Owner: random.Uint160(), Owner: random.Uint160(),
Name: "random name", Name: "random name",
Description: "random description",
} }
m := s.ToMap() m := s.ToMap()
@ -69,10 +65,6 @@ func TestNFTTokenState_ToMap(t *testing.T) {
i := m.Index(stackitem.Make("name")) i := m.Index(stackitem.Make("name"))
require.True(t, i < len(elems)) require.True(t, i < len(elems))
require.Equal(t, []byte("random name"), elems[i].Value.Value()) require.Equal(t, []byte("random name"), elems[i].Value.Value())
i = m.Index(stackitem.Make("description"))
require.True(t, i < len(elems))
require.Equal(t, []byte("random description"), elems[i].Value.Value())
} }
func TestNFTAccountState_Serializable(t *testing.T) { func TestNFTAccountState_Serializable(t *testing.T) {