-
Notifications
You must be signed in to change notification settings - Fork 40
/
contract_store_test.go
177 lines (167 loc) · 5.77 KB
/
contract_store_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
167
168
169
170
171
172
173
174
175
176
177
package seth_test
import (
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/smartcontractkit/chainlink-testing-framework/seth"
)
func TestSmokeContractABIStore(t *testing.T) {
type test struct {
name string
abiPath string
gethWrappersPaths []string
err string
expectedABICount int
}
tests := []test{
{
name: "can load the ABI only from ABI files",
abiPath: "./contracts/abi",
expectedABICount: 8,
},
{
name: "can load the ABI from ABI files and from gethwrappers",
abiPath: "./contracts/abi",
gethWrappersPaths: []string{"./contracts/bind"},
expectedABICount: 11,
},
{
name: "can load the ABI only from gethwrappers",
gethWrappersPaths: []string{"./contracts/bind"},
expectedABICount: 7,
},
{
name: "can load the ABI from 2 gethwrappers folders",
gethWrappersPaths: []string{"./contracts/bind", "./contracts/bind2"},
expectedABICount: 8,
},
{
name: "can't open the ABI path",
abiPath: "dasdsadd",
err: "open dasdsadd: no such file or directory",
},
{
name: "can't open the gethwrappers path",
gethWrappersPaths: []string{"dasdsadd"},
err: "failed to load geth wrappers from [dasdsadd]: lstat dasdsadd: no such file or directory",
},
{
name: "correct and broken gethwrappers path",
gethWrappersPaths: []string{"./contracts/emptyContractDir", "dasdsadd"},
err: "failed to load geth wrappers from [./contracts/emptyContractDir dasdsadd]: lstat dasdsadd: no such file or directory",
},
{
name: "broken and correct gethwrappers path",
gethWrappersPaths: []string{"dasdsadd", "./contracts/emptyContractDir"},
err: "failed to load geth wrappers from [dasdsadd ./contracts/emptyContractDir]: lstat dasdsadd: no such file or directory",
},
{
name: "empty ABI dir",
abiPath: "./contracts/emptyContractDir",
err: "no ABI files found in './contracts/emptyContractDir'. Fix the path or comment out 'abi_dir' setting",
},
{
name: "empty gethwrappers dir",
gethWrappersPaths: []string{"./contracts/emptyContractDir"},
err: "failed to load geth wrappers from [./contracts/emptyContractDir]: no geth wrappers found in '[./contracts/emptyContractDir]'. Fix the path or comment out 'geth_wrappers_dirs' setting",
},
{
name: "empty ABI and gethwrappers dir",
abiPath: "./contracts/emptyContractDir",
gethWrappersPaths: []string{"./contracts/emptyContractDir"},
err: "no ABI files found in './contracts/emptyContractDir'. Fix the path or comment out 'abi_dir' setting",
},
{
name: "no MetaData in one of gethwrappers",
gethWrappersPaths: []string{"./contracts/noMetaDataContractDir"},
expectedABICount: 1,
},
{
name: "empty MetaData in one of gethwrappers",
gethWrappersPaths: []string{"./contracts/emptyMetaDataContractDir"},
err: "failed to load geth wrappers from [./contracts/emptyMetaDataContractDir]: failed to parse ABI content: EOF",
},
{
name: "gethwrappers dir mixes regular go files and gethwrappers",
gethWrappersPaths: []string{"./contracts/gethWrapperAndGoFile"},
expectedABICount: 1,
},
{
name: "invalid ABI inside ABI dir",
abiPath: "./contracts/invalidContractDir",
err: "failed to parse ABI file: invalid character ':' after array element",
},
{
name: "invalid ABI in gethwrappers inside dir",
gethWrappersPaths: []string{"./contracts/invalidContractDir"},
err: "failed to load geth wrappers from [./contracts/invalidContractDir]: failed to parse ABI content: invalid character 'i' looking for beginning of value",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var err error
cs, err := seth.NewContractStore(tc.abiPath, "", tc.gethWrappersPaths)
if err == nil {
require.NotNil(t, cs.ABIs, "ABIs should not be nil")
require.Equal(t, tc.expectedABICount, len(cs.ABIs), "ABIs should have the expected count")
require.NotNil(t, cs.BINs, "BINs should not be nil")
require.Equal(t, make(map[string][]uint8), cs.BINs)
err = errors.New("")
}
require.Equal(t, tc.err, err.Error())
})
}
}
func TestSmokeContractBINStore(t *testing.T) {
type test struct {
name string
abiPath string
binPath string
binFound bool
err string
}
tests := []test{
{
name: "can load the ABI and BIN",
abiPath: "./contracts/abi",
binPath: "./contracts/bin",
binFound: true,
},
{
name: "can load the ABI and BIN and gethWrappers",
abiPath: "./contracts/abi",
binPath: "./contracts/bin",
binFound: true,
},
{
name: "can't open the BIN path",
abiPath: "./contracts/abi",
binPath: "./contract/i-don't-exist",
err: "open ./contract/i-don't-exist: no such file or directory",
},
{
name: "empty BIN dir",
abiPath: "./contracts/abi",
binPath: "./contracts/emptyContractDir",
err: "no BIN files found in './contracts/emptyContractDir'. Fix the path or comment out 'bin_dir' setting",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var err error
cs, err := seth.NewContractStore(tc.abiPath, tc.binPath, nil)
if err == nil {
require.NotEmpty(t, cs.ABIs, "ABIs should not be empty")
err = errors.New("")
if tc.binFound {
require.NotEmpty(t, cs.BINs, "BINs should not be empty")
} else {
require.Empty(t, cs.BINs, "BINs should be empty")
}
} else {
require.Nil(t, cs, "ContractStore should be nil")
}
require.Equal(t, tc.err, err.Error(), "error should match")
})
}
}