-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompiler_test.go
60 lines (56 loc) · 1.44 KB
/
compiler_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
package huffc_test
import (
"errors"
"path/filepath"
"strconv"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sprintertech/go-huffc"
)
func TestCompilerCompile(t *testing.T) {
tests := []struct {
Filename string
Options *huffc.Options
WantContract *huffc.Contract
WantErr error
}{
{
Filename: "stop.huff",
WantContract: &huffc.Contract{
Runtime: []byte{0x00},
Constructor: []byte{0x60, 0x01, 0x80, 0x60, 0x09, 0x3d, 0x39, 0x3d, 0xf3, 0x00},
},
},
{
Filename: "push.huff",
WantContract: &huffc.Contract{
Runtime: []byte{0x5f},
Constructor: []byte{0x60, 0x01, 0x80, 0x60, 0x09, 0x3d, 0x39, 0x3d, 0xf3, 0x5f},
},
},
{
Filename: "push.huff",
Options: &huffc.Options{EVMVersion: huffc.EVMVersionParis},
WantContract: &huffc.Contract{
Runtime: []byte{0x60, 0x00},
Constructor: []byte{0x60, 0x02, 0x80, 0x60, 0x09, 0x3d, 0x39, 0x3d, 0xf3, 0x60, 0x00},
},
},
{
Filename: "error.huff",
WantErr: huffc.ErrCompilationFailed,
},
}
for i, test := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
c := huffc.New()
gotContract, gotErr := c.Compile(filepath.Join("testdata", test.Filename), test.Options)
if !errors.Is(gotErr, test.WantErr) {
t.Errorf("Err: want %v, got %v", test.WantErr, gotErr)
}
if diff := cmp.Diff(test.WantContract, gotContract); diff != "" {
t.Errorf("Contract (-want +got):\n%s", diff)
}
})
}
}