From 0ce971d9d396521697b56efeb60e28fe40bd0015 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 15:27:14 +0200 Subject: [PATCH 01/24] Add new formatting regex --- rpc/responses_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 43924151a4..20bc8e97dd 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -13,12 +13,13 @@ import ( ) const ( - reHash = `"0x[0-9a-f]{64}"` // 32 bytes - reHashOpt = `"(0x[0-9a-f]{64})"|null` // 32 bytes or null - reAddress = `"0x[0-9a-f]{40}"` // 20 bytes - reAddressOpt = `"0x[0-9a-f]{40}"|null` // 20 bytes or null - reNum = `"0x([1-9a-f][0-9a-f]{1,15})|0"` // must not have left-padded zeros - reData = `"0x[0-9a-f]*"` // can be "empty" + reHash = `"0x[0-9a-f]{64}"` // 32 bytes + reHashOpt = `"(0x[0-9a-f]{64})"|null` // 32 bytes or null + reAddress = `"0x[0-9a-f]{40}"` // 20 bytes + reAddressOpt = `"0x[0-9a-f]{40}"|null` // 20 bytes or null + reNum = `"0x([1-9a-f][0-9a-f]{0,15})|0"` // must not have left-padded zeros + reNumOpt = `"0x([1-9a-f][0-9a-f]{0,15})|0"|null` // must not have left-padded zeros or null + reData = `"0x[0-9a-f]*"` // can be "empty" ) func TestNewBlockRes(t *testing.T) { From 93f832a1a76430ebb18276aaf2a3f18d000edae2 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 15:27:37 +0200 Subject: [PATCH 02/24] Make block context optional nulls --- rpc/responses_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 20bc8e97dd..702fc5c226 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -72,9 +72,9 @@ func TestNewTransactionRes(t *testing.T) { tests := map[string]string{ "hash": reHash, "nonce": reNum, - "blockHash": reHash, - "blockNum": reNum, - "transactionIndex": reNum, + "blockHash": reHashOpt, + "blockNum": reNumOpt, + "transactionIndex": reNumOpt, "from": reAddress, "to": reAddressOpt, "value": reNum, From 6e8ff578f18473d7c4fe013a88d2bece1ecf65d1 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 15:28:06 +0200 Subject: [PATCH 03/24] Block nonce as data --- rpc/responses.go | 4 ++-- rpc/responses_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/responses.go b/rpc/responses.go index 45a2fa18b2..0f67299fc3 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -11,7 +11,7 @@ type BlockRes struct { BlockNumber *hexnum `json:"number"` BlockHash *hexdata `json:"hash"` ParentHash *hexdata `json:"parentHash"` - Nonce *hexnum `json:"nonce"` + Nonce *hexdata `json:"nonce"` Sha3Uncles *hexdata `json:"sha3Uncles"` LogsBloom *hexdata `json:"logsBloom"` TransactionRoot *hexdata `json:"transactionRoot"` @@ -41,7 +41,7 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { res.BlockNumber = newHexNum(block.Number()) res.BlockHash = newHexData(block.Hash()) res.ParentHash = newHexData(block.ParentHash()) - res.Nonce = newHexNum(block.Header().Nonce) + res.Nonce = newHexData(block.Header().Nonce) res.Sha3Uncles = newHexData(block.Header().UncleHash) res.LogsBloom = newHexData(block.Bloom()) res.TransactionRoot = newHexData(block.Header().TxHash) diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 702fc5c226..949e1794ba 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -34,7 +34,7 @@ func TestNewBlockRes(t *testing.T) { "number": reNum, "hash": reHash, "parentHash": reHash, - "nonce": reNum, + "nonce": reData, "sha3Uncles": reHash, "logsBloom": reData, "transactionRoot": reHash, From ac03ff6f055ef2bd9404a30a0c257fdd2722eafe Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 15:44:09 +0200 Subject: [PATCH 04/24] Fix block size output #613 --- common/size.go | 4 ++++ rpc/responses.go | 2 +- rpc/responses_test.go | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/size.go b/common/size.go index b5c0b0b3f6..0d9dbf5583 100644 --- a/common/size.go +++ b/common/size.go @@ -17,6 +17,10 @@ func (self StorageSize) String() string { } } +func (self StorageSize) Int64() int64 { + return int64(self) +} + // The different number of units var ( Douglas = BigPow(10, 42) diff --git a/rpc/responses.go b/rpc/responses.go index 0f67299fc3..41776a0be0 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -49,7 +49,7 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { res.Miner = newHexData(block.Header().Coinbase) res.Difficulty = newHexNum(block.Difficulty()) res.TotalDifficulty = newHexNum(block.Td) - res.Size = newHexNum(block.Size()) + res.Size = newHexNum(block.Size().Int64()) res.ExtraData = newHexData(block.Header().Extra) res.GasLimit = newHexNum(block.GasLimit()) // res.MinGasPrice = diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 949e1794ba..704a381863 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -18,6 +18,7 @@ const ( reAddress = `"0x[0-9a-f]{40}"` // 20 bytes reAddressOpt = `"0x[0-9a-f]{40}"|null` // 20 bytes or null reNum = `"0x([1-9a-f][0-9a-f]{0,15})|0"` // must not have left-padded zeros + reNumNonZero = `"0x([1-9a-f][0-9a-f]{0,15})"` // non-zero required must not have left-padded zeros reNumOpt = `"0x([1-9a-f][0-9a-f]{0,15})|0"|null` // must not have left-padded zeros or null reData = `"0x[0-9a-f]*"` // can be "empty" ) @@ -42,7 +43,7 @@ func TestNewBlockRes(t *testing.T) { "miner": reAddress, "difficulty": `"0x1"`, "totalDifficulty": reNum, - "size": reNum, + "size": reNumNonZero, "extraData": reData, "gasLimit": reNum, // "minGasPrice": "0x", From bea3879d6f5862886948b9045b6c6111b41f8480 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 15:45:56 +0200 Subject: [PATCH 05/24] If nil, type doesn't matter --- rpc/messages.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpc/messages.go b/rpc/messages.go index 3c011cd93b..549268cce3 100644 --- a/rpc/messages.go +++ b/rpc/messages.go @@ -45,6 +45,9 @@ func (d *hexdata) UnmarshalJSON(b []byte) (err error) { func newHexData(input interface{}) *hexdata { d := new(hexdata) + if input == nil { + d.data = nil + } switch input := input.(type) { case []byte: d.data = input From 55b9689950dbb3f47e2d4720d04d2539243429bd Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 15:53:48 +0200 Subject: [PATCH 06/24] rename messages to types --- rpc/{messages.go => types.go} | 0 rpc/{messages_test.go => types_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename rpc/{messages.go => types.go} (100%) rename rpc/{messages_test.go => types_test.go} (100%) diff --git a/rpc/messages.go b/rpc/types.go similarity index 100% rename from rpc/messages.go rename to rpc/types.go diff --git a/rpc/messages_test.go b/rpc/types_test.go similarity index 100% rename from rpc/messages_test.go rename to rpc/types_test.go From b6f0b400375dfe3ae1ada954f14fa15155163f1e Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 16:49:07 +0200 Subject: [PATCH 07/24] Respect fullTx option #614 --- rpc/responses.go | 95 +++++++++++++++++++++++++++++++++++++++++++ rpc/responses_test.go | 63 ++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/rpc/responses.go b/rpc/responses.go index 41776a0be0..172a0902fd 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -1,6 +1,8 @@ package rpc import ( + "encoding/json" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" ) @@ -29,6 +31,99 @@ type BlockRes struct { Uncles []*hexdata `json:"uncles"` } +func (b *BlockRes) MarshalJSON() ([]byte, error) { + if b.fullTx { + var ext struct { + BlockNumber *hexnum `json:"number"` + BlockHash *hexdata `json:"hash"` + ParentHash *hexdata `json:"parentHash"` + Nonce *hexdata `json:"nonce"` + Sha3Uncles *hexdata `json:"sha3Uncles"` + LogsBloom *hexdata `json:"logsBloom"` + TransactionRoot *hexdata `json:"transactionRoot"` + StateRoot *hexdata `json:"stateRoot"` + Miner *hexdata `json:"miner"` + Difficulty *hexnum `json:"difficulty"` + TotalDifficulty *hexnum `json:"totalDifficulty"` + Size *hexnum `json:"size"` + ExtraData *hexdata `json:"extraData"` + GasLimit *hexnum `json:"gasLimit"` + MinGasPrice *hexnum `json:"minGasPrice"` + GasUsed *hexnum `json:"gasUsed"` + UnixTimestamp *hexnum `json:"timestamp"` + Transactions []*TransactionRes `json:"transactions"` + Uncles []*hexdata `json:"uncles"` + } + + ext.BlockNumber = b.BlockNumber + ext.BlockHash = b.BlockHash + ext.ParentHash = b.ParentHash + ext.Nonce = b.Nonce + ext.Sha3Uncles = b.Sha3Uncles + ext.LogsBloom = b.LogsBloom + ext.TransactionRoot = b.TransactionRoot + ext.StateRoot = b.StateRoot + ext.Miner = b.Miner + ext.Difficulty = b.Difficulty + ext.TotalDifficulty = b.TotalDifficulty + ext.Size = b.Size + ext.ExtraData = b.ExtraData + ext.GasLimit = b.GasLimit + ext.MinGasPrice = b.MinGasPrice + ext.GasUsed = b.GasUsed + ext.UnixTimestamp = b.UnixTimestamp + ext.Transactions = b.Transactions + ext.Uncles = b.Uncles + return json.Marshal(ext) + } else { + var ext struct { + BlockNumber *hexnum `json:"number"` + BlockHash *hexdata `json:"hash"` + ParentHash *hexdata `json:"parentHash"` + Nonce *hexdata `json:"nonce"` + Sha3Uncles *hexdata `json:"sha3Uncles"` + LogsBloom *hexdata `json:"logsBloom"` + TransactionRoot *hexdata `json:"transactionRoot"` + StateRoot *hexdata `json:"stateRoot"` + Miner *hexdata `json:"miner"` + Difficulty *hexnum `json:"difficulty"` + TotalDifficulty *hexnum `json:"totalDifficulty"` + Size *hexnum `json:"size"` + ExtraData *hexdata `json:"extraData"` + GasLimit *hexnum `json:"gasLimit"` + MinGasPrice *hexnum `json:"minGasPrice"` + GasUsed *hexnum `json:"gasUsed"` + UnixTimestamp *hexnum `json:"timestamp"` + Transactions []*hexdata `json:"transactions"` + Uncles []*hexdata `json:"uncles"` + } + + ext.BlockNumber = b.BlockNumber + ext.BlockHash = b.BlockHash + ext.ParentHash = b.ParentHash + ext.Nonce = b.Nonce + ext.Sha3Uncles = b.Sha3Uncles + ext.LogsBloom = b.LogsBloom + ext.TransactionRoot = b.TransactionRoot + ext.StateRoot = b.StateRoot + ext.Miner = b.Miner + ext.Difficulty = b.Difficulty + ext.TotalDifficulty = b.TotalDifficulty + ext.Size = b.Size + ext.ExtraData = b.ExtraData + ext.GasLimit = b.GasLimit + ext.MinGasPrice = b.MinGasPrice + ext.GasUsed = b.GasUsed + ext.UnixTimestamp = b.UnixTimestamp + ext.Transactions = make([]*hexdata, len(b.Transactions)) + for i, tx := range b.Transactions { + ext.Transactions[i] = tx.Hash + } + ext.Uncles = b.Uncles + return json.Marshal(ext) + } +} + func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { // TODO respect fullTx flag diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 704a381863..0f911c8869 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -21,6 +21,8 @@ const ( reNumNonZero = `"0x([1-9a-f][0-9a-f]{0,15})"` // non-zero required must not have left-padded zeros reNumOpt = `"0x([1-9a-f][0-9a-f]{0,15})|0"|null` // must not have left-padded zeros or null reData = `"0x[0-9a-f]*"` // can be "empty" + // reListHash = `[("\w":"0x[0-9a-f]{64}",?)*]` + // reListObj = `[("\w":(".+"|null),?)*]` ) func TestNewBlockRes(t *testing.T) { @@ -49,9 +51,70 @@ func TestNewBlockRes(t *testing.T) { // "minGasPrice": "0x", "gasUsed": reNum, "timestamp": reNum, + // "transactions": reListHash, + // "uncles": reListHash, } + to := common.HexToAddress("0x02") + amount := big.NewInt(1) + gasAmount := big.NewInt(1) + gasPrice := big.NewInt(1) + data := []byte{1, 2, 3} + tx := types.NewTransactionMessage(to, amount, gasAmount, gasPrice, data) + v := NewBlockRes(block, false) + v.Transactions = make([]*TransactionRes, 1) + v.Transactions[0] = NewTransactionRes(tx) + j, _ := json.Marshal(v) + + for k, re := range tests { + match, _ := regexp.MatchString(fmt.Sprintf(`{.*"%s":%s.*}`, k, re), string(j)) + if !match { + t.Error(fmt.Sprintf("%s output json does not match format %s. Got %s", k, re, j)) + } + } +} + +func TestNewBlockResWithTrans(t *testing.T) { + parentHash := common.HexToHash("0x01") + coinbase := common.HexToAddress("0x01") + root := common.HexToHash("0x01") + difficulty := common.Big1 + nonce := uint64(1) + extra := "" + block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra) + tests := map[string]string{ + "number": reNum, + "hash": reHash, + "parentHash": reHash, + "nonce": reData, + "sha3Uncles": reHash, + "logsBloom": reData, + "transactionRoot": reHash, + "stateRoot": reHash, + "miner": reAddress, + "difficulty": `"0x1"`, + "totalDifficulty": reNum, + "size": reNumNonZero, + "extraData": reData, + "gasLimit": reNum, + // "minGasPrice": "0x", + "gasUsed": reNum, + "timestamp": reNum, + // "transactions": `[{.*}]`, + // "uncles": reListHash, + } + + to := common.HexToAddress("0x02") + amount := big.NewInt(1) + gasAmount := big.NewInt(1) + gasPrice := big.NewInt(1) + data := []byte{1, 2, 3} + tx := types.NewTransactionMessage(to, amount, gasAmount, gasPrice, data) + + v := NewBlockRes(block, true) + v.Transactions = make([]*TransactionRes, 1) + v.Transactions[0] = NewTransactionRes(tx) j, _ := json.Marshal(v) for k, re := range tests { From 1045015a3c8df048d80c0f66598a8a8fa09b2f71 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 17:48:53 +0200 Subject: [PATCH 08/24] Update nonce field --- rpc/responses.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/responses.go b/rpc/responses.go index 172a0902fd..bf4f518aaf 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -136,7 +136,7 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { res.BlockNumber = newHexNum(block.Number()) res.BlockHash = newHexData(block.Hash()) res.ParentHash = newHexData(block.ParentHash()) - res.Nonce = newHexData(block.Header().Nonce) + res.Nonce = newHexData(block.Nonce()) res.Sha3Uncles = newHexData(block.Header().UncleHash) res.LogsBloom = newHexData(block.Bloom()) res.TransactionRoot = newHexData(block.Header().TxHash) From eac4d582d7bfe427d4bf5c738e38f1f9861cd30a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 17:49:22 +0200 Subject: [PATCH 09/24] Patches --- rpc/types.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rpc/types.go b/rpc/types.go index 549268cce3..2d0cf53be6 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -47,6 +47,7 @@ func newHexData(input interface{}) *hexdata { if input == nil { d.data = nil + return d } switch input := input.(type) { case []byte: @@ -57,8 +58,8 @@ func newHexData(input interface{}) *hexdata { d.data = input.Bytes() case common.Address: d.data = input.Bytes() - case *common.Address: - d.data = input.Bytes() + // case *common.Address: + // d.data = input.Bytes() case *big.Int: d.data = input.Bytes() case int64: From 5d8be9c30d1f2334ecac0ddb92d82a878b35c51c Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 1 Apr 2015 23:08:00 +0200 Subject: [PATCH 10/24] Fixed decoding for uint64 into bytes --- rpc/types.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rpc/types.go b/rpc/types.go index 2d0cf53be6..75c4ba85f9 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -17,6 +17,7 @@ package rpc import ( + "encoding/binary" "encoding/json" "fmt" "math/big" @@ -65,7 +66,9 @@ func newHexData(input interface{}) *hexdata { case int64: d.data = big.NewInt(input).Bytes() case uint64: - d.data = big.NewInt(int64(input)).Bytes() + buff := make([]byte, 8) + binary.BigEndian.PutUint64(buff, input) + d.data = buff case int: d.data = big.NewInt(int64(input)).Bytes() case uint: From c71ca1a089cc963848c5eee7391a53168adf188c Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 11:32:50 +0200 Subject: [PATCH 11/24] Better nil handling --- rpc/types.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/rpc/types.go b/rpc/types.go index 75c4ba85f9..53a2a08061 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -24,10 +24,12 @@ import ( "strings" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" ) type hexdata struct { - data []byte + data []byte + isNil bool } func (d *hexdata) String() string { @@ -35,6 +37,9 @@ func (d *hexdata) String() string { } func (d *hexdata) MarshalJSON() ([]byte, error) { + if d.isNil { + return json.Marshal(nil) + } return json.Marshal(d.String()) } @@ -56,11 +61,19 @@ func newHexData(input interface{}) *hexdata { case common.Hash: d.data = input.Bytes() case *common.Hash: - d.data = input.Bytes() + if input == nil { + d.isNil = true + } else { + d.data = input.Bytes() + } case common.Address: d.data = input.Bytes() - // case *common.Address: - // d.data = input.Bytes() + case *common.Address: + if input == nil { + d.isNil = true + } else { + d.data = input.Bytes() + } case *big.Int: d.data = input.Bytes() case int64: @@ -83,7 +96,8 @@ func newHexData(input interface{}) *hexdata { } type hexnum struct { - data []byte + data []byte + isNil bool } func (d *hexnum) String() string { @@ -99,6 +113,9 @@ func (d *hexnum) String() string { } func (d *hexnum) MarshalJSON() ([]byte, error) { + if d.isNil { + return json.Marshal(nil) + } return json.Marshal(d.String()) } From 85ebbc9aa5e4c8902b94847dbeb78f26255eb0aa Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 11:57:26 +0200 Subject: [PATCH 12/24] Default BlockNumber to -1 when missing --- rpc/args.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rpc/args.go b/rpc/args.go index dd013147d9..220daf9608 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -233,6 +233,8 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeightFromJson(obj[1], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil @@ -320,6 +322,8 @@ func (args *CallArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeightFromJson(obj[1], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil @@ -350,6 +354,8 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil @@ -387,6 +393,8 @@ func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeight(obj[2], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil @@ -417,6 +425,8 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil @@ -447,6 +457,8 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil @@ -477,6 +489,8 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) { if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } + } else { + args.BlockNumber = -1 } return nil From f89baa73e5cfc0e93f32e36f5c3838cd808e6f46 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 12:30:22 +0200 Subject: [PATCH 13/24] transactionRoot -> transactionsRoot --- rpc/responses.go | 6 ++--- rpc/responses_test.go | 56 +++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/rpc/responses.go b/rpc/responses.go index bf4f518aaf..f1dc344db2 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -16,7 +16,7 @@ type BlockRes struct { Nonce *hexdata `json:"nonce"` Sha3Uncles *hexdata `json:"sha3Uncles"` LogsBloom *hexdata `json:"logsBloom"` - TransactionRoot *hexdata `json:"transactionRoot"` + TransactionRoot *hexdata `json:"transactionsRoot"` StateRoot *hexdata `json:"stateRoot"` Miner *hexdata `json:"miner"` Difficulty *hexnum `json:"difficulty"` @@ -40,7 +40,7 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { Nonce *hexdata `json:"nonce"` Sha3Uncles *hexdata `json:"sha3Uncles"` LogsBloom *hexdata `json:"logsBloom"` - TransactionRoot *hexdata `json:"transactionRoot"` + TransactionRoot *hexdata `json:"transactionsRoot"` StateRoot *hexdata `json:"stateRoot"` Miner *hexdata `json:"miner"` Difficulty *hexnum `json:"difficulty"` @@ -83,7 +83,7 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { Nonce *hexdata `json:"nonce"` Sha3Uncles *hexdata `json:"sha3Uncles"` LogsBloom *hexdata `json:"logsBloom"` - TransactionRoot *hexdata `json:"transactionRoot"` + TransactionRoot *hexdata `json:"transactionsRoot"` StateRoot *hexdata `json:"stateRoot"` Miner *hexdata `json:"miner"` Difficulty *hexnum `json:"difficulty"` diff --git a/rpc/responses_test.go b/rpc/responses_test.go index 0f911c8869..2ec6d9d15f 100644 --- a/rpc/responses_test.go +++ b/rpc/responses_test.go @@ -34,20 +34,20 @@ func TestNewBlockRes(t *testing.T) { extra := "" block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra) tests := map[string]string{ - "number": reNum, - "hash": reHash, - "parentHash": reHash, - "nonce": reData, - "sha3Uncles": reHash, - "logsBloom": reData, - "transactionRoot": reHash, - "stateRoot": reHash, - "miner": reAddress, - "difficulty": `"0x1"`, - "totalDifficulty": reNum, - "size": reNumNonZero, - "extraData": reData, - "gasLimit": reNum, + "number": reNum, + "hash": reHash, + "parentHash": reHash, + "nonce": reData, + "sha3Uncles": reHash, + "logsBloom": reData, + "transactionsRoot": reHash, + "stateRoot": reHash, + "miner": reAddress, + "difficulty": `"0x1"`, + "totalDifficulty": reNum, + "size": reNumNonZero, + "extraData": reData, + "gasLimit": reNum, // "minGasPrice": "0x", "gasUsed": reNum, "timestamp": reNum, @@ -84,20 +84,20 @@ func TestNewBlockResWithTrans(t *testing.T) { extra := "" block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra) tests := map[string]string{ - "number": reNum, - "hash": reHash, - "parentHash": reHash, - "nonce": reData, - "sha3Uncles": reHash, - "logsBloom": reData, - "transactionRoot": reHash, - "stateRoot": reHash, - "miner": reAddress, - "difficulty": `"0x1"`, - "totalDifficulty": reNum, - "size": reNumNonZero, - "extraData": reData, - "gasLimit": reNum, + "number": reNum, + "hash": reHash, + "parentHash": reHash, + "nonce": reData, + "sha3Uncles": reHash, + "logsBloom": reData, + "transactionsRoot": reHash, + "stateRoot": reHash, + "miner": reAddress, + "difficulty": `"0x1"`, + "totalDifficulty": reNum, + "size": reNumNonZero, + "extraData": reData, + "gasLimit": reNum, // "minGasPrice": "0x", "gasUsed": reNum, "timestamp": reNum, From cc45b4d8b536a53b59696389e3609c2f633d07a7 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 12:30:42 +0200 Subject: [PATCH 14/24] Trim left only, not right --- rpc/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/types.go b/rpc/types.go index 53a2a08061..83542c83db 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -104,7 +104,7 @@ func (d *hexnum) String() string { // Get hex string from bytes out := common.Bytes2Hex(d.data) // Trim leading 0s - out = strings.Trim(out, "0") + out = strings.TrimLeft(out, "0") // Output "0x0" when value is 0 if len(out) == 0 { out = "0" From b10e33c04011c9b9f52841ed09de0b8d4cb5bc6a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 12:31:10 +0200 Subject: [PATCH 15/24] More types supported --- rpc/types.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rpc/types.go b/rpc/types.go index 83542c83db..205b58b0a2 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -74,6 +74,14 @@ func newHexData(input interface{}) *hexdata { } else { d.data = input.Bytes() } + case types.Bloom: + d.data = input.Bytes() + case *types.Bloom: + if input == nil { + d.isNil = true + } else { + d.data = input.Bytes() + } case *big.Int: d.data = input.Bytes() case int64: @@ -86,6 +94,18 @@ func newHexData(input interface{}) *hexdata { d.data = big.NewInt(int64(input)).Bytes() case uint: d.data = big.NewInt(int64(input)).Bytes() + case int8: + d.data = big.NewInt(int64(input)).Bytes() + case uint8: + d.data = big.NewInt(int64(input)).Bytes() + case int16: + d.data = big.NewInt(int64(input)).Bytes() + case uint16: + d.data = big.NewInt(int64(input)).Bytes() + case int32: + d.data = big.NewInt(int64(input)).Bytes() + case uint32: + d.data = big.NewInt(int64(input)).Bytes() case string: // hexstring d.data = common.Big(input).Bytes() default: From edfd2757d9d958dca936fe38efe350cf60b2c3ce Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 12:52:25 +0200 Subject: [PATCH 16/24] Better decoding of uint* --- rpc/types.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rpc/types.go b/rpc/types.go index 205b58b0a2..0789a99017 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -101,11 +101,15 @@ func newHexData(input interface{}) *hexdata { case int16: d.data = big.NewInt(int64(input)).Bytes() case uint16: - d.data = big.NewInt(int64(input)).Bytes() + buff := make([]byte, 8) + binary.BigEndian.PutUint16(buff, input) + d.data = buff case int32: d.data = big.NewInt(int64(input)).Bytes() case uint32: - d.data = big.NewInt(int64(input)).Bytes() + buff := make([]byte, 8) + binary.BigEndian.PutUint32(buff, input) + d.data = buff case string: // hexstring d.data = common.Big(input).Bytes() default: From 585aec127cb231d91998b33564b2294659f56ac1 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 12:56:36 +0200 Subject: [PATCH 17/24] Don't ignore user-specified "include tx" param --- rpc/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 660bb32513..940b80758a 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -179,7 +179,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } block := api.xeth().EthBlockByHash(args.BlockHash) - br := NewBlockRes(block, true) + br := NewBlockRes(block, args.IncludeTxs) *reply = br case "eth_getBlockByNumber": @@ -189,7 +189,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } block := api.xeth().EthBlockByNumber(args.BlockNumber) - br := NewBlockRes(block, true) + br := NewBlockRes(block, args.IncludeTxs) *reply = br case "eth_getTransactionByHash": From 2efb89d5440a9e43bec75b5f59032a0ff0cdc3cc Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:04:58 +0200 Subject: [PATCH 18/24] Guard for nil *big.Int --- rpc/types.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rpc/types.go b/rpc/types.go index 0789a99017..806c9c8a43 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -83,7 +83,11 @@ func newHexData(input interface{}) *hexdata { d.data = input.Bytes() } case *big.Int: - d.data = input.Bytes() + if input == nil { + d.isNil = true + } else { + d.data = input.Bytes() + } case int64: d.data = big.NewInt(input).Bytes() case uint64: From 14c14fd61f72bfa8c1494fa799a4f2e2eb14f4c1 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:05:13 +0200 Subject: [PATCH 19/24] Output empty block as nil --- rpc/responses.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/responses.go b/rpc/responses.go index f1dc344db2..3d1687cb68 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -128,7 +128,7 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { // TODO respect fullTx flag if block == nil { - return &BlockRes{} + return nil } res := new(BlockRes) From e402e1dc2e72df2a433b984caeaba771085b2b66 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:17:55 +0200 Subject: [PATCH 20/24] New args types with stricter checking --- rpc/api.go | 12 +++---- rpc/args.go | 88 ++++++++++++++++++++++++++++++++++-------------- rpc/args_test.go | 12 ++++++- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 940b80758a..478ca87521 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -108,15 +108,15 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err count := api.xethAtStateNum(args.BlockNumber).TxCountAt(args.Address) *reply = common.ToHex(big.NewInt(int64(count)).Bytes()) case "eth_getBlockTransactionCountByHash": - args := new(GetBlockByHashArgs) + args := new(HashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } - block := NewBlockRes(api.xeth().EthBlockByHash(args.BlockHash), false) + block := NewBlockRes(api.xeth().EthBlockByHash(args.Hash), false) *reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes()) case "eth_getBlockTransactionCountByNumber": - args := new(GetBlockByNumberArgs) + args := new(BlockNumArg) if err := json.Unmarshal(req.Params, &args); err != nil { return err } @@ -124,16 +124,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := NewBlockRes(api.xeth().EthBlockByNumber(args.BlockNumber), false) *reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes()) case "eth_getUncleCountByBlockHash": - args := new(GetBlockByHashArgs) + args := new(HashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } - block := api.xeth().EthBlockByHash(args.BlockHash) + block := api.xeth().EthBlockByHash(args.Hash) br := NewBlockRes(block, false) *reply = common.ToHex(big.NewInt(int64(len(br.Uncles))).Bytes()) case "eth_getUncleCountByBlockNumber": - args := new(GetBlockByNumberArgs) + args := new(BlockNumArg) if err := json.Unmarshal(req.Params, &args); err != nil { return err } diff --git a/rpc/args.go b/rpc/args.go index 220daf9608..b43c465c05 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -108,8 +108,8 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) { return NewDecodeParamError(err.Error()) } - if len(obj) < 1 { - return NewInsufficientParamsError(len(obj), 1) + if len(obj) < 2 { + return NewInsufficientParamsError(len(obj), 2) } argstr, ok := obj[0].(string) @@ -118,9 +118,7 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) { } args.BlockHash = argstr - if len(obj) > 1 { - args.IncludeTxs = obj[1].(bool) - } + args.IncludeTxs = obj[1].(bool) return nil } @@ -136,8 +134,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) { return NewDecodeParamError(err.Error()) } - if len(obj) < 1 { - return NewInsufficientParamsError(len(obj), 1) + if len(obj) < 2 { + return NewInsufficientParamsError(len(obj), 2) } if v, ok := obj[0].(float64); ok { @@ -148,9 +146,7 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) { return NewInvalidTypeError("blockNumber", "not a number or string") } - if len(obj) > 1 { - args.IncludeTxs = obj[1].(bool) - } + args.IncludeTxs = obj[1].(bool) return nil } @@ -496,6 +492,27 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) { return nil } +type BlockNumArg struct { + BlockNumber int64 +} + +func (args *BlockNumArg) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return NewDecodeParamError(err.Error()) + } + + if len(obj) < 1 { + return NewInsufficientParamsError(len(obj), 1) + } + + if err := blockHeight(obj[0], &args.BlockNumber); err != nil { + return err + } + + return nil +} + type BlockNumIndexArgs struct { BlockNumber int64 Index int64 @@ -507,21 +524,42 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) { return NewDecodeParamError(err.Error()) } - if len(obj) < 1 { - return NewInsufficientParamsError(len(obj), 1) + if len(obj) < 2 { + return NewInsufficientParamsError(len(obj), 2) } if err := blockHeight(obj[0], &args.BlockNumber); err != nil { return err } - if len(obj) > 1 { - arg1, ok := obj[1].(string) - if !ok { - return NewInvalidTypeError("index", "not a string") - } - args.Index = common.Big(arg1).Int64() + arg1, ok := obj[1].(string) + if !ok { + return NewInvalidTypeError("index", "not a string") } + args.Index = common.Big(arg1).Int64() + + return nil +} + +type HashArgs struct { + Hash string +} + +func (args *HashArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return NewDecodeParamError(err.Error()) + } + + if len(obj) < 1 { + return NewInsufficientParamsError(len(obj), 1) + } + + arg0, ok := obj[0].(string) + if !ok { + return NewInvalidTypeError("hash", "not a string") + } + args.Hash = arg0 return nil } @@ -537,8 +575,8 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) { return NewDecodeParamError(err.Error()) } - if len(obj) < 1 { - return NewInsufficientParamsError(len(obj), 1) + if len(obj) < 2 { + return NewInsufficientParamsError(len(obj), 2) } arg0, ok := obj[0].(string) @@ -547,13 +585,11 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) { } args.Hash = arg0 - if len(obj) > 1 { - arg1, ok := obj[1].(string) - if !ok { - return NewInvalidTypeError("index", "not a string") - } - args.Index = common.Big(arg1).Int64() + arg1, ok := obj[1].(string) + if !ok { + return NewInvalidTypeError("index", "not a string") } + args.Index = common.Big(arg1).Int64() return nil } diff --git a/rpc/args_test.go b/rpc/args_test.go index 3635882c00..f00899b790 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -225,7 +225,7 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) { input := `[8]` args := new(GetBlockByHashArgs) - str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args)) + str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args)) if len(str) > 0 { t.Error(str) } @@ -281,6 +281,16 @@ func TestGetBlockByNumberEmpty(t *testing.T) { } } +func TestGetBlockByNumberShort(t *testing.T) { + input := `["0xbbb"]` + + args := new(GetBlockByNumberArgs) + str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args)) + if len(str) > 0 { + t.Error(str) + } +} + func TestGetBlockByNumberBool(t *testing.T) { input := `[true, true]` From b86450aaae361ef183928b2de53e3724d3e174a8 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:27:58 +0200 Subject: [PATCH 21/24] Guard from nil pointers --- rpc/api.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rpc/api.go b/rpc/api.go index 478ca87521..20299bef1e 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -238,6 +238,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } br := NewBlockRes(api.xeth().EthBlockByHash(args.Hash), false) + if br == nil { + *reply = nil + return nil + } if args.Index >= int64(len(br.Uncles)) || args.Index < 0 { return NewValidationError("Index", "does not exist") @@ -256,6 +260,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByNumber(args.BlockNumber) v := NewBlockRes(block, true) + if v == nil { + *reply = nil + return nil + } + if args.Index >= int64(len(v.Uncles)) || args.Index < 0 { return NewValidationError("Index", "does not exist") } From 81de8ed0912f767b2e3104aaad5c7f31920aaf2a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:38:12 +0200 Subject: [PATCH 22/24] Format code as hexdata --- rpc/api.go | 3 ++- xeth/xeth.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/rpc/api.go b/rpc/api.go index 20299bef1e..b554dc16b4 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -146,7 +146,8 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err if err := json.Unmarshal(req.Params, &args); err != nil { return err } - *reply = api.xethAtStateNum(args.BlockNumber).CodeAt(args.Address) + v := api.xethAtStateNum(args.BlockNumber).CodeAtBytes(args.Address) + *reply = newHexData(v) case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { diff --git a/xeth/xeth.go b/xeth/xeth.go index 5936c0fb2e..1b6b1ccd0e 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -325,6 +325,10 @@ func (self *XEth) CodeAt(address string) string { return common.ToHex(self.State().SafeGet(address).Code()) } +func (self *XEth) CodeAtBytes(address string) []byte { + return self.State().SafeGet(address).Code() +} + func (self *XEth) IsContract(address string) bool { return len(self.State().SafeGet(address).Code()) > 0 } From 015453f5b3f5b78ac8f432aed2247c839a6e5049 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 13:55:53 +0200 Subject: [PATCH 23/24] Default Value to 0 for NewTxArgs --- rpc/args.go | 2 +- rpc/args_test.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/rpc/args.go b/rpc/args.go index b43c465c05..df57e69c4c 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -198,7 +198,7 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { var num int64 if ext.Value == nil { - return NewValidationError("value", "is required") + num = 0 } else { if err := numString(ext.Value, &num); err != nil { return err diff --git a/rpc/args_test.go b/rpc/args_test.go index f00899b790..8c1e8c4780 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -500,12 +500,18 @@ func TestNewTxArgsValueMissing(t *testing.T) { "gasPrice": "0x9184e72a000", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" }]` + expected := new(NewTxArgs) + expected.Value = big.NewInt(0) args := new(NewTxArgs) - str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) - if len(str) > 0 { - t.Error(str) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) } + + if bytes.Compare(expected.Value.Bytes(), args.Value.Bytes()) != 0 { + t.Errorf("Value shoud be %v but is %v", expected.Value, args.Value) + } + } func TestNewTxArgsEmpty(t *testing.T) { From b4eef59b6f9631d22fdf62a2b1a40fe05209fccd Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 14:05:14 +0200 Subject: [PATCH 24/24] No longer require gas & gas price in transactions Defaults to 0, which is then set to default values in XEth --- rpc/args.go | 4 ++-- rpc/args_test.go | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/rpc/args.go b/rpc/args.go index df57e69c4c..70618a01a4 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -207,7 +207,7 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { args.Value = big.NewInt(num) if ext.Gas == nil { - return NewValidationError("gas", "is required") + num = 0 } else { if err := numString(ext.Gas, &num); err != nil { return err @@ -216,7 +216,7 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { args.Gas = big.NewInt(num) if ext.GasPrice == nil { - return NewValidationError("gasprice", "is required") + num = 0 } else { if err := numString(ext.GasPrice, &num); err != nil { return err diff --git a/rpc/args_test.go b/rpc/args_test.go index 8c1e8c4780..902f8013e4 100644 --- a/rpc/args_test.go +++ b/rpc/args_test.go @@ -468,11 +468,16 @@ func TestNewTxArgsGasMissing(t *testing.T) { "value": "0x9184e72a000", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" }]` + expected := new(NewTxArgs) + expected.Gas = big.NewInt(0) args := new(NewTxArgs) - str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) - if len(str) > 0 { - t.Error(str) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) + } + + if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 { + t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas) } } @@ -484,12 +489,18 @@ func TestNewTxArgsBlockGaspriceMissing(t *testing.T) { "value": "0x9184e72a000", "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" }]` + expected := new(NewTxArgs) + expected.GasPrice = big.NewInt(0) args := new(NewTxArgs) - str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) - if len(str) > 0 { - t.Error(str) + if err := json.Unmarshal([]byte(input), &args); err != nil { + t.Error(err) } + + if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 { + t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice) + } + } func TestNewTxArgsValueMissing(t *testing.T) {