-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(std): support timestamp skipping in test cases (#569)
<!--- Provide a general summary of your changes in the Title above --> <!--- If you need to use a more detailed template, append the query param template=detailed_pr_template.md to the URL --> # Description support timestamp skipping in test cases # How has this been tested? test case run by gnodev
- Loading branch information
Showing
5 changed files
with
36 additions
and
5 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 |
---|---|---|
|
@@ -49,8 +49,8 @@ func main() { | |
// 177 | ||
// 802 | ||
// --- | ||
// 450 | ||
// 78 | ||
// 777 | ||
// 15 | ||
// 339 | ||
// 269 | ||
// 233 | ||
// 591 | ||
// 936 | ||
// 908 |
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 @@ | ||
package skiptime |
27 changes: 27 additions & 0 deletions
27
examples/gno.land/r/x/skip_height_to_skip_time/skiptime_test.gno
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,27 @@ | ||
package skiptime | ||
|
||
import ( | ||
"std" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestSkipHeights(t *testing.T) { | ||
oldHeight := std.GetHeight() | ||
shouldEQ(t, oldHeight, 123) | ||
|
||
oldNow := time.Now().Unix() | ||
shouldEQ(t, oldNow, 1234567890) | ||
|
||
// skip 3 blocks == 15 seconds | ||
std.TestSkipHeights(3) | ||
|
||
shouldEQ(t, std.GetHeight()-oldHeight, 3) | ||
shouldEQ(t, time.Now().Unix()-oldNow, 15) | ||
} | ||
|
||
func shouldEQ(t *testing.T, got, expected int64) { | ||
if got != expected { | ||
t.Fatalf("expected %d, got %d.", expected, got) | ||
} | ||
} |
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