signed_data_internal_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. //
  17. package core
  18. import (
  19. "math/big"
  20. "testing"
  21. )
  22. func TestParseInteger(t *testing.T) {
  23. for i, tt := range []struct {
  24. t string
  25. v interface{}
  26. exp *big.Int
  27. }{
  28. {"uint32", "-123", nil},
  29. {"int32", "-123", big.NewInt(-123)},
  30. {"uint32", "0xff", big.NewInt(0xff)},
  31. {"int8", "0xffff", nil},
  32. } {
  33. res, err := parseInteger(tt.t, tt.v)
  34. if tt.exp == nil && res == nil {
  35. continue
  36. }
  37. if tt.exp == nil && res != nil {
  38. t.Errorf("test %d, got %v, expected nil", i, res)
  39. continue
  40. }
  41. if tt.exp != nil && res == nil {
  42. t.Errorf("test %d, got '%v', expected %v", i, err, tt.exp)
  43. continue
  44. }
  45. if tt.exp.Cmp(res) != 0 {
  46. t.Errorf("test %d, got %v expected %v", i, res, tt.exp)
  47. }
  48. }
  49. }