forked from TrueCloudLab/neoneo-go
rpc: marshal GAS correctly
When using ",string" in JSON struct tag, value is first unmarshaled to a numeric value (float64 in our case), then to our real type via `UnmarshalJSON()`, which can lead to rounding errors.
This commit is contained in:
parent
1fee268f95
commit
7368ff09ef
2 changed files with 3 additions and 4 deletions
|
@ -26,7 +26,7 @@ type Invoke struct {
|
|||
|
||||
type invokeAux struct {
|
||||
State string `json:"state"`
|
||||
GasConsumed fixedn.Fixed8 `json:"gasconsumed,string"`
|
||||
GasConsumed fixedn.Fixed8 `json:"gasconsumed"`
|
||||
Script []byte `json:"script"`
|
||||
Stack json.RawMessage `json:"stack"`
|
||||
FaultException string `json:"exception,omitempty"`
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -14,7 +13,7 @@ import (
|
|||
func TestInvoke_MarshalJSON(t *testing.T) {
|
||||
result := &Invoke{
|
||||
State: "HALT",
|
||||
GasConsumed: int64(fixedn.Fixed8FromFloat(123.45)),
|
||||
GasConsumed: 237626000,
|
||||
Script: []byte{10},
|
||||
Stack: []stackitem.Item{stackitem.NewBigInteger(big.NewInt(1))},
|
||||
FaultException: "",
|
||||
|
@ -26,7 +25,7 @@ func TestInvoke_MarshalJSON(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
expected := `{
|
||||
"state":"HALT",
|
||||
"gasconsumed":"123.45",
|
||||
"gasconsumed":"2.37626",
|
||||
"script":"` + base64.StdEncoding.EncodeToString(result.Script) + `",
|
||||
"stack":[
|
||||
{"type":"Integer","value":"1"}
|
||||
|
|
Loading…
Reference in a new issue