This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move block height estimation to its own function and test it
- Loading branch information
1 parent
586a045
commit f2ed3ca
Showing
2 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/NebulousLabs/Sia/types" | ||
) | ||
|
||
// TestEstimatedHeightAt tests that the expectedHeightAt function correctly | ||
// estimates the blockheight (and rounds to the nearest block). | ||
func TestEstimatedHeightAt(t *testing.T) { | ||
tests := []struct { | ||
t time.Time | ||
expectedHeight types.BlockHeight | ||
}{ | ||
// Test on the same block that is used to estimate the height | ||
{ | ||
time.Date(2016, time.May, 11, 19, 33, 0, 0, time.UTC), | ||
5e4, | ||
}, | ||
// 4 minutes later | ||
{ | ||
time.Date(2016, time.May, 11, 19, 37, 0, 0, time.UTC), | ||
5e4, | ||
}, | ||
// 5 minutes later | ||
{ | ||
time.Date(2016, time.May, 11, 19, 38, 0, 0, time.UTC), | ||
5e4 + 1, | ||
}, | ||
// 10 minutes later | ||
{ | ||
time.Date(2016, time.May, 11, 19, 43, 0, 0, time.UTC), | ||
5e4 + 1, | ||
}, | ||
// 1 day later | ||
{ | ||
time.Date(2016, time.May, 12, 19, 33, 0, 0, time.UTC), | ||
5e4 + 144, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
h := estimatedHeightAt(tt.t) | ||
if h != tt.expectedHeight { | ||
t.Errorf("expected an estimated height of %v, but got %v", tt.expectedHeight, h) | ||
} | ||
} | ||
} |