2020-11-26 11:17:21 +00:00
|
|
|
package result
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
2021-03-25 16:18:01 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2020-11-26 11:17:21 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInvoke_MarshalJSON(t *testing.T) {
|
2021-03-25 16:18:01 +00:00
|
|
|
tx := transaction.New([]byte{1, 2, 3, 4}, 0)
|
|
|
|
tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}
|
2021-04-08 12:49:14 +00:00
|
|
|
tx.Scripts = []transaction.Witness{{InvocationScript: []byte{}, VerificationScript: []byte{}}}
|
2021-03-25 16:18:01 +00:00
|
|
|
_ = tx.Size()
|
|
|
|
tx.Hash()
|
|
|
|
|
2020-11-26 11:17:21 +00:00
|
|
|
result := &Invoke{
|
|
|
|
State: "HALT",
|
2020-12-10 12:21:26 +00:00
|
|
|
GasConsumed: 237626000,
|
2020-11-26 11:17:21 +00:00
|
|
|
Script: []byte{10},
|
|
|
|
Stack: []stackitem.Item{stackitem.NewBigInteger(big.NewInt(1))},
|
|
|
|
FaultException: "",
|
2021-03-25 16:18:01 +00:00
|
|
|
Transaction: tx,
|
2020-11-26 11:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(result)
|
|
|
|
require.NoError(t, err)
|
|
|
|
expected := `{
|
|
|
|
"state":"HALT",
|
2021-02-09 08:16:18 +00:00
|
|
|
"gasconsumed":"237626000",
|
2020-11-26 11:17:21 +00:00
|
|
|
"script":"` + base64.StdEncoding.EncodeToString(result.Script) + `",
|
|
|
|
"stack":[
|
|
|
|
{"type":"Integer","value":"1"}
|
|
|
|
],
|
2021-03-25 16:18:01 +00:00
|
|
|
"tx":"` + base64.StdEncoding.EncodeToString(tx.Bytes()) + `"
|
2020-11-26 11:17:21 +00:00
|
|
|
}`
|
|
|
|
require.JSONEq(t, expected, string(data))
|
|
|
|
|
|
|
|
actual := new(Invoke)
|
|
|
|
require.NoError(t, json.Unmarshal(data, actual))
|
|
|
|
require.Equal(t, result, actual)
|
|
|
|
}
|