-
Notifications
You must be signed in to change notification settings - Fork 20
/
parse_integration_test.go
166 lines (147 loc) · 4.68 KB
/
parse_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package overflow
import (
"fmt"
"testing"
"github.com/hexops/autogold"
"github.com/sanity-io/litter"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseConfig(t *testing.T) {
g, err2 := OverflowTesting()
require.NoError(t, err2)
require.NotNil(t, g)
t.Run("parse", func(t *testing.T) {
result, err := g.ParseAll()
assert.NoError(t, err)
assert.NotNil(t, result)
// TODO; do not know
// TODO; do not know why equal does not work here
// autogold.Equal(t, result)
})
t.Run("parse and merge", func(t *testing.T) {
result, err := g.ParseAll()
assert.NoError(t, err)
merged := result.MergeSpecAndCode()
// TODO; do not know why equal does not work here
assert.NotNil(t, merged)
})
t.Run("parse and filter", func(t *testing.T) {
result, err := g.ParseAllWithConfig(true, []string{"arguments"}, []string{"test"})
assert.NoError(t, err)
autogold.Equal(t, result)
})
t.Run("parse and merge strip network prefix scripts", func(t *testing.T) {
result, err := g.ParseAll()
assert.NoError(t, err)
merged := result.MergeSpecAndCode()
emulator := merged.Networks["emulator"]
_, ok := emulator.Scripts["Foo"]
assert.True(t, ok, litter.Sdump(emulator.Scripts))
mainnet := merged.Networks["mainnet"]
_, mainnetOk := mainnet.Scripts["Foo"]
assert.True(t, mainnetOk, litter.Sdump(mainnet.Scripts))
})
t.Run("parse and merge strip network prefix transaction", func(t *testing.T) {
result, err := g.ParseAll()
assert.NoError(t, err)
merged := result.MergeSpecAndCode()
emulator := merged.Networks["emulator"]
_, ok := emulator.Transactions["Foo"]
assert.True(t, ok, litter.Sdump(emulator.Transactions))
mainnet := merged.Networks["mainnet"]
_, mainnetOk := mainnet.Transactions["Foo"]
assert.True(t, mainnetOk, litter.Sdump(mainnet.Transactions))
})
tx := `import FungibleToken from %s
transaction() {
// This is a %s transaction
}`
script := `import FungibleToken from %s
// This is a %s script
access(all) fun main(account: Address): String {
return getAccount(account).address.toString()
}`
result, err := g.ParseAll()
assert.NoError(t, err)
merged := result.MergeSpecAndCode()
type ParseIntegrationTestCase struct {
Network string
ScriptName string
ScriptType string
ContractAddress string
Expected string
}
tcs := []ParseIntegrationTestCase{
{
Network: "mainnet",
ScriptType: "Transaction",
ScriptName: "aTransaction",
ContractAddress: "0xf233dcee88fe0abe",
Expected: fmt.Sprintf(tx, "0xf233dcee88fe0abe", "mainnet specific"),
},
{
Network: "mainnet",
ScriptType: "Transaction",
ScriptName: "zTransaction",
ContractAddress: "0xf233dcee88fe0abe",
Expected: fmt.Sprintf(tx, "0xf233dcee88fe0abe", "mainnet specific"),
},
{
Network: "emulator",
ScriptType: "Transaction",
ScriptName: "aTransaction",
ContractAddress: "0xee82856bf20e2aa6",
Expected: fmt.Sprintf(tx, "0xee82856bf20e2aa6", "generic"),
},
{
Network: "emulator",
ScriptType: "Transaction",
ScriptName: "zTransaction",
ContractAddress: "0xf233dcee88fe0abe",
Expected: fmt.Sprintf(tx, "0xee82856bf20e2aa6", "generic"),
},
{
Network: "mainnet",
ScriptType: "Script",
ScriptName: "aScript",
ContractAddress: "0xf233dcee88fe0abe",
Expected: fmt.Sprintf(script, "0xf233dcee88fe0abe", "mainnet specific"),
},
{
Network: "mainnet",
ScriptType: "Script",
ScriptName: "zScript",
ContractAddress: "0xf233dcee88fe0abe",
Expected: fmt.Sprintf(script, "0xf233dcee88fe0abe", "mainnet specific"),
},
{
Network: "emulator",
ScriptType: "Script",
ScriptName: "aScript",
ContractAddress: "0xee82856bf20e2aa6",
Expected: fmt.Sprintf(script, "0xee82856bf20e2aa6", "generic"),
},
{
Network: "emulator",
ScriptType: "Script",
ScriptName: "zScript",
ContractAddress: "0xf233dcee88fe0abe",
Expected: fmt.Sprintf(script, "0xee82856bf20e2aa6", "generic"),
},
}
for _, tc := range tcs {
t.Run(fmt.Sprintf("parse and overwrite %s with %s network prefix script : %s", tc.ScriptType, tc.Network, tc.ScriptName), func(t *testing.T) {
network := merged.Networks[tc.Network]
if tc.ScriptType == "Script" {
script, ok := network.Scripts[tc.ScriptName]
assert.True(t, ok, litter.Sdump(network.Scripts))
assert.Equal(t, tc.Expected, script.Code)
return
}
tx, ok := network.Transactions[tc.ScriptName]
assert.True(t, ok, litter.Sdump(network.Transactions))
assert.Equal(t, tc.Expected, tx.Code)
})
}
}