-
Notifications
You must be signed in to change notification settings - Fork 92
/
EntriesBeforeChain_test.go
116 lines (91 loc) · 2.83 KB
/
EntriesBeforeChain_test.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
package simtest
import (
"bytes"
"fmt"
"github.com/FactomProject/factom"
"github.com/FactomProject/factomd/engine"
. "github.com/FactomProject/factomd/testHelper"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCreatEntriesBeforeChain(t *testing.T) {
//FIXME test disabled
return
encode := func(s string) []byte {
b := bytes.Buffer{}
b.WriteString(s)
return b.Bytes()
}
id := "92475004e70f41b94750f4a77bf7b430551113b25d3d57169eadca5692bb043d"
extids := [][]byte{encode("foo"), encode("bar")}
a := AccountFromFctSecret("Fs2zQ3egq2j99j37aYzaCddPq9AF3mgh64uG9gRaDAnrkjRx3eHs")
b := GetBankAccount()
numEntries := 250 // set the total number of entries to add
t.Run("generate accounts", func(t *testing.T) {
println(b.String())
println(a.String())
})
// KLUDGE: using "LAF" causes timeout on CI
t.Run("Run sim to create entries", func(t *testing.T) {
state0 := SetupSim("L", map[string]string{"--debuglog": ""}, 200, 0, 0, t)
stop := func() {
ShutDownEverything(t)
WaitForAllNodes(state0)
}
t.Run("Create Entries Before Chain", func(t *testing.T) {
publish := func(i int) {
e := factom.Entry{
ChainID: id,
ExtIDs: extids,
Content: encode(fmt.Sprintf("hello@%v", i)), // ensure no duplicate msg hashes
}
i++
commit, _ := ComposeCommitEntryMsg(a.Priv, e)
reveal, _ := ComposeRevealEntryMsg(a.Priv, &e)
state0.APIQueue().Enqueue(commit)
state0.APIQueue().Enqueue(reveal)
}
for x := 0; x < numEntries; x++ {
publish(x)
}
})
t.Run("Create Chain", func(t *testing.T) {
e := factom.Entry{
ChainID: id,
ExtIDs: extids,
Content: encode("Hello World!"),
}
c := factom.NewChain(&e)
commit, _ := ComposeChainCommit(a.Priv, c)
reveal, _ := ComposeRevealEntryMsg(a.Priv, c.FirstEntry)
state0.APIQueue().Enqueue(commit)
state0.APIQueue().Enqueue(reveal)
})
t.Run("Fund EC Address", func(t *testing.T) {
amt := uint64(numEntries + 10)
engine.FundECWallet(state0, b.FctPrivHash(), a.EcAddr(), amt*state0.GetFactoshisPerEC())
WaitForAnyDeposit(state0, a.EcPub())
})
t.Run("End simulation", func(t *testing.T) {
WaitForZero(state0, a.EcPub())
ht := state0.GetDBHeightComplete()
WaitBlocks(state0, 1)
newHt := state0.GetDBHeightComplete()
//fmt.Printf("Old: %v New: %v", ht, newHt)
assert.True(t, ht < newHt, "block height should progress")
//assert.True(t, newHt >= uint32(11), "should be past block 10")
stop()
})
t.Run("Verify Entries", func(t *testing.T) {
bal := engine.GetBalanceEC(state0, a.EcPub())
//fmt.Printf("Bal: => %v", bal)
assert.Equal(t, bal, int64(0))
for _, v := range state0.Holding {
s, _ := v.JSONString()
println(s)
}
// TODO: actually check for confirmed entries
assert.Equal(t, 0, len(state0.Holding), "messages stuck in holding")
})
})
}