forked from TrueCloudLab/neoneo-go
165525b7e9
Marshal account with `0x` prefix and add a test. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
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))
|
|
}
|