ec641751a8
This commit modifies the BuildMerkleTreeStore function to accept a slice of btcutil.Tx transactions as opposed to a full block. This allows more flexibility when calculating merkle roots since a full block may not be created yet (particularly when generating blocks that need to be solved in mining). Previously, the BuildMerkleTreeStore function accepted a btcutil.Block because originally the block itself cached the transaction hashes and it was necessary to have access to the block to make use of the cached transactions. However, the code has since been improved such that it caches transaction hashes directly in each btcutil.Tx. This means the code can remain as efficient as before while allowing the individual transacitons to be passed.
23 lines
712 B
Go
23 lines
712 B
Go
// 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.
|
|
|
|
package btcchain_test
|
|
|
|
import (
|
|
"github.com/conformal/btcchain"
|
|
"github.com/conformal/btcutil"
|
|
"testing"
|
|
)
|
|
|
|
// TestMerkle tests the BuildMerkleTreeStore API.
|
|
func TestMerkle(t *testing.T) {
|
|
block := btcutil.NewBlock(&Block100000)
|
|
merkles := btcchain.BuildMerkleTreeStore(block.Transactions())
|
|
calculatedMerkleRoot := merkles[len(merkles)-1]
|
|
wantMerkle := &Block100000.Header.MerkleRoot
|
|
if !wantMerkle.IsEqual(calculatedMerkleRoot) {
|
|
t.Errorf("BuildMerkleTreeStore: merkle root mismatch - "+
|
|
"got %v, want %v", calculatedMerkleRoot, wantMerkle)
|
|
}
|
|
}
|