Increased test coverage for args

This commit is contained in:
Taylor Gerring 2015-04-04 11:58:23 -05:00
parent 435378e953
commit 5c988c8ea0
1 changed files with 214 additions and 0 deletions

View File

@ -8,6 +8,61 @@ import (
"testing"
)
func TestBlockheightInvalidString(t *testing.T) {
v := "foo"
var num int64
str := ExpectInvalidTypeError(blockHeight(v, &num))
if len(str) > 0 {
t.Error(str)
}
}
func TestBlockheightEarliest(t *testing.T) {
v := "earliest"
e := int64(0)
var num int64
err := blockHeight(v, &num)
if err != nil {
t.Error(err)
}
if num != e {
t.Errorf("Expected %s but got %s", e, num)
}
}
func TestBlockheightLatest(t *testing.T) {
v := "latest"
e := int64(-1)
var num int64
err := blockHeight(v, &num)
if err != nil {
t.Error(err)
}
if num != e {
t.Errorf("Expected %s but got %s", e, num)
}
}
func TestBlockheightPending(t *testing.T) {
v := "pending"
e := int64(-2)
var num int64
err := blockHeight(v, &num)
if err != nil {
t.Error(err)
}
if num != e {
t.Errorf("Expected %s but got %s", e, num)
}
}
func ExpectValidationError(err error) string {
var str string
switch err.(type) {
@ -121,6 +176,26 @@ func TestGetBalanceArgs(t *testing.T) {
}
}
func TestGetBalanceArgsBlocknumMissing(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
expected := new(GetBalanceArgs)
expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected.BlockNumber = -1
args := new(GetBalanceArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if args.Address != expected.Address {
t.Errorf("Address should be %v but is %v", expected.Address, args.Address)
}
if args.BlockNumber != expected.BlockNumber {
t.Errorf("BlockNumber should be %v but is %v", expected.BlockNumber, args.BlockNumber)
}
}
func TestGetBalanceArgsLatest(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
expected := new(GetBalanceArgs)
@ -231,6 +306,16 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
}
}
func TestGetBlockByHashArgsHashBool(t *testing.T) {
input := `[false, true]`
args := new(GetBlockByHashArgs)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestGetBlockByNumberArgsBlockNum(t *testing.T) {
input := `[436, false]`
expected := new(GetBlockByNumberArgs)
@ -850,6 +935,26 @@ func TestGetStorageArgs(t *testing.T) {
}
}
func TestGetStorageArgsMissingBlocknum(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
expected := new(GetStorageArgs)
expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected.BlockNumber = -1
args := new(GetStorageArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if expected.Address != args.Address {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
if expected.BlockNumber != args.BlockNumber {
t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
}
}
func TestGetStorageInvalidArgs(t *testing.T) {
input := `{}`
@ -915,6 +1020,31 @@ func TestGetStorageAtArgs(t *testing.T) {
}
}
func TestGetStorageAtArgsMissingBlocknum(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0"]`
expected := new(GetStorageAtArgs)
expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected.Key = "0x0"
expected.BlockNumber = -1
args := new(GetStorageAtArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if expected.Address != args.Address {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
if expected.Key != args.Key {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
if expected.BlockNumber != args.BlockNumber {
t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
}
}
func TestGetStorageAtEmptyArgs(t *testing.T) {
input := `[]`
@ -1015,6 +1145,26 @@ func TestGetTxCountAddressNotString(t *testing.T) {
}
}
func TestGetTxCountBlockheightMissing(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
expected := new(GetTxCountArgs)
expected.Address = "0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected.BlockNumber = -1
args := new(GetTxCountArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if expected.Address != args.Address {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
if expected.BlockNumber != args.BlockNumber {
t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
}
}
func TestGetTxCountBlockheightInvalid(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
@ -1045,6 +1195,26 @@ func TestGetDataArgs(t *testing.T) {
}
}
func TestGetDataArgsBlocknumMissing(t *testing.T) {
input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"]`
expected := new(GetDataArgs)
expected.Address = "0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
expected.BlockNumber = -1
args := new(GetDataArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if expected.Address != args.Address {
t.Errorf("Address shoud be %#v but is %#v", expected.Address, args.Address)
}
if expected.BlockNumber != args.BlockNumber {
t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
}
}
func TestGetDataArgsEmpty(t *testing.T) {
input := `[]`
@ -1995,6 +2165,50 @@ func TestWhisperIdentityArgsInt(t *testing.T) {
}
}
func TestBlockNumArgs(t *testing.T) {
input := `["0x29a"]`
expected := new(BlockNumIndexArgs)
expected.BlockNumber = 666
args := new(BlockNumArg)
if err := json.Unmarshal([]byte(input), &args); err != nil {
t.Error(err)
}
if expected.BlockNumber != args.BlockNumber {
t.Errorf("BlockNumber shoud be %#v but is %#v", expected.BlockNumber, args.BlockNumber)
}
}
func TestBlockNumArgsInvalid(t *testing.T) {
input := `{}`
args := new(BlockNumArg)
str := ExpectDecodeParamError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestBlockNumArgsEmpty(t *testing.T) {
input := `[]`
args := new(BlockNumArg)
str := ExpectInsufficientParamsError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestBlockNumArgsBool(t *testing.T) {
input := `[true]`
args := new(BlockNumArg)
str := ExpectInvalidTypeError(json.Unmarshal([]byte(input), &args))
if len(str) > 0 {
t.Error(str)
}
}
func TestBlockNumIndexArgs(t *testing.T) {
input := `["0x29a", "0x0"]`
expected := new(BlockNumIndexArgs)