MCPcopy
hub / github.com/btcsuite/btcd / TestStack

Function TestStack

txscript/stack_test.go:48–950  ·  view source on GitHub ↗

TestStack tests that all of the stack operations work as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

46
47// TestStack tests that all of the stack operations work as expected.
48func TestStack(t *testing.T) {
49 t.Parallel()
50
51 tests := []struct {
52 name string
53 before [][]byte
54 operation func(*stack) error
55 err error
56 after [][]byte
57 }{
58 {
59 "noop",
60 [][]byte{{1}, {2}, {3}, {4}, {5}},
61 func(s *stack) error {
62 return nil
63 },
64 nil,
65 [][]byte{{1}, {2}, {3}, {4}, {5}},
66 },
67 {
68 "peek underflow (byte)",
69 [][]byte{{1}, {2}, {3}, {4}, {5}},
70 func(s *stack) error {
71 _, err := s.PeekByteArray(5)
72 return err
73 },
74 scriptError(ErrInvalidStackOperation, ""),
75 nil,
76 },
77 {
78 "peek underflow (int)",
79 [][]byte{{1}, {2}, {3}, {4}, {5}},
80 func(s *stack) error {
81 _, err := s.PeekInt(5)
82 return err
83 },
84 scriptError(ErrInvalidStackOperation, ""),
85 nil,
86 },
87 {
88 "peek underflow (bool)",
89 [][]byte{{1}, {2}, {3}, {4}, {5}},
90 func(s *stack) error {
91 _, err := s.PeekBool(5)
92 return err
93 },
94 scriptError(ErrInvalidStackOperation, ""),
95 nil,
96 },
97 {
98 "pop",
99 [][]byte{{1}, {2}, {3}, {4}, {5}},
100 func(s *stack) error {
101 val, err := s.PopByteArray()
102 if err != nil {
103 return err
104 }
105 if !bytes.Equal(val, []byte{5}) {

Callers

nothing calls this directly

Calls 15

PeekByteArrayMethod · 0.95
PeekIntMethod · 0.95
PeekBoolMethod · 0.95
PopByteArrayMethod · 0.95
PopBoolMethod · 0.95
PopIntMethod · 0.95
PushIntMethod · 0.95
DupNMethod · 0.95
PushBoolMethod · 0.95
NipNMethod · 0.95
TuckMethod · 0.95
DropNMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…