gitlab.com/jokerrs1/Sia@v1.3.2/siatest/consensus/consensus_test.go (about)

     1  package consensus
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/NebulousLabs/Sia/node"
     7  	"github.com/NebulousLabs/Sia/siatest"
     8  )
     9  
    10  // TestApiHeight checks if the consensus api endpoint works
    11  func TestApiHeight(t *testing.T) {
    12  	if testing.Short() {
    13  		t.SkipNow()
    14  	}
    15  	testdir, err := siatest.TestDir(t.Name())
    16  	if err != nil {
    17  		t.Fatal(err)
    18  	}
    19  
    20  	// Create a new server
    21  	testNode, err := siatest.NewNode(node.AllModules(testdir))
    22  	if err != nil {
    23  		t.Fatal(err)
    24  	}
    25  	defer func() {
    26  		if err := testNode.Close(); err != nil {
    27  			t.Fatal(err)
    28  		}
    29  	}()
    30  
    31  	// Send GET request
    32  	cg, err := testNode.ConsensusGet()
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  	height := cg.Height
    37  
    38  	// Mine a block
    39  	if err := testNode.MineBlock(); err != nil {
    40  		t.Fatal(err)
    41  	}
    42  
    43  	// Request height again and check if it increased
    44  	cg, err = testNode.ConsensusGet()
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	if cg.Height != height+1 {
    49  		t.Fatal("Height should have increased by 1 block")
    50  	}
    51  }