MCPcopy Create free account
hub / github.com/copernet/copernicus / TestScript_PushSingleData

Function TestScript_PushSingleData

model/script/script_test.go:848–891  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

846}
847
848func TestScript_PushSingleData(t *testing.T) {
849 tests := []struct {
850 in []byte
851 wantScriptData []byte
852 wantError error
853 description string
854 }{
855 {nil, []byte{0x00}, nil, "Nil data to test."},
856 {
857 bytes.Repeat([]byte{0x00}, OP_PUSHDATA1),
858 combineBytes([]byte{0x4c, 0x4c}, bytes.Repeat([]byte{0x00}, 0x4c)),
859 nil,
860 "Push 0X4c data to test.",
861 },
862 {
863 bytes.Repeat([]byte{0x00}, 0xff),
864 combineBytes([]byte{0x4c, 0xff}, bytes.Repeat([]byte{0x00}, 0xff)),
865 nil,
866 "Push 0xff data to test.",
867 },
868 {
869 bytes.Repeat([]byte{0x00}, 0xffff),
870 combineBytes([]byte{0x4d, 0xff, 0xff}, bytes.Repeat([]byte{0x00}, 0xffff)),
871 nil,
872 "Push 0xffff data to test.",
873 },
874 {
875 bytes.Repeat([]byte{0x00}, 0x010000),
876 combineBytes([]byte{0x4e, 0x00, 0x00, 0x01, 0x00}, bytes.Repeat([]byte{0x00}, 0x010000)),
877 nil,
878 "Push 0x010000 data to test.",
879 },
880 }
881
882 for _, v := range tests {
883 value := v
884
885 nullScript := NewEmptyScript()
886 err := nullScript.PushSingleData(value.in)
887 assert.Equal(t, value.wantError, err, value.description)
888 data := nullScript.Bytes()
889 assert.Equal(t, hex.EncodeToString(value.wantScriptData), hex.EncodeToString(data), value.description)
890 }
891}
892
893func combineBytes(pBytes ...[]byte) []byte {
894 return bytes.Join(pBytes, []byte{})

Callers

nothing calls this directly

Calls 5

combineBytesFunction · 0.85
NewEmptyScriptFunction · 0.85
PushSingleDataMethod · 0.80
EqualMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected