@@ -17,6 +17,7 @@ package common
17
17
import (
18
18
"encoding/hex"
19
19
"encoding/json"
20
+ "math/big"
20
21
"reflect"
21
22
"testing"
22
23
@@ -128,6 +129,90 @@ func TestMultiAssetJson(t *testing.T) {
128
129
}
129
130
}
130
131
132
+ func TestMultiAssetToPlutusData (t * testing.T ) {
133
+ testDefs := []struct {
134
+ multiAssetObj any
135
+ expectedData data.PlutusData
136
+ }{
137
+ {
138
+ multiAssetObj : MultiAsset [MultiAssetTypeOutput ]{
139
+ data : map [Blake2b224 ]map [cbor.ByteString ]MultiAssetTypeOutput {
140
+ NewBlake2b224 (test .DecodeHexString ("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61" )): {
141
+ cbor .NewByteString (test .DecodeHexString ("6675726e697368613239686e" )): 123456 ,
142
+ },
143
+ },
144
+ },
145
+ expectedData : data .NewMap (
146
+ [][2 ]data.PlutusData {
147
+ {
148
+ data .NewByteString (test .DecodeHexString ("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61" )),
149
+ data .NewMap (
150
+ [][2 ]data.PlutusData {
151
+ {
152
+ data .NewByteString (test .DecodeHexString ("6675726e697368613239686e" )),
153
+ data .NewInteger (big .NewInt (123456 )),
154
+ },
155
+ },
156
+ ),
157
+ },
158
+ },
159
+ ),
160
+ },
161
+ {
162
+ multiAssetObj : MultiAsset [MultiAssetTypeOutput ]{
163
+ data : map [Blake2b224 ]map [cbor.ByteString ]MultiAssetTypeOutput {
164
+ NewBlake2b224 (test .DecodeHexString ("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61" )): {
165
+ cbor .NewByteString (test .DecodeHexString ("6675726e697368613239686e" )): 123456 ,
166
+ },
167
+ NewBlake2b224 (test .DecodeHexString ("eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5" )): {
168
+ cbor .NewByteString (test .DecodeHexString ("426f7764757261436f6e63657074733638" )): 234567 ,
169
+ },
170
+ },
171
+ },
172
+ expectedData : data .NewMap (
173
+ [][2 ]data.PlutusData {
174
+ {
175
+ data .NewByteString (test .DecodeHexString ("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61" )),
176
+ data .NewMap (
177
+ [][2 ]data.PlutusData {
178
+ {
179
+ data .NewByteString (test .DecodeHexString ("6675726e697368613239686e" )),
180
+ data .NewInteger (big .NewInt (123456 )),
181
+ },
182
+ },
183
+ ),
184
+ },
185
+ {
186
+ data .NewByteString (test .DecodeHexString ("eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5" )),
187
+ data .NewMap (
188
+ [][2 ]data.PlutusData {
189
+ {
190
+ data .NewByteString (test .DecodeHexString ("426f7764757261436f6e63657074733638" )),
191
+ data .NewInteger (big .NewInt (234567 )),
192
+ },
193
+ },
194
+ ),
195
+ },
196
+ },
197
+ ),
198
+ },
199
+ }
200
+ for _ , testDef := range testDefs {
201
+ var tmpData data.PlutusData
202
+ switch v := testDef .multiAssetObj .(type ) {
203
+ case MultiAsset [MultiAssetTypeOutput ]:
204
+ tmpData = v .ToPlutusData ()
205
+ case MultiAsset [MultiAssetTypeMint ]:
206
+ tmpData = v .ToPlutusData ()
207
+ default :
208
+ t .Fatalf ("test def multi-asset object was not expected type: %T" , v )
209
+ }
210
+ if ! reflect .DeepEqual (tmpData , testDef .expectedData ) {
211
+ t .Fatalf ("did not get expected PlutusData\n got: %#v\n wanted: %#v" , tmpData , testDef .expectedData )
212
+ }
213
+ }
214
+ }
215
+
131
216
func TestMultiAssetCompare (t * testing.T ) {
132
217
testDefs := []struct {
133
218
asset1 * MultiAsset [MultiAssetTypeOutput ]
0 commit comments