Merge pull request #2959 from nspcc-dev/fix-nil-param

Fixes Any type processing server-side.
This commit is contained in:
Roman Khimov 2023-04-05 19:46:22 +03:00 committed by GitHub
commit 7e92b4a694
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -18,6 +18,7 @@ import (
"github.com/google/uuid"
"github.com/gorilla/websocket"
"github.com/nspcc-dev/neo-go/internal/basicchain"
"github.com/nspcc-dev/neo-go/internal/testchain"
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core"
@ -2529,3 +2530,34 @@ func TestWSClient_SubscriptionsCompat(t *testing.T) {
checkRelevant(t, false)
})
}
func TestActor_CallWithNilParam(t *testing.T) {
chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t)
defer chain.Close()
defer rpcSrv.Shutdown()
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
require.NoError(t, err)
acc, err := wallet.NewAccount()
require.NoError(t, err)
act, err := actor.New(c, []actor.SignerAccount{
{
Signer: transaction.Signer{
Account: acc.ScriptHash(),
},
Account: acc,
},
})
require.NoError(t, err)
rubles, err := chain.GetContractScriptHash(basicchain.RublesContractID)
require.NoError(t, err)
// We don't have a suitable contract, thus use Rubles with simple put method,
// it should fail at the moment of conversion Null value to ByteString (not earlier,
// and that's the point of the test!).
res, err := act.Call(rubles, "putValue", "123", (*util.Uint160)(nil))
require.NoError(t, err)
require.True(t, strings.Contains(res.FaultException, "invalid conversion: Null/ByteString"), res.FaultException)
}

View file

@ -84,7 +84,7 @@ func ExpandArrayIntoScript(script *io.BinWriter, slice []Param) error {
return err
}
case smartcontract.AnyType:
if fp.Value.IsNull() {
if fp.Value.IsNull() || len(fp.Value.RawMessage) == 0 {
emit.Opcodes(script, opcode.PUSHNULL)
}
default: