This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontract_store_test.go
103 lines (93 loc) · 2.27 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
package seth_test
import (
"testing"
"github.com/pkg/errors"
"github.com/smartcontractkit/seth"
"github.com/stretchr/testify/require"
)
func TestSmokeContractABIStore(t *testing.T) {
type test struct {
name string
abiPath string
err string
}
tests := []test{
{
name: "can load the ABI",
abiPath: "./contracts/abi",
},
{
name: "can't open the ABI path",
abiPath: "dasdsadd",
err: "open dasdsadd: no such file or directory",
},
{
name: "empty ABI dir",
abiPath: "./contracts/emptyContractDir",
},
{
name: "invalid ABI inside dir",
abiPath: "./contracts/invalidContractDir",
err: "failed to parse ABI file: invalid character ':' after array element",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var err error
cs, err := seth.NewContractStore(tc.abiPath, tc.abiPath)
if err == nil {
require.NotNil(t, cs.ABIs, "ABIs should not be nil")
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'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",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var err error
cs, err := seth.NewContractStore(tc.abiPath, tc.binPath)
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")
})
}
}