CityOfZion / props

Ecosystem props than can be used to enhance project functionality
5 stars 3 forks source link

tokens/tokensOf implementation in PUPPET seems to be wrong #45

Open roman-khimov opened 2 years ago

roman-khimov commented 2 years ago

Test invocation of tokensOf for some address returns two elements:

./bin/neo-go contract testinvokefunction -r https://rpc10.n3.nspcc.ru:10331 0x76a8f8a7a901b29a33013b469949f4b08db15756 tokensOf NTApChTbQbGwGbrpiAkZ6HsFEDBWcmRd1W
{
  "state": "HALT",
  "gasconsumed": "618444",
  "script": "DBRPl57jRYRr2hwYCrfRsIX8eR/GlhHAHwwIdG9rZW5zT2YMFFZXsY2w9EmZRjsBM5qyAamn+Kh2QWJ9W1I=",
  "stack": [
    {
      "type": "InteropInterface",
      "iterator": [
        {
          "type": "Struct",
          "value": [
            {
              "type": "ByteString",
              "value": "aYcBXzEwNzc="
            },
            {
              "type": "ByteString",
              "value": "MTA3Nw=="
            }
          ]
        },
        {
          "type": "Struct",
          "value": [
            {
              "type": "ByteString",
              "value": "aYcBXzYwMQ=="
            },
            {
              "type": "ByteString",
              "value": "NjAx"
            }
          ]
        }
      ]
    }
  ],
  "exception": null,
  "notifications": []
}

Each of them is a struct, while NEP-11 says:

Each of these IDs SHOULD be a ByteString with a length of no more than 64 bytes.

The same thing happens with the tokens call. Most likely this happens because of the default Storage.Find options. I'm not sure about the storage scheme used by the contract, but you probably need to use ValuesOnly (or KeysOnly with RemovePrefix).

For an example of well-behaving NEP-11 please check 0xcd10d9f697230b04d9ebb8594a1ffe18fa95d9ad:

$ ./bin/neo-go contract testinvokefunction -r https://rpc10.n3.nspcc.ru:10331 0xcd10d9f697230b04d9ebb8594a1ffe18fa95d9ad tokensOf NeteCycXF1o64QgJQwUKVAp5HaViZwjGnq
{
  "state": "HALT",
  "gasconsumed": "455667",
  "script": "DBTQKiGP1X8uBQeo5FgOveUii7ouFxHAHwwIdG9rZW5zT2YMFK3ZlfoY/h9KWbjr2QQLI5f22RDNQWJ9W1I=",
  "stack": [
    {
      "type": "InteropInterface",
      "iterator": [
        {
          "type": "ByteString",
          "value": "TyAjMTQxMiBTY2FsYWJpbGl0eQ=="
        }
      ]
    }
  ],
  "exception": null,
  "notifications": []
}