github.com/Inphi/go-ethereum@v1.9.7/core/types/bloom9_test.go (about)

     1  // Copyright 2014 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 types
    18  
    19  import (
    20  	"math/big"
    21  	"testing"
    22  )
    23  
    24  func TestBloom(t *testing.T) {
    25  	positive := []string{
    26  		"testtest",
    27  		"test",
    28  		"hallo",
    29  		"other",
    30  	}
    31  	negative := []string{
    32  		"tes",
    33  		"lo",
    34  	}
    35  
    36  	var bloom Bloom
    37  	for _, data := range positive {
    38  		bloom.Add(new(big.Int).SetBytes([]byte(data)))
    39  	}
    40  
    41  	for _, data := range positive {
    42  		if !bloom.TestBytes([]byte(data)) {
    43  			t.Error("expected", data, "to test true")
    44  		}
    45  	}
    46  	for _, data := range negative {
    47  		if bloom.TestBytes([]byte(data)) {
    48  			t.Error("did not expect", data, "to test true")
    49  		}
    50  	}
    51  }
    52  
    53  /*
    54  import (
    55  	"testing"
    56  
    57  	"github.com/ethereum/go-ethereum/core/state"
    58  )
    59  
    60  func TestBloom9(t *testing.T) {
    61  	testCase := []byte("testtest")
    62  	bin := LogsBloom([]state.Log{
    63  		{testCase, [][]byte{[]byte("hellohello")}, nil},
    64  	}).Bytes()
    65  	res := BloomLookup(bin, testCase)
    66  
    67  	if !res {
    68  		t.Errorf("Bloom lookup failed")
    69  	}
    70  }
    71  
    72  
    73  func TestAddress(t *testing.T) {
    74  	block := &Block{}
    75  	block.Coinbase = common.Hex2Bytes("22341ae42d6dd7384bc8584e50419ea3ac75b83f")
    76  	fmt.Printf("%x\n", crypto.Keccak256(block.Coinbase))
    77  
    78  	bin := CreateBloom(block)
    79  	fmt.Printf("bin = %x\n", common.LeftPadBytes(bin, 64))
    80  }
    81  */