github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/crypto/secp256k1/curve_test.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser 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  // The go-ethereum library 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 Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package secp256k1
    18  
    19  import (
    20  	"bytes"
    21  	"encoding/hex"
    22  	"math/big"
    23  	"testing"
    24  )
    25  
    26  func TestReadBits(t *testing.T) {
    27  	check := func(input string) {
    28  		want, _ := hex.DecodeString(input)
    29  		int, _ := new(big.Int).SetString(input, 16)
    30  		buf := make([]byte, len(want))
    31  		readBits(buf, int)
    32  		if !bytes.Equal(buf, want) {
    33  			t.Errorf("have: %x\nwant: %x", buf, want)
    34  		}
    35  	}
    36  	check("000000000000000000000000000000000000000000000000000000FEFCF3F8F0")
    37  	check("0000000000012345000000000000000000000000000000000000FEFCF3F8F0")
    38  	check("18F8F8F1000111000110011100222004330052300000000000000000FEFCF3F8F0")
    39  }