nspcc-dev / neofs-contract

NeoFS smart-contract
Other
9 stars 17 forks source link

rpc: Audit contract reader returns error from `List` when contract has no items #415

Open cthulhu-rider opened 1 week ago

cthulhu-rider commented 1 week ago

im exploring Audit contract in public NeoFS networks. I called list method of the Audit contract to analyze all stored results. As it turned out, there are no results in the contract, but I found out about this in an unexpected way

Current Behavior

Error:          Received unexpected error:
                            not an array

Expected Behavior

no error and number of results: 0

Possible Solution

i dug down to the result stack: there is 1 element of type Null. The error is originated by https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.106.2/pkg/rpcclient/unwrap#Array

i see next alternatives:

  1. make unwrap.Array to return nil, nil
  2. make unwrap.Array to return ErrNull
  3. add new function ArrayOrNull
  4. do manual stack surgery

being a user, i like 1 the most, but this is a change that could break some code which also treats null as an error. 3 will prevent this, but there is a whole family of ArrayOf* functions, and generated code . 4 is the worst to me - unwrap package and generated RPC callers were conceived to avoid this

another challenge is to teach codegen what to do - fail or not on null

Steps to Reproduce

func TestAuditResults(t *testing.T) {
    h, err := util.Uint160DecodeStringLE("85fe181f4aa3cbdc94023d97c69001ece0730398")
    require.NoError(t, err)
    c, err := rpcclient.New(context.Background(), "https://rpc1.morph.fs.neo.org:40341", rpcclient.Options{})
    require.NoError(t, err)
    require.NoError(t, c.Init())

    list, err := auditcontract.NewReader(invoker.New(c, nil), h).List()
    require.NoError(t, err)
    fmt.Println("number of results:", len(list))
}

Context

there are some other contracts and/or methods returning arrays, so same issue is likely related to them

Regression

no

Your Environment


P.S.

i'd add context to the error, who is not an array, of course you can guess, but you can also doubt it

roman-khimov commented 1 week ago

See https://github.com/nspcc-dev/neo-go/issues/2795.