MCPcopy
hub / github.com/OffchainLabs/prysm / TestSafeCopyRootAtIndex

Function TestSafeCopyRootAtIndex

encoding/bytesutil/bytes_test.go:48–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestSafeCopyRootAtIndex(t *testing.T) {
49 tests := []struct {
50 name string
51 input [][]byte
52 idx uint64
53 want []byte
54 wantErr bool
55 }{
56 {
57 name: "index out of range in non-empty slice",
58 input: [][]byte{{0x1}, {0x2}},
59 idx: 2,
60 wantErr: true,
61 },
62 {
63 name: "index out of range in empty slice",
64 input: [][]byte{},
65 idx: 0,
66 wantErr: true,
67 },
68 {
69 name: "nil input",
70 input: nil,
71 idx: 3,
72 want: nil,
73 },
74 {
75 name: "correct copy",
76 input: [][]byte{{0x1}, {0x2}},
77 idx: 1,
78 want: bytesutil.PadTo([]byte{0x2}, 32),
79 },
80 }
81 for _, tt := range tests {
82 t.Run(tt.name, func(t *testing.T) {
83 got, err := bytesutil.SafeCopyRootAtIndex(tt.input, tt.idx)
84 if (err != nil) != tt.wantErr {
85 t.Errorf("SafeCopyRootAtIndex() error = %v, wantErr %v", err, tt.wantErr)
86 return
87 }
88 if !reflect.DeepEqual(got, tt.want) {
89 t.Errorf("SafeCopyRootAtIndex() got = %v, want %v", got, tt.want)
90 }
91 })
92 }
93}
94
95func TestSafeCopy2dBytes(t *testing.T) {
96 tests := []struct {

Callers

nothing calls this directly

Calls 3

PadToFunction · 0.92
SafeCopyRootAtIndexFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected