Default Value to 0 for NewTxArgs

This commit is contained in:
Taylor Gerring 2015-04-02 13:55:53 +02:00
parent 118ad22ee5
commit 015453f5b3
2 changed files with 10 additions and 4 deletions

View File

@ -198,7 +198,7 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
var num int64 var num int64
if ext.Value == nil { if ext.Value == nil {
return NewValidationError("value", "is required") num = 0
} else { } else {
if err := numString(ext.Value, &num); err != nil { if err := numString(ext.Value, &num); err != nil {
return err return err

View File

@ -500,12 +500,18 @@ func TestNewTxArgsValueMissing(t *testing.T) {
"gasPrice": "0x9184e72a000", "gasPrice": "0x9184e72a000",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}]` }]`
expected := new(NewTxArgs)
expected.Value = big.NewInt(0)
args := new(NewTxArgs) args := new(NewTxArgs)
str := ExpectValidationError(json.Unmarshal([]byte(input), &args)) if err := json.Unmarshal([]byte(input), &args); err != nil {
if len(str) > 0 { t.Error(err)
t.Error(str)
} }
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) { func TestNewTxArgsEmpty(t *testing.T) {