github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/consensus/persist_test.go (about)

     1  package consensus
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/NebulousLabs/Sia/build"
     8  	"github.com/NebulousLabs/Sia/modules"
     9  	"github.com/NebulousLabs/Sia/modules/gateway"
    10  )
    11  
    12  // TestSaveLoad populates a blockchain, saves it, loads it, and checks
    13  // the consensus set hash before and after
    14  func TestSaveLoad(t *testing.T) {
    15  	if testing.Short() {
    16  		t.SkipNow()
    17  	}
    18  	cst, err := createConsensusSetTester("TestSaveLoad")
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	cst.testBlockSuite()
    23  	oldHash := cst.cs.dbConsensusChecksum()
    24  	cst.cs.Close()
    25  
    26  	// Reassigning this will lose subscribers and such, but we
    27  	// just want to call load and get a hash
    28  	g, err := gateway.New("localhost:0", build.TempDir(modules.ConsensusDir, "TestSaveLoad", modules.GatewayDir))
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  	d := filepath.Join(build.SiaTestingDir, modules.ConsensusDir, "TestSaveLoad", modules.ConsensusDir)
    33  	cst.cs, err = New(g, d)
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  	newHash := cst.cs.dbConsensusChecksum()
    38  	if oldHash != newHash {
    39  		t.Fatal("consensus set hash changed after load")
    40  	}
    41  }