-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage_test.go
165 lines (142 loc) · 4.27 KB
/
storage_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
package standards
import (
"github.com/unpackdev/standards/shared"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
eip_pb "github.com/unpackdev/protos/dist/go/eip"
)
func TestEIPStorage(t *testing.T) {
// Register all EIPs.
assert.NoError(t, LoadStandards())
// Test non existing yet standard...
s, err := GetContractByStandard("CORRUPTED")
assert.Error(t, err)
assert.Nil(t, s)
unknown := shared.Standard("NOT_DEFINED_YET")
assert.Equal(t, unknown.ToProto(), eip_pb.Standard_UNKNOWN)
tests := []struct {
name string
standard shared.EIP
expectedExists bool
isStagnant bool
expectedError string
}{
{
name: "Test ERC20",
standard: func() shared.EIP {
standard, err := GetContractByStandard(ERC20)
assert.NoError(t, err)
assert.NotNil(t, standard)
return standard
}(),
expectedExists: true,
expectedError: "standard ERC20 already exists",
},
{
name: "Test ERC721",
standard: func() shared.EIP {
standard, err := GetContractByStandard(ERC721)
assert.NoError(t, err)
assert.NotNil(t, standard)
return standard
}(),
expectedExists: true,
expectedError: "standard ERC721 already exists",
},
{
name: "Test ERC1155",
standard: func() shared.EIP {
standard, err := GetContractByStandard(ERC1155)
assert.NoError(t, err)
assert.NotNil(t, standard)
return standard
}(),
expectedExists: true,
expectedError: "standard ERC1155 already exists",
},
{
name: "Test ERC1820",
standard: func() shared.EIP {
standard, err := GetContractByStandard(ERC1820)
assert.NoError(t, err)
assert.NotNil(t, standard)
return standard
}(),
expectedExists: true,
expectedError: "standard ERC1820 already exists",
},
{
name: "Test ERC1822",
standard: func() shared.EIP {
standard, err := GetContractByStandard(ERC1822)
assert.NoError(t, err)
assert.NotNil(t, standard)
return standard
}(),
expectedExists: true,
isStagnant: true,
expectedError: "standard ERC1822 already exists",
},
{
name: "Test ERC1967",
standard: func() shared.EIP {
standard, err := GetContractByStandard(ERC1967)
assert.NoError(t, err)
assert.NotNil(t, standard)
return standard
}(),
expectedExists: true,
expectedError: "standard ERC1967 already exists",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Check if all methods of the EIP interface are implemented
eipType := reflect.TypeOf((*shared.EIP)(nil)).Elem()
assert.True(t, reflect.TypeOf(tt.standard).Implements(eipType), "EIP methods not fully implemented")
// Test GetName
assert.NotEmpty(t, tt.standard.GetName())
// Test GetType
assert.NotNil(t, tt.standard.GetType())
// Test GetUrl
assert.NotEmpty(t, tt.standard.GetUrl())
// Test GetFunctions
assert.NotEmpty(t, tt.standard.GetFunctions())
// Test GetEvents
assert.NotEmpty(t, tt.standard.GetEvents())
// Test GetStandard
assert.NotNil(t, tt.standard.GetStandard())
// Test TokenCount
assert.GreaterOrEqual(t, tt.standard.TokenCount(), 0)
// Test IsStagnant
assert.Equal(t, tt.isStagnant, tt.standard.IsStagnant())
// Test GetABI
assert.NotEmpty(t, tt.standard.GetABI(), "ABI is empty")
// Test ToProto
assert.NotNil(t, tt.standard.ToProto())
// Test String representation
assert.NotEmpty(t, tt.standard.String())
// Test RegisterStandard
err := RegisterStandard(tt.standard.GetType(), tt.standard)
if tt.expectedError == "" {
assert.NoError(t, err)
} else {
assert.EqualError(t, err, tt.expectedError)
}
// Test Exists
exists := Exists(tt.standard.GetType())
assert.Equal(t, tt.expectedExists, exists)
// Test GetRegisteredStandards
registeredStandards := GetRegisteredStandards()
_, ok := registeredStandards[tt.standard.GetType()]
assert.True(t, ok, "standard %v not found in registered standards", tt.standard.GetType())
standard, bool := GetStandard(tt.standard.GetType())
assert.True(t, bool, "standard %v not found in registered standards", tt.standard.GetType())
assert.NotNil(t, standard)
assert.Equal(t, tt.standard.GetStandard(), standard.GetStandard())
assert.NotNil(t, GetSortedRegisteredStandards())
assert.True(t, StandardsLoaded())
})
}
}