2014-07-10 03:01:38 +02:00
|
|
|
// Copyright (c) 2013, 2014 Conformal Systems LLC.
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-07-09 04:59:33 +02:00
|
|
|
package bloom_test
|
2014-07-01 02:51:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/hex"
|
2014-07-09 04:59:33 +02:00
|
|
|
"testing"
|
|
|
|
|
2014-07-01 02:51:45 +02:00
|
|
|
"github.com/conformal/btcutil"
|
2014-07-09 04:59:33 +02:00
|
|
|
"github.com/conformal/btcutil/bloom"
|
2014-07-01 02:51:45 +02:00
|
|
|
"github.com/conformal/btcwire"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:33 +02:00
|
|
|
f := bloom.NewFilter(10, 0, 0.000001, btcwire.BloomUpdateAll)
|
2014-07-01 02:51:45 +02:00
|
|
|
|
|
|
|
inputStr := "63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5"
|
|
|
|
sha, err := btcwire.NewShaHashFromStr(inputStr)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("TestMerkleBlock3 NewShaHashFromStr failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
f.AddShaHash(sha)
|
|
|
|
|
2014-07-09 04:59:33 +02:00
|
|
|
mBlock, _ := bloom.NewMerkleBlock(blk, f)
|
2014-07-01 02:51:45 +02:00
|
|
|
|
|
|
|
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, btcwire.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
|
|
|
|
}
|
|
|
|
}
|