github.com/bloxroute-labs/bor@v0.1.4/signer/core/signed_data_internal_test.go (about)

     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  
    19  import (
    20  	"math/big"
    21  	"testing"
    22  )
    23  
    24  func TestParseInteger(t *testing.T) {
    25  	for i, tt := range []struct {
    26  		t   string
    27  		v   interface{}
    28  		exp *big.Int
    29  	}{
    30  		{"uint32", "-123", nil},
    31  		{"int32", "-123", big.NewInt(-123)},
    32  		{"uint32", "0xff", big.NewInt(0xff)},
    33  		{"int8", "0xffff", nil},
    34  	} {
    35  		res, err := parseInteger(tt.t, tt.v)
    36  		if tt.exp == nil && res == nil {
    37  			continue
    38  		}
    39  		if tt.exp == nil && res != nil {
    40  			t.Errorf("test %d, got %v, expected nil", i, res)
    41  			continue
    42  		}
    43  		if tt.exp != nil && res == nil {
    44  			t.Errorf("test %d, got '%v', expected %v", i, err, tt.exp)
    45  			continue
    46  		}
    47  		if tt.exp.Cmp(res) != 0 {
    48  			t.Errorf("test %d, got %v expected %v", i, res, tt.exp)
    49  		}
    50  	}
    51  }