github.com/NebulousLabs/Sia@v1.3.7/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  	t.Parallel()
    19  	cst, err := createConsensusSetTester(t.Name())
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	defer cst.Close()
    24  	cst.testBlockSuite()
    25  	oldHash := cst.cs.dbConsensusChecksum()
    26  	cst.cs.Close()
    27  
    28  	// Reassigning this will lose subscribers and such, but we
    29  	// just want to call load and get a hash
    30  	g, err := gateway.New("localhost:0", false, build.TempDir(modules.ConsensusDir, t.Name(), modules.GatewayDir))
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  	d := filepath.Join(build.SiaTestingDir, modules.ConsensusDir, t.Name(), modules.ConsensusDir)
    35  	cst.cs, err = New(g, false, d)
    36  	if err != nil {
    37  		t.Fatal(err)
    38  	}
    39  	newHash := cst.cs.dbConsensusChecksum()
    40  	if oldHash != newHash {
    41  		t.Fatal("consensus set hash changed after load")
    42  	}
    43  }