File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,22 @@ func (s *ScriptRef) UnmarshalCBOR(data []byte) error {
8282 return nil
8383}
8484
85+ func (s * ScriptRef ) MarshalCBOR () ([]byte , error ) {
86+ tmpData := []any {
87+ s .Type ,
88+ s .Script ,
89+ }
90+ tmpDataCbor , err := cbor .Encode (tmpData )
91+ if err != nil {
92+ return nil , err
93+ }
94+ tmpTag := cbor.Tag {
95+ Number : 24 ,
96+ Content : tmpDataCbor ,
97+ }
98+ return cbor .Encode (tmpTag )
99+ }
100+
85101type PlutusV1Script []byte
86102
87103func (PlutusV1Script ) isScript () {}
Original file line number Diff line number Diff line change @@ -23,9 +23,10 @@ import (
2323 "github.com/blinklabs-io/gouroboros/ledger/common"
2424)
2525
26- func TestScriptRefDecode (t * testing.T ) {
26+ func TestScriptRefDecodeEncode (t * testing.T ) {
2727 // 24_0(<<[3, h'480123456789abcdef']>>)
28- testCbor , _ := hex .DecodeString ("d8184c820349480123456789abcdef" )
28+ testCborHex := "d8184c820349480123456789abcdef"
29+ testCbor , _ := hex .DecodeString (testCborHex )
2930 scriptCbor , _ := hex .DecodeString ("480123456789abcdef" )
3031 expectedScript := common .PlutusV3Script (scriptCbor )
3132 var testScriptRef common.ScriptRef
@@ -39,6 +40,13 @@ func TestScriptRefDecode(t *testing.T) {
3940 & expectedScript ,
4041 )
4142 }
43+ scriptRefCbor , err := cbor .Encode (testScriptRef )
44+ if err != nil {
45+ t .Fatalf ("unexpected error: %s" , err )
46+ }
47+ if hex .EncodeToString (scriptRefCbor ) != testCborHex {
48+ t .Fatalf ("did not get expected CBOR\n got: %x\n wanted: %s" , scriptRefCbor , testCborHex )
49+ }
4250}
4351
4452func TestNativeScriptHash (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments