-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpow_live_test.go
More file actions
53 lines (46 loc) · 1.44 KB
/
Copy pathpow_live_test.go
File metadata and controls
53 lines (46 loc) · 1.44 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
package main
import (
"context"
"os"
"strconv"
"testing"
"time"
)
// TestLivePowSolve runs the full fetch-current-module-and-solve path against a
// live guns.lol challenge. It is network-gated: set GUNS_LIVE=1 to run. This is
// the regression test for the rotation 1003 bug — it confirms the fetched
// module matches the current challenge's seal.
func TestLivePowSolve(t *testing.T) {
if os.Getenv("GUNS_LIVE") != "1" {
t.Skip("set GUNS_LIVE=1 to run the live PoW integration test")
}
username := os.Getenv("GUNS_USER")
if username == "" {
username = "tenshii"
}
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
sess, err := newSession(os.Getenv("GUNS_PROXY"), false)
if err != nil {
t.Fatalf("newSession: %v", err)
}
wd, err := sess.FetchWorkerData(ctx, username)
if err != nil {
t.Fatalf("FetchWorkerData: %v", err)
}
t.Logf("challenge id=%s worker=%s difficulty=%d", wd.ID, wd.WorkerURL, wd.Difficulty)
mod, err := sess.FetchPowModule(ctx, wd.ID, wd.WorkerURL)
if err != nil {
t.Fatalf("FetchPowModule: %v", err)
}
t.Logf("ctor=%s solve=%s wasm=%d bytes", mod.ctorExport, mod.solveExport, len(mod.wasm))
res, err := SolveWithWasm(ctx, mod, wd.Challenge, wd.Difficulty,
strconv.FormatInt(wd.Timestamp, 10), wd.Nonce, wd.Seal)
if err != nil {
t.Fatalf("SolveWithWasm: %v", err)
}
t.Logf("proof=%s", res.Oo)
if res.Oo == "" {
t.Fatal("solver returned an empty _oo proof")
}
}