File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,31 @@ var testDefs = []struct {
224224 // {_ h'01': 1, h'02': 2}
225225 CborHex : "bf410101410202ff" ,
226226 },
227+ // Map with duplicate keys
228+ {
229+ Data : NewMapDefIndef (
230+ false ,
231+ [][2 ]PlutusData {
232+ {
233+ NewByteString ([]byte ("6Key" )),
234+ NewByteString ([]byte ("1" )),
235+ },
236+ {
237+ NewByteString ([]byte ("5Key" )),
238+ NewByteString ([]byte ("7" )),
239+ },
240+ {
241+ NewByteString ([]byte ("6Key" )),
242+ NewByteString (nil ),
243+ },
244+ {
245+ NewByteString ([]byte ("5Key" )),
246+ NewByteString (nil ),
247+ },
248+ },
249+ ),
250+ CborHex : "a444364b6579413144354b6579413744364b65794044354b657940" ,
251+ },
227252}
228253
229254func TestPlutusDataEncode (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -105,9 +105,10 @@ func decodeCborRawMap(data []byte) (any, error) {
105105 // The below is a hack to work around our CBOR library not supporting preserving key
106106 // order when decoding a map. We decode our map to determine its length, create a dummy
107107 // list the same length as our map to determine the header size, and then decode each
108- // key/value pair individually
108+ // key/value pair individually. We use a pointer for the key to keep duplicates to get
109+ // an accurate count for decoding
109110 useIndef := (data [0 ] & CborIndefFlag ) == CborIndefFlag
110- var tmpData map [RawMessageStr ]RawMessageStr
111+ var tmpData map [* RawMessageStr ]RawMessageStr
111112 if err := cborUnmarshal (data , & tmpData ); err != nil {
112113 return nil , err
113114 }
You can’t perform that action at this time.
0 commit comments