Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cthulhu-rider opened this issue Jun 27, 2024 · 1 comment
Labels
blocked Can't be done because of something bug Something isn't working I4 No visible changes S4 Routine U3 Regular

Comments

@cthulhu-rider
Copy link
Contributor

cthulhu-rider commented Jun 27, 2024

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/[email protected]/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

@cthulhu-rider cthulhu-rider added the bug Something isn't working label Jun 27, 2024
@roman-khimov
Copy link
Member

See nspcc-dev/neo-go#2795.

@roman-khimov roman-khimov added U3 Regular blocked Can't be done because of something S4 Routine I4 No visible changes labels Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Can't be done because of something bug Something isn't working I4 No visible changes S4 Routine U3 Regular
Projects
None yet
Development

No branches or pull requests

2 participants