22c91fa80a
This updates all code in the main package and subpackages to make use of the new chainhash package since the old wire.ShaHash type and functions have been removed in favor of the abstracted package. Also, since this required API changes anyways and the hash algorithm is no longer tied specifically to SHA, all other functions throughout the code base which had "Sha" in their name have been changed to Hash so they are not incorrectly implying the hash algorithm. The following is an overview of the changes: - Update all references to wire.ShaHash to the new chainhash.Hash type - Rename the following functions and update all references: - Block.Sha -> Hash - Block.TxSha -> TxHash - Tx.Sha -> Hash - bloom.Filter.AddShaHash -> AddHash - Rename all variables that included sha in their name to include hash instead - Add license headers to coinset package files
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
// Copyright (c) 2013-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package bloom_test
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
"github.com/btcsuite/btcd/wire"
|
|
"github.com/btcsuite/btcutil"
|
|
"github.com/btcsuite/btcutil/bloom"
|
|
)
|
|
|
|
func TestMerkleBlock3(t *testing.T) {
|
|
blockStr := "0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b" +
|
|
"4b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdc" +
|
|
"c96b2c3ff60abe184f196367291b4d4c86041b8fa45d630101000000010" +
|
|
"00000000000000000000000000000000000000000000000000000000000" +
|
|
"0000ffffffff08044c86041b020a02ffffffff0100f2052a01000000434" +
|
|
"104ecd3229b0571c3be876feaac0442a9f13c5a572742927af1dc623353" +
|
|
"ecf8c202225f64868137a18cdd85cbbb4c74fbccfd4f49639cf1bdc94a5" +
|
|
"672bb15ad5d4cac00000000"
|
|
blockBytes, err := hex.DecodeString(blockStr)
|
|
if err != nil {
|
|
t.Errorf("TestMerkleBlock3 DecodeString failed: %v", err)
|
|
return
|
|
}
|
|
blk, err := btcutil.NewBlockFromBytes(blockBytes)
|
|
if err != nil {
|
|
t.Errorf("TestMerkleBlock3 NewBlockFromBytes failed: %v", err)
|
|
return
|
|
}
|
|
|
|
f := bloom.NewFilter(10, 0, 0.000001, wire.BloomUpdateAll)
|
|
|
|
inputStr := "63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"
|
|
hash, err := chainhash.NewHashFromStr(inputStr)
|
|
if err != nil {
|
|
t.Errorf("TestMerkleBlock3 NewHashFromStr failed: %v", err)
|
|
return
|
|
}
|
|
|
|
f.AddHash(hash)
|
|
|
|
mBlock, _ := bloom.NewMerkleBlock(blk, f)
|
|
|
|
wantStr := "0100000079cda856b143d9db2c1caff01d1aecc8630d30625d10e8b4" +
|
|
"b8b0000000000000b50cc069d6a3e33e3ff84a5c41d9d3febe7c770fdcc" +
|
|
"96b2c3ff60abe184f196367291b4d4c86041b8fa45d630100000001b50c" +
|
|
"c069d6a3e33e3ff84a5c41d9d3febe7c770fdcc96b2c3ff60abe184f196" +
|
|
"30101"
|
|
want, err := hex.DecodeString(wantStr)
|
|
if err != nil {
|
|
t.Errorf("TestMerkleBlock3 DecodeString failed: %v", err)
|
|
return
|
|
}
|
|
|
|
got := bytes.NewBuffer(nil)
|
|
err = mBlock.BtcEncode(got, wire.ProtocolVersion)
|
|
if err != nil {
|
|
t.Errorf("TestMerkleBlock3 BtcEncode failed: %v", err)
|
|
return
|
|
}
|
|
|
|
if !bytes.Equal(want, got.Bytes()) {
|
|
t.Errorf("TestMerkleBlock3 failed merkle block comparison: "+
|
|
"got %v want %v", got.Bytes(), want)
|
|
return
|
|
}
|
|
}
|