diff --git a/pkg/neorpc/types.go b/pkg/neorpc/types.go index bbe7b690a..8a2a24dd2 100644 --- a/pkg/neorpc/types.go +++ b/pkg/neorpc/types.go @@ -97,7 +97,7 @@ func (s *SignerWithWitness) MarshalJSON() ([]byte, error) { return nil, fmt.Errorf("failed to marshal scopes: %w", err) } signer := &signerWithWitnessAux{ - Account: s.Account.StringLE(), + Account: `0x` + s.Account.StringLE(), Scopes: sc, AllowedContracts: s.AllowedContracts, AllowedGroups: s.AllowedGroups, diff --git a/pkg/neorpc/types_test.go b/pkg/neorpc/types_test.go new file mode 100644 index 000000000..f0c99ea23 --- /dev/null +++ b/pkg/neorpc/types_test.go @@ -0,0 +1,40 @@ +package neorpc + +import ( + "encoding/json" + "testing" + + "github.com/nspcc-dev/neo-go/internal/testserdes" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/stretchr/testify/require" +) + +func TestSignerWithWitnessMarshalUnmarshalJSON(t *testing.T) { + s := &SignerWithWitness{ + Signer: transaction.Signer{ + Account: util.Uint160{1, 2, 3}, + Scopes: transaction.CalledByEntry | transaction.CustomContracts, + AllowedContracts: []util.Uint160{{1, 2, 3, 4}}, + }, + Witness: transaction.Witness{ + InvocationScript: []byte{1, 2, 3}, + VerificationScript: []byte{4, 5, 6}, + }, + } + testserdes.MarshalUnmarshalJSON(t, s, &SignerWithWitness{}) + + // Check marshalling separately to ensure Scopes are marshalled OK. + expected := `{"account":"0xcadb3dc2faa3ef14a13b619c9a43124755aa2569","scopes":"CalledByEntry, CustomContracts"}` + acc, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569") + require.NoError(t, err) + s = &SignerWithWitness{ + Signer: transaction.Signer{ + Account: acc, + Scopes: transaction.CalledByEntry | transaction.CustomContracts, + }, + } + actual, err := json.Marshal(s) + require.NoError(t, err) + require.Equal(t, expected, string(actual)) +}