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
}
elems := item.Value().([]stackitem.Item)
if len(elems) < 5 {
if len(elems) < 4 {
return errors.New("invalid stack item")
}
bi, err := elems[3].TryInteger()
bi, err := elems[2].TryInteger()
if err != nil || !bi.IsUint64() {
return errors.New("invalid stack item")
}
_, isNull := elems[4].(stackitem.Null)
_, isNull := elems[3].(stackitem.Null)
if !isNull {
bs, err := elems[4].TryBytes()
bs, err := elems[3].TryBytes()
if err != nil {
return err
}

View file

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

View file

@ -13,9 +13,8 @@ import (
// NFTTokenState represents state of nonfungible token.
type NFTTokenState struct {
Owner util.Uint160
Name string
Description string
Owner util.Uint160
Name string
}
// NFTAccountState represents state of nonfunglible account.
@ -35,7 +34,6 @@ func (s *NFTTokenState) ToStackItem() stackitem.Item {
return stackitem.NewStruct([]stackitem.Item{
stackitem.NewByteArray(owner.BytesBE()),
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.
func (s *NFTTokenState) FromStackItem(item stackitem.Item) error {
arr, ok := item.Value().([]stackitem.Item)
if !ok || len(arr) < 3 {
if !ok || len(arr) < 2 {
return errors.New("invalid stack item")
}
@ -63,14 +61,9 @@ func (s *NFTTokenState) FromStackItem(item stackitem.Item) error {
if err != nil {
return err
}
desc, err := stackitem.ToString(arr[2])
if err != nil {
return err
}
s.Owner = owner
s.Name = name
s.Description = desc
return nil
}
@ -89,10 +82,6 @@ func (s *NFTTokenState) ToMap() *stackitem.Map {
Key: stackitem.NewByteArray([]byte("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) {
t.Run("valid", func(t *testing.T) {
s := &NFTTokenState{
Owner: random.Uint160(),
Name: "random name",
Description: "random description",
Owner: random.Uint160(),
Name: "random name",
}
id := s.ID()
actual := new(NFTTokenState)
@ -42,8 +41,6 @@ func TestNFTTokenState_Serializable(t *testing.T) {
{"invalid owner uint160", newStruct("123", "name", "desc")},
{"invalid name",
newStruct(random.Uint160().BytesBE(), []byte{0x80}, "desc")},
{"invalid description",
newStruct(random.Uint160().BytesBE(), "name", []byte{0x80})},
}
for _, tc := range errCases {
@ -59,9 +56,8 @@ func TestNFTTokenState_Serializable(t *testing.T) {
func TestNFTTokenState_ToMap(t *testing.T) {
s := &NFTTokenState{
Owner: random.Uint160(),
Name: "random name",
Description: "random description",
Owner: random.Uint160(),
Name: "random name",
}
m := s.ToMap()
@ -69,10 +65,6 @@ func TestNFTTokenState_ToMap(t *testing.T) {
i := m.Index(stackitem.Make("name"))
require.True(t, i < len(elems))
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) {