-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
TestSkipHeights
skip 5 seconds per every height
- Loading branch information
Showing
3 changed files
with
29 additions
and
0 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
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