-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheoa_test.go
More file actions
76 lines (58 loc) · 1.53 KB
/
Copy patheoa_test.go
File metadata and controls
76 lines (58 loc) · 1.53 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2023-2026 Onur Cinar.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// https://github.com/cinar/checker
package v2_test
import (
"errors"
"testing"
v2 "github.com/cinar/checker/v2"
)
func TestIsEOASuccess(t *testing.T) {
value := "0x71C7656EC7ab88b098defB751B7401B5f6d8976F"
result, err := v2.IsEOA(value)
if err != nil {
t.Fatal(err)
}
if result != value {
t.Fatalf("actual %s expected %s", result, value)
}
}
func TestIsEOAMissingPrefix(t *testing.T) {
_, err := v2.IsEOA("71C7656EC7ab88b098defB751B7401B5f6d8976")
if !errors.Is(err, v2.ErrNotEOA) {
t.Fatalf("got unexpected error %v", err)
}
}
func TestIsEOAWrongLength(t *testing.T) {
_, err := v2.IsEOA("0x71C7656EC7ab88b098defB751B7401B5f6d897")
if !errors.Is(err, v2.ErrNotEOA) {
t.Fatalf("got unexpected error %v", err)
}
}
func TestIsEOANotHex(t *testing.T) {
_, err := v2.IsEOA("0xzzC7656EC7ab88b098defB751B7401B5f6d8976")
if !errors.Is(err, v2.ErrNotEOA) {
t.Fatalf("got unexpected error %v", err)
}
}
func TestCheckStructEOA(t *testing.T) {
type Wallet struct {
Address string `checkers:"eoa"`
}
wallet := &Wallet{
Address: "not-an-address",
}
errs, ok := v2.CheckStruct(wallet)
if ok {
t.Fatal("expected errors")
}
if !errors.Is(errs["Address"], v2.ErrNotEOA) {
t.Fatalf("expected address not EOA %v", errs)
}
wallet.Address = "0x71C7656EC7ab88b098defB751B7401B5f6d8976F"
errs, ok = v2.CheckStruct(wallet)
if !ok {
t.Fatalf("got unexpected errors %v", errs)
}
}