From 925e9a8b7f0c1f704e76f586ed852dc4b74a4071 Mon Sep 17 00:00:00 2001 From: Goran Rojovic Date: Mon, 25 Mar 2024 09:58:57 +0100 Subject: [PATCH] unmarshal fix --- e2e/txpool_test.go | 16 ++++++++++++++++ types/json_unmarshal.go | 23 +++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/e2e/txpool_test.go b/e2e/txpool_test.go index 9374729769..aa3bcc1da3 100644 --- a/e2e/txpool_test.go +++ b/e2e/txpool_test.go @@ -5,6 +5,8 @@ import ( "crypto/ecdsa" "errors" "math/big" + "os" + "path/filepath" "testing" "time" @@ -25,6 +27,20 @@ import ( "github.com/stretchr/testify/assert" ) +func init() { + wd, err := os.Getwd() + if err != nil { + return + } + + parent := filepath.Dir(wd) + wd = filepath.Join(parent, "/artifacts/polygon-edge") + os.Setenv("EDGE_BINARY", wd) + os.Setenv("E2E_TESTS", "true") + os.Setenv("E2E_LOGS", "true") + os.Setenv("E2E_LOG_LEVEL", "debug") +} + var ( oneEth = framework.EthToWei(1) defaultChainID = uint64(100) diff --git a/types/json_unmarshal.go b/types/json_unmarshal.go index b9fbea925b..6574ac5355 100644 --- a/types/json_unmarshal.go +++ b/types/json_unmarshal.go @@ -15,7 +15,6 @@ func (b *Block) UnmarshalJSON(buf []byte) error { } // header - b.Header = &Header{} if err := b.Header.unmarshalJSON(v); err != nil { return err } @@ -66,6 +65,8 @@ func (h *Header) UnmarshalJSON(buf []byte) error { } func (h *Header) unmarshalJSON(v *fastjson.Value) error { + h = new(Header) + var err error if h.Hash, err = UnmarshalJSONHash(v, "hash"); err != nil { @@ -151,6 +152,8 @@ func (t *Transaction) UnmarshalJSON(buf []byte) error { } func (t *Transaction) UnmarshalJSONWith(v *fastjson.Value) error { + t = new(Transaction) + if HasKey(v, "type") { txnType, err := UnmarshalJSONUint64(v, "type") if err != nil { @@ -183,6 +186,8 @@ func (r *Receipt) UnmarshalJSON(buf []byte) error { return nil } + r = new(Receipt) + if HasKey(v, "contractAddress") { contractAddr, err := UnmarshalJSONAddr(v, "contractAddress") if err != nil { @@ -238,7 +243,7 @@ func (r *Receipt) UnmarshalJSON(buf []byte) error { } // UnmarshalJSON implements the unmarshal interface -func (r *Log) UnmarshalJSON(buf []byte) error { +func (l *Log) UnmarshalJSON(buf []byte) error { p := DefaultPool.Get() defer DefaultPool.Put(p) @@ -247,21 +252,23 @@ func (r *Log) UnmarshalJSON(buf []byte) error { return nil } - return r.unmarshalJSON(v) + return l.unmarshalJSON(v) } -func (r *Log) unmarshalJSON(v *fastjson.Value) error { +func (l *Log) unmarshalJSON(v *fastjson.Value) error { + l = new(Log) + var err error - if r.Address, err = UnmarshalJSONAddr(v, "address"); err != nil { + if l.Address, err = UnmarshalJSONAddr(v, "address"); err != nil { return err } - if r.Data, err = UnmarshalJSONBytes(v, "data"); err != nil { + if l.Data, err = UnmarshalJSONBytes(v, "data"); err != nil { return err } - r.Topics = r.Topics[:0] + l.Topics = l.Topics[:0] for _, topic := range v.GetArray("topics") { b, err := topic.StringBytes() @@ -274,7 +281,7 @@ func (r *Log) unmarshalJSON(v *fastjson.Value) error { return err } - r.Topics = append(r.Topics, t) + l.Topics = append(l.Topics, t) } return nil