Skip to content

Commit

Permalink
unmarshal fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Mar 25, 2024
1 parent 57d22cb commit 925e9a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
16 changes: 16 additions & 0 deletions e2e/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"crypto/ecdsa"
"errors"
"math/big"
"os"
"path/filepath"
"testing"
"time"

Expand All @@ -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)
Expand Down
23 changes: 15 additions & 8 deletions types/json_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 925e9a8

Please sign in to comment.