transactions: fix JSON unmarshalling of fees

Fixed8 is already marshalled as a string and stripping quotes from it just
leads to interpreting it as a float with all regular float problems (like
test transaction failing with `txid doesn't match transaction hash`).
This commit is contained in:
Roman Khimov 2021-01-22 18:22:09 +03:00
parent dfc23c4246
commit 120ae4841f
2 changed files with 34 additions and 2 deletions

View file

@ -307,8 +307,8 @@ type transactionJSON struct {
Version uint8 `json:"version"`
Nonce uint32 `json:"nonce"`
Sender string `json:"sender"`
SystemFee fixedn.Fixed8 `json:"sysfee,string"`
NetworkFee fixedn.Fixed8 `json:"netfee,string"`
SystemFee fixedn.Fixed8 `json:"sysfee"`
NetworkFee fixedn.Fixed8 `json:"netfee"`
ValidUntilBlock uint32 `json:"validuntilblock"`
Attributes []Attribute `json:"attributes"`
Signers []Signer `json:"signers"`

View file

@ -3,6 +3,7 @@ package transaction
import (
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"math"
"testing"
@ -113,6 +114,37 @@ func TestDecodingTXWithNoScript(t *testing.T) {
require.Error(t, err)
}
func TestUnmarshalNeoFSTX(t *testing.T) {
txjson := []byte(`
{
"hash": "0x635a3624bbe6cf99aee70e9cbd6473d913b6712cad6e717647f3ddf0fd13bfbb",
"size": 232,
"version": 0,
"nonce": 737880259,
"sender": "NiRqSd5MtRZT5yUhgWd7oG11brkDG76Jim",
"sysfee": "2.2371942",
"netfee": "0.0121555",
"validuntilblock": 1931,
"attributes": [],
"signers": [
{
"account": "0x8f0ecd714c31c5624b6647e5fd661e5031c8f8f6",
"scopes": "Global"
}
],
"script": "DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcIRwBESwAwEdm90ZQwUo4Hyc4fSGC6JbZtdrGb9LBbtWJtBYn1bUg==",
"witnesses": [
{
"invocation": "DEDr2gA/8T/wxQvgOZVfCdkbj6uGrprkDgJvpOJCcbl+tvlKZkZytCZEWm6NoZhJyIlEI3VQSLtU3AHuJfShAT5L",
"verification": "DCEDAS1H52IQrsc745qz0YbgpA/o2Gv6PU+r/aV7oTuI+WoLQZVEDXg="
}
]
}`)
tx := new(Transaction)
tx.Network = 56753
require.NoError(t, json.Unmarshal(txjson, tx))
}
func TestMarshalUnmarshalJSONInvocationTX(t *testing.T) {
tx := &Transaction{
Version: 0,