2019-06-03 09:56:05 -05:00
|
|
|
// Copyright 2019 The go-ethereum Authors
|
2019-07-22 04:17:27 -05:00
|
|
|
// This file is part of the go-ethereum library.
|
2019-06-03 09:56:05 -05:00
|
|
|
//
|
2019-07-22 04:17:27 -05:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
2019-06-03 09:56:05 -05:00
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2019-07-22 04:17:27 -05:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2019-06-03 09:56:05 -05:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-07-22 04:17:27 -05:00
|
|
|
// GNU Lesser General Public License for more details.
|
2019-06-03 09:56:05 -05:00
|
|
|
//
|
2019-07-22 04:17:27 -05:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-06-03 09:56:05 -05:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseInteger(t *testing.T) {
|
|
|
|
for i, tt := range []struct {
|
|
|
|
t string
|
|
|
|
v interface{}
|
|
|
|
exp *big.Int
|
|
|
|
}{
|
|
|
|
{"uint32", "-123", nil},
|
|
|
|
{"int32", "-123", big.NewInt(-123)},
|
|
|
|
{"uint32", "0xff", big.NewInt(0xff)},
|
|
|
|
{"int8", "0xffff", nil},
|
|
|
|
} {
|
|
|
|
res, err := parseInteger(tt.t, tt.v)
|
|
|
|
if tt.exp == nil && res == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if tt.exp == nil && res != nil {
|
|
|
|
t.Errorf("test %d, got %v, expected nil", i, res)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if tt.exp != nil && res == nil {
|
|
|
|
t.Errorf("test %d, got '%v', expected %v", i, err, tt.exp)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if tt.exp.Cmp(res) != 0 {
|
|
|
|
t.Errorf("test %d, got %v expected %v", i, res, tt.exp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|