From a8d0ffa99e79fb2814acd53ef2696f2940239d5c Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 11 Dec 2019 16:13:37 -0600 Subject: [PATCH] fix trx decoding; test --- core/types/transaction.go | 4 ++-- core/types/transaction_test.go | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 23a833ab6..651d12c14 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -45,7 +45,7 @@ type Transaction struct { type txdata struct { AccountNonce uint64 `json:"nonce" gencodec:"required"` - Price *big.Int `json:"gasPrice"` + Price *big.Int `json:"gasPrice" rlp:"nil"` GasLimit uint64 `json:"gas" gencodec:"required"` Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation Amount *big.Int `json:"value" gencodec:"required"` @@ -244,7 +244,7 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error { } tx.data = txdata{ AccountNonce: *accountNonce, - Price: price, + Price: nil, GasLimit: *gasLimit, Recipient: recipient, Amount: amount, diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 56412b15e..747644292 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -147,6 +147,49 @@ func TestEIP1159TransactionEncode(t *testing.T) { } } +func TestEIP1159TransactionDecode(t *testing.T) { + tx, err := decodeTx(common.Hex2Bytes("f86903808207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a82554483030d40830c35001ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3")) + if err != nil { + t.Fatal(err) + } + if tx.data.FeeCap == nil || tx.data.FeeCap.Cmp(eip1559Tx.data.FeeCap) != 0 { + t.Fatal("unexpected FeeCap") + } + if tx.data.GasPremium == nil || tx.data.GasPremium.Cmp(eip1559Tx.data.GasPremium) != 0 { + t.Fatal("unexpected GasPremium") + } + if tx.data.Price != nil { + t.Fatal("expected GasPrice to be nil") + } + if tx.data.Hash != nil { + t.Fatal("expected tx Hash to be nil") + } + if tx.data.GasLimit != eip1559Tx.data.GasLimit { + t.Fatal("unexpected GasLimit") + } + if tx.data.Amount == nil || tx.data.Amount.Cmp(eip1559Tx.data.Amount) != 0 { + t.Fatal("unexpected Amount") + } + if tx.data.Recipient == nil || !bytes.Equal(tx.data.Recipient.Bytes(), eip1559Tx.data.Recipient.Bytes()) { + t.Fatal("unexpected Recipient") + } + if !bytes.Equal(tx.data.Payload, eip1559Tx.data.Payload) { + t.Fatal("unexpected Payload") + } + if tx.data.AccountNonce != eip1559Tx.data.AccountNonce { + t.Fatal("unexpected AccountNonce") + } + if tx.data.R == nil || tx.data.R.Cmp(eip1559Tx.data.R) != 0 { + t.Fatal("unexpected R") + } + if tx.data.V == nil || tx.data.V.Cmp(eip1559Tx.data.V) != 0 { + t.Fatal("unexpected V") + } + if tx.data.S == nil || tx.data.S.Cmp(eip1559Tx.data.S) != 0 { + t.Fatal("unexpected S") + } +} + func decodeTx(data []byte) (*Transaction, error) { var tx Transaction t, err := &tx, rlp.Decode(bytes.NewReader(data), &tx)