forked from OffchainLabs/fastssz
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrapper_test.go
More file actions
59 lines (53 loc) · 1.29 KB
/
wrapper_test.go
File metadata and controls
59 lines (53 loc) · 1.29 KB
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
package ssz
import (
"bytes"
"go/ast"
"go/parser"
"go/token"
"testing"
)
type wrapperSlot uint64
func TestAddUintAcceptsNamedUint64(t *testing.T) {
var w Wrapper
AddUint(&w, wrapperSlot(7))
want := make([]byte, 32)
want[0] = 7
if len(w.nodes) != 1 || !bytes.Equal(w.nodes[0].value, want) {
t.Fatalf("unexpected node value: %v", w.nodes)
}
}
func TestDeprecatedAddWrappersCallAddUint(t *testing.T) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "wrapper.go", nil, 0)
if err != nil {
t.Fatal(err)
}
for _, name := range []string{"AddUint64", "AddUint32", "AddUint16", "AddUint8"} {
found := false
for _, decl := range file.Decls {
fn, ok := decl.(*ast.FuncDecl)
if !ok || fn.Name.Name != name {
continue
}
found = true
if len(fn.Body.List) != 1 {
t.Fatalf("expected %s to have exactly one statement", name)
}
exprStmt, ok := fn.Body.List[0].(*ast.ExprStmt)
if !ok {
t.Fatalf("expected %s to delegate with a direct call", name)
}
call, ok := exprStmt.X.(*ast.CallExpr)
if !ok {
t.Fatalf("expected %s body to be a call", name)
}
ident, ok := call.Fun.(*ast.Ident)
if !ok || ident.Name != "AddUint" {
t.Fatalf("expected %s to call AddUint", name)
}
}
if !found {
t.Fatalf("did not find %s", name)
}
}
}