From 1081791c6815c1ec0640ddf83ebe02c3c381722b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 18 Jun 2020 22:36:28 +0300 Subject: [PATCH] core: fix contract manifest unpacking in System.Contract.Create It's just JSON, io.Serializable is only used for DB storage where the length should be obtained from the stream. Fixes: 2020-06-18T22:14:10.571+0300 WARN contract invocation failed {"tx": "1ffd475a9c246495d6206cb80a9a78e9d14a433ded60cd37aa87d897655606e1", "block": 25893, "error": "error encountered at instruction 3696 (SYSCALL): failed to invoke syscall: invalid character ':' after top-level value"} --- pkg/core/helper_test.go | 2 +- pkg/core/interop_neo.go | 8 +++----- pkg/rpc/request/txBuilder.go | 7 ++++--- pkg/rpc/server/server_test.go | 4 ++-- pkg/rpc/server/testdata/testblocks.acc | Bin 6784 -> 6781 bytes 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index c4ff4f4b6..a334baa33 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -234,7 +234,7 @@ func TestCreateBasicChain(t *testing.T) { } m.ABI.EntryPoint.ReturnType = smartcontract.BoolType m.Features = smartcontract.HasStorage - bs, err := testserdes.EncodeBinary(m) + bs, err := m.MarshalJSON() require.NoError(t, err) emit.Bytes(script.BinWriter, bs) emit.Bytes(script.BinWriter, avm) diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index e27919ae5..6717c620c 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -8,7 +8,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/state" - "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" @@ -76,10 +75,9 @@ func createContractStateFromVM(ic *interop.Context, v *vm.VM) (*state.Contract, return nil, errGasLimitExceeded } var m manifest.Manifest - r := io.NewBinReaderFromBuf(manifestBytes) - m.DecodeBinary(r) - if r.Err != nil { - return nil, r.Err + err := m.UnmarshalJSON(manifestBytes) + if err != nil { + return nil, err } return &state.Contract{ Script: script, diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index 7176ff7f2..a28f94d4b 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -19,9 +19,10 @@ import ( // with its metadata and system fee require for this. func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util.Fixed8, error) { script := io.NewBufBinWriter() - w := io.NewBufBinWriter() - manif.EncodeBinary(w.BinWriter) - rawManifest := w.Bytes() + rawManifest, err := manif.MarshalJSON() + if err != nil { + return nil, 0, err + } emit.Bytes(script.BinWriter, rawManifest) emit.Bytes(script.BinWriter, avm) emit.Syscall(script.BinWriter, "System.Contract.Create") diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index a8428a642..7cd510479 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -51,7 +51,7 @@ type rpcTestCase struct { } const testContractHash = "e65ff7b3a02d207b584a5c27057d4e9862ef01da" -const deploymentTxHash = "5ce44eae362d3f81d440cb73cf4e4af71e69851bcd683b076aa08b7346d4e69b" +const deploymentTxHash = "b0428600383ec7f7b06734978a24dbe81edc87b781f58c0614f122c735d8cf6a" var rpcTestCases = map[string][]rpcTestCase{ "getapplicationlog": { @@ -148,7 +148,7 @@ var rpcTestCases = map[string][]rpcTestCase{ }, { Asset: e.chain.UtilityTokenHash(), - Amount: "923.96934740", + Amount: "923.96937740", LastUpdated: 6, }}, Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(), diff --git a/pkg/rpc/server/testdata/testblocks.acc b/pkg/rpc/server/testdata/testblocks.acc index 2a6c5f9107ba2f68574a7bd466c2b764305e5081..aa3bb8e87f48da812f1f12e0c5f3930e322b3ade 100644 GIT binary patch delta 2048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