-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevent_integration_test.go
116 lines (96 loc) · 3.26 KB
/
event_integration_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 main
import (
"github.com/bjartek/go-with-the-flow/v2/gwtf"
"github.com/stretchr/testify/assert"
"io/fs"
"os"
"testing"
)
func TestEvents(t *testing.T) {
t.Run("Test that from index cannot be negative", func(t *testing.T) {
g := gwtf.NewTestingEmulator()
g.TransactionFromFile("mint_tokens").
SignProposeAndPayAsService().
AccountArgument("first").
UFix64Argument("100.0").
Test(t).
AssertSuccess().
AssertEventCount(3)
_, err := g.EventFetcher().End(2).From(-10).Event("A.0ae53cb6e3f42a79.FlowToken.TokensMinted").Run()
assert.Error(t, err)
assert.Contains(t, "FromIndex is negative", err.Error())
})
t.Run("Fetch last events", func(t *testing.T) {
g := gwtf.NewTestingEmulator()
g.TransactionFromFile("mint_tokens").
SignProposeAndPayAsService().
AccountArgument("first").
UFix64Argument("100.0").
Test(t).
AssertSuccess().
AssertEventCount(3)
ev, err := g.EventFetcher().Last(2).Event("A.0ae53cb6e3f42a79.FlowToken.TokensMinted").Run()
assert.NoError(t, err)
assert.Equal(t, 1, len(ev))
})
t.Run("Fetch last events and sort them ", func(t *testing.T) {
g := gwtf.NewTestingEmulator()
g.TransactionFromFile("mint_tokens").
SignProposeAndPayAsService().
AccountArgument("first").
UFix64Argument("100.0").
Test(t).
AssertSuccess().
AssertEventCount(3)
g.TransactionFromFile("mint_tokens").
SignProposeAndPayAsService().
AccountArgument("first").
UFix64Argument("100.0").
Test(t).
AssertSuccess().
AssertEventCount(3)
ev, err := g.EventFetcher().Last(3).Event("A.0ae53cb6e3f42a79.FlowToken.TokensMinted").Run()
assert.NoError(t, err)
assert.Equal(t, 2, len(ev))
assert.True(t, ev[0].BlockHeight < ev[1].BlockHeight)
})
t.Run("Fetch last write progress file", func(t *testing.T) {
g := gwtf.NewTestingEmulator()
g.TransactionFromFile("mint_tokens").
SignProposeAndPayAsService().
AccountArgument("first").
UFix64Argument("100.0").
Test(t).
AssertSuccess().
AssertEventCount(3)
ev, err := g.EventFetcher().Event("A.0ae53cb6e3f42a79.FlowToken.TokensMinted").TrackProgressIn("progress").Run()
defer os.Remove("progress")
assert.NoError(t, err)
assert.Equal(t, 1, len(ev))
})
t.Run("should fail reading invalid progress from file", func(t *testing.T) {
err := os.WriteFile("progress", []byte("invalid"), fs.ModePerm)
assert.NoError(t, err)
g := gwtf.NewTestingEmulator()
_, err = g.EventFetcher().Event("A.0ae53cb6e3f42a79.FlowToken.TokensMinted").TrackProgressIn("progress").Run()
defer os.Remove("progress")
assert.Error(t, err)
assert.Equal(t, "could not parse progress file as block height strconv.ParseInt: parsing \"invalid\": invalid syntax", err.Error())
})
t.Run("Fetch last write progress file that exists", func(t *testing.T) {
err := os.WriteFile("progress", []byte("1"), fs.ModePerm)
assert.NoError(t, err)
g := gwtf.NewTestingEmulator()
g.TransactionFromFile("mint_tokens").
SignProposeAndPayAsService().
AccountArgument("first").
UFix64Argument("100.0").
Test(t).
AssertSuccess().
AssertEventCount(3)
ev, err := g.EventFetcher().Event("A.0ae53cb6e3f42a79.FlowToken.TokensMinted").TrackProgressIn("progress").Run()
defer os.Remove("progress")
assert.NoError(t, err)
assert.Equal(t, 1, len(ev))
})
}