forked from FactomProject/FactomCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplay_test.go
More file actions
55 lines (45 loc) · 1.01 KB
/
replay_test.go
File metadata and controls
55 lines (45 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package process
import (
"fmt"
fct "github.com/FactomProject/factoid"
"math/rand"
"testing"
"time"
)
var _ = fmt.Printf
var _ = rand.New
var now = time.Now().Unix()
var hour = int64(60 * 60)
func Test_Replay(test *testing.T) {
type mh struct {
hash []byte
time int64
}
var h [5000]*mh
for i := 0; i < 5000; i++ {
h[i] = new(mh)
h[i].hash = fct.Sha([]byte(fmt.Sprintf("h%d", i))).Bytes()
h[i].time = now + (rand.Int63() % 24 * hour) - 12*hour
if !IsTSValid_(h[i].hash, h[i].time, now) {
fmt.Println("Failed Test ", i, "first")
test.Fail()
return
}
if IsTSValid_(h[i].hash, h[i].time, now) {
fmt.Println("Failed Test ", i, "second")
test.Fail()
return
}
now += rand.Int63() % hour
for j := 0; j < i; j++ {
if IsTSValid_(h[i].hash, h[i].time, hour) {
fmt.Println("Failed Test ", i, j, "repeat")
test.Fail()
return
}
}
}
}