github.com/fozzysec/SiaPrime@v0.0.0-20190612043147-66c8e8d11fe3/cmd/spc/consensuscmd_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"SiaPrime/types"
     8  )
     9  
    10  // TestEstimatedHeightAt tests that the expectedHeightAt function correctly
    11  // estimates the blockheight (and rounds to the nearest block).
    12  func TestEstimatedHeightAt(t *testing.T) {
    13  	tests := []struct {
    14  		t              time.Time
    15  		expectedHeight types.BlockHeight
    16  	}{
    17  		// Test on the same block that is used to estimate the height
    18  		{
    19  			time.Date(2018, time.December, 9, 5, 30, 17, 0, time.UTC),
    20  			5694,
    21  		},
    22  		// 4 minutes later
    23  		{
    24  			time.Date(2018, time.December, 9, 5, 34, 17, 0, time.UTC),
    25  			5694,
    26  		},
    27  		// 5 minutes later
    28  		{
    29  			time.Date(2018, time.December, 9, 5, 35, 17, 0, time.UTC),
    30  			5694,
    31  		},
    32  		// 15 minutes later
    33  		{
    34  			time.Date(2018, time.December, 9, 5, 45, 17, 0, time.UTC),
    35  			5696,
    36  		},
    37  		// 1 day later
    38  		{
    39  			time.Date(2018, time.December, 10, 5, 45, 17, 0, time.UTC),
    40  			5856,
    41  		},
    42  	}
    43  	for _, tt := range tests {
    44  		h := estimatedHeightAt(tt.t)
    45  		if h != tt.expectedHeight {
    46  			t.Errorf("expected an estimated height of %v, but got %v", tt.expectedHeight, h)
    47  		}
    48  	}
    49  }