github.com/dmmcquay/sia@v1.3.1-0.20180712220038-9f8d535311b9/cmd/siac/consensuscmd_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/NebulousLabs/Sia/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(2017, time.April, 13, 23, 29, 49, 0, time.UTC),
    20  			100e3,
    21  		},
    22  		// 4 minutes later
    23  		{
    24  			time.Date(2017, time.April, 13, 23, 33, 49, 0, time.UTC),
    25  			100e3,
    26  		},
    27  		// 5 minutes later
    28  		{
    29  			time.Date(2017, time.April, 13, 23, 34, 49, 0, time.UTC),
    30  			100e3 + 1,
    31  		},
    32  		// 15 minutes later
    33  		{
    34  			time.Date(2017, time.April, 13, 23, 44, 49, 0, time.UTC),
    35  			100e3 + 2,
    36  		},
    37  		// 1 day later
    38  		{
    39  			time.Date(2017, time.April, 14, 23, 29, 49, 0, time.UTC),
    40  			100e3 + 160,
    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  }