/
e2e.go
136 lines (112 loc) · 2.9 KB
/
e2e.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package e2e
import (
"os"
"time"
"github.com/lbryio/chainquery/model"
"github.com/volatiletech/sqlboiler/queries/qm"
"github.com/lbryio/lbry.go/extras/errors"
"github.com/lbryio/chainquery/daemon"
"github.com/lbryio/chainquery/daemon/jobs"
"github.com/lbryio/chainquery/lbrycrd"
"github.com/sirupsen/logrus"
)
const claimAmount = 0.5
// StartE2ETesting launches the test suite
func StartE2ETesting() {
go daemon.DoYourThing()
logrus.Info("Started E2E tests")
testBasicClaimCreation()
increment(10)
createChannelWithClaims()
increment(1)
time.Sleep(15 * time.Second)
jobs.ClaimTrieSync()
jobs.CertificateSync()
time.Sleep(2 * time.Second)
exitOnErr(checkCertValid([]string{"claim1", "claim2", "claim3"}))
testImageMetadata()
testVideoMetaData()
daemon.ShutdownDaemon()
}
func createChannelWithClaims() {
channel, key, err := createChannel("@MyChannel")
if err != nil {
exit(1, err)
}
logrus.Info(lbrycrd.GenerateBlocks(1))
claimResponse, err := lbrycrd.GetClaimsForName("@MyChannel")
if err != nil {
exit(1, err)
}
claim1, err := newStreamClaim("title1", "description2")
if err != nil {
exit(1, err)
}
claim2, err := newStreamClaim("title1", "description2")
if err != nil {
exit(1, err)
}
claim3, err := newStreamClaim("title1", "description2")
if err != nil {
exit(1, err)
}
rawTx, err := getEmptyTx(claimAmount * 3)
if err != nil {
exit(1, err)
}
exitOnErr(signClaim(rawTx, *key, claim1, channel, claimResponse.Claims[0].ClaimID))
exitOnErr(signClaim(rawTx, *key, claim2, channel, claimResponse.Claims[0].ClaimID))
exitOnErr(signClaim(rawTx, *key, claim3, channel, claimResponse.Claims[0].ClaimID))
exitOnErr(addClaimToTx(rawTx, claim1, "claim1"))
exitOnErr(addClaimToTx(rawTx, claim2, "claim2"))
exitOnErr(addClaimToTx(rawTx, claim3, "claim3"))
chainHash, err := signTxAndSend(rawTx)
if err != nil {
exit(1, err)
}
logrus.Info("Tx:", chainHash.String())
}
func exit(code int, err error) {
logrus.Error(err, "\n", errors.FullTrace(err))
os.Exit(code)
}
func exitOnErr(err error) {
if err != nil {
exit(1, errors.Err(err))
}
}
func increment(blocks ...int) {
if len(blocks) > 0 {
_, err := lbrycrd.GenerateBlocks(int64(blocks[0]))
exitOnErr(err)
}
}
func test(run func(), check func() error, blocks uint) {
height, err := lbrycrd.GetBlockCount()
exitOnErr(errors.Err(err))
run()
increment(int(blocks + 1))
//wait x blocks
reached := make(chan bool)
ticker := time.NewTicker(100 * time.Millisecond)
go func() {
for range ticker.C {
block, err := model.Blocks(qm.OrderBy("height DESC"), qm.Limit(1)).OneG()
exitOnErr(errors.Err(err))
if (block.Height - *height) >= uint64(blocks+1) {
logrus.Infof("Block %d reached from %d", block.Height, *height)
reached <- true
ticker.Stop()
}
}
}()
<-reached
exitOnErr(check())
}
func verify(test bool, message string) {
var err error
if !test {
err = errors.Err(message)
}
exitOnErr(err)
}