func reorgTestShort(t *testing.T) {
	chain, teardownFunc, err := blockchain.SetupTestChain("reorgunittest",
		simNetParams)
	if err != nil {
		t.Errorf("Failed to setup chain instance: %v", err)
		return
	}
	defer teardownFunc()
	genesisBlock := simNetParams.GenesisBlock
	err = chain.CheckConnectBlock(hcashutil.NewBlock(genesisBlock), false)
	if err == nil {
		t.Errorf("CheckConnectBlock: Did not receive expected error")
	}
	filename := filepath.Join("testdata/", "reorgto179.bz2")
	fi, err := os.Open(filename)
	if err != nil {
		t.Errorf("Unable to open %s: %v", filename, err)
	}
	bcStream := bzip2.NewReader(fi)
	defer fi.Close()
	bcBuf := new(bytes.Buffer)
	bcBuf.ReadFrom(bcStream)
	bcDecoder := gob.NewDecoder(bcBuf)
	blockChain1 := make(map[int64][]byte)
	if err := bcDecoder.Decode(&blockChain1); err != nil {
		t.Errorf("error decoding test blockchain: %v", err.Error())
	}
	filename = filepath.Join("testdata/", "reorgto180.bz2")
	fi, err = os.Open(filename)
	if err != nil {
		t.Errorf("Unable to open %s: %v", filename, err)
	}
	bcStream = bzip2.NewReader(fi)
	defer fi.Close()
	bcBuf = new(bytes.Buffer)
	bcBuf.ReadFrom(bcStream)
	bcDecoder = gob.NewDecoder(bcBuf)
	blockChain2 := make(map[int64][]byte)
	if err := bcDecoder.Decode(&blockChain2); err != nil {
		t.Errorf("error decoding test blockchain: %v", err.Error())
	}
	forkPoint := 131
	finalIdx2 := 180
	for i := 1; i < forkPoint+1; i++ {
		bl, err := hcashutil.NewBlockFromBytes(blockChain1[int64(i)])
		if err != nil {
			t.Fatalf("NewBlockFromBytes error: %v", err.Error())
		}
		_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
		if err != nil {
			t.Fatalf("ProcessBlock error at height %v: %v", i, err.Error())
		}
	}
	dominant := blockChain2
	orphaned := blockChain1
	for i := forkPoint; i < finalIdx2; i++ {
		for j := 0; j < 2; j++ {
			bl, err := hcashutil.NewBlockFromBytes(dominant[int64(i+j)])
			if err != nil {
				t.Fatalf("NewBlockFromBytes error: %v", err.Error())
			}
			_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
			if err != nil {
				t.Fatalf("ProcessBlock error: %v", err.Error())
			}
		}
		dominant, orphaned = orphaned, dominant
	}
	topBlock, _ := chain.GetTopBlock()
	tipHash := topBlock.Hash()
	expected, _ := chainhash.NewHashFromStr("5ab969d0afd8295b6cd1506f2a310d" +
		"259322015c8bd5633f283a163ce0e50594")
	if *tipHash != *expected {
		t.Errorf("Failed to correctly reorg; expected tip %v, got tip %v",
			expected, tipHash)
	}
	have, err := chain.HaveBlock(expected)
	if !have {
		t.Errorf("missing tip block after reorganization test")
	}
	if err != nil {
		t.Errorf("unexpected error testing for presence of new tip block "+
			"after reorg test: %v", err)
	}
	return
}
reorgTestsShort does short reorganizations to test multiple, frequent
reorganizations.
package blockchain_test
import (
	"bytes"
	"compress/bzip2"
	"encoding/gob"
	"os"
	"path/filepath"
	"testing"
	"github.com/HcashOrg/hcashd/blockchain"
	"github.com/HcashOrg/hcashd/chaincfg/chainhash"
	"github.com/HcashOrg/hcashutil"
)
func reorgTestLong(t *testing.T) {
	chain, teardownFunc, err := blockchain.SetupTestChain("reorgunittest", simNetParams)
	if err != nil {
		t.Errorf("Failed to setup chain instance: %v", err)
		return
	}
	defer teardownFunc()
	genesisBlock := simNetParams.GenesisBlock
	err = chain.CheckConnectBlock(hcashutil.NewBlock(genesisBlock), false)
	if err == nil {
		t.Errorf("CheckConnectBlock: Did not receive expected error")
	}
	filename := filepath.Join("testdata/", "reorgto179.bz2")
	fi, err := os.Open(filename)
	if err != nil {
		t.Errorf("Unable to open %s: %v", filename, err)
	}
	bcStream := bzip2.NewReader(fi)
	defer fi.Close()
	bcBuf := new(bytes.Buffer)
	bcBuf.ReadFrom(bcStream)
	bcDecoder := gob.NewDecoder(bcBuf)
	blockChain := make(map[int64][]byte)
	if err := bcDecoder.Decode(&blockChain); err != nil {
		t.Errorf("error decoding test blockchain: %v", err.Error())
	}
	finalIdx1 := 179
	for i := 1; i < finalIdx1+1; i++ {
		bl, err := hcashutil.NewBlockFromBytes(blockChain[int64(i)])
		if err != nil {
			t.Fatalf("NewBlockFromBytes error: %v", err.Error())
		}
		_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
		if err != nil {
			t.Fatalf("ProcessBlock error at height %v: %v", i, err.Error())
		}
	}
	filename = filepath.Join("testdata/", "reorgto180.bz2")
	fi, err = os.Open(filename)
	if err != nil {
		t.Errorf("Unable to open %s: %v", filename, err)
	}
	bcStream = bzip2.NewReader(fi)
	defer fi.Close()
	bcBuf = new(bytes.Buffer)
	bcBuf.ReadFrom(bcStream)
	bcDecoder = gob.NewDecoder(bcBuf)
	blockChain = make(map[int64][]byte)
	if err := bcDecoder.Decode(&blockChain); err != nil {
		t.Errorf("error decoding test blockchain: %v", err.Error())
	}
	forkPoint := 131
	finalIdx2 := 180
	for i := forkPoint; i < finalIdx2+1; i++ {
		bl, err := hcashutil.NewBlockFromBytes(blockChain[int64(i)])
		if err != nil {
			t.Fatalf("NewBlockFromBytes error: %v", err.Error())
		}
		_, _, err = chain.ProcessBlock(bl, blockchain.BFNone)
		if err != nil {
			t.Fatalf("ProcessBlock error: %v", err.Error())
		}
	}
	topBlock, _ := chain.GetTopBlock()
	tipHash := topBlock.Hash()
	expected, _ := chainhash.NewHashFromStr("5ab969d0afd8295b6cd1506f2a310d" +
		"259322015c8bd5633f283a163ce0e50594")
	if *tipHash != *expected {
		t.Errorf("Failed to correctly reorg; expected tip %v, got tip %v",
			expected, tipHash)
	}
	have, err := chain.HaveBlock(expected)
	if !have {
		t.Errorf("missing tip block after reorganization test")
	}
	if err != nil {
		t.Errorf("unexpected error testing for presence of new tip block "+
			"after reorg test: %v", err)
	}
	return
}