1212from cryptoconditions import Ed25519Sha256
1313from pytest import fixture
1414from sha3 import sha3_256
15+ from ipld import multihash , marshal
1516
1617from planetmint_driver .common .transaction import Transaction , _fulfillment_to_details
1718
@@ -232,7 +233,7 @@ def alice_transaction_obj(alice_pubkey):
232233 return Transaction .create (
233234 tx_signers = [alice_pubkey ],
234235 recipients = [([alice_pubkey ], 1 )],
235- asset = {"serial_number" : serial_number },
236+ asset = {"data" : multihash ( marshal ({ " serial_number" : serial_number })) },
236237 )
237238
238239
@@ -263,7 +264,7 @@ def persisted_random_transaction(alice_pubkey, alice_privkey):
263264 from uuid import uuid4
264265 from planetmint_driver .common .transaction import Transaction
265266
266- asset = {"data" : {"x" : str (uuid4 ())}}
267+ asset = {"data" : multihash ( marshal ( {"x" : str (uuid4 ())})) }
267268 tx = Transaction .create (
268269 tx_signers = [alice_pubkey ],
269270 recipients = [([alice_pubkey ], 1 )],
@@ -277,7 +278,7 @@ def sent_persisted_random_transaction(alice_pubkey, alice_privkey, transactions_
277278 from uuid import uuid4
278279 from planetmint_driver .common .transaction import Transaction
279280
280- asset = {"data" : {"x" : str (uuid4 ())}}
281+ asset = {"data" : multihash ( marshal ( {"x" : str (uuid4 ())})) }
281282 tx = Transaction .create (
282283 tx_signers = [alice_pubkey ],
283284 recipients = [([alice_pubkey ], 1 )],
@@ -322,7 +323,7 @@ def prepared_carol_bicycle_transaction(carol_keypair, bicycle_data):
322323 fulfillment = make_fulfillment (carol_keypair .public_key )
323324 tx = {
324325 "asset" : {
325- "data" : bicycle_data ,
326+ "data" : multihash ( marshal ( bicycle_data )) ,
326327 },
327328 "metadata" : None ,
328329 "operation" : "CREATE" ,
@@ -360,7 +361,7 @@ def prepared_carol_car_transaction(carol_keypair, car_data):
360361 fulfillment = make_fulfillment (carol_keypair .public_key )
361362 tx = {
362363 "asset" : {
363- "data" : car_data ,
364+ "data" : multihash ( marshal ( car_data )) ,
364365 },
365366 "metadata" : None ,
366367 "operation" : "CREATE" ,
@@ -515,7 +516,7 @@ def persisted_transfer_dimi_car_to_ewy(
515516def unsigned_transaction ():
516517 return {
517518 "operation" : "CREATE" ,
518- "asset" : {"data" : {"serial_number" : "NNP43x-DaYoSWg==" }},
519+ "asset" : {"data" : multihash ( marshal ( {"serial_number" : "NNP43x-DaYoSWg==" })) },
519520 "version" : "2.0" ,
520521 "outputs" : [
521522 {
@@ -546,7 +547,17 @@ def unsigned_transaction():
546547
547548
548549@fixture
549- def text_search_assets (api_root , transactions_api_full_url , alice_pubkey , alice_privkey ):
550+ def search_assets ():
551+ assets = [
552+ {"data" : multihash (marshal ({"msg" : "Hello Planetmint 1!" }))},
553+ {"data" : multihash (marshal ({"msg" : "Hello Planetmint 2!" }))},
554+ {"data" : multihash (marshal ({"msg" : "Hello Planetmint 3!" }))},
555+ ]
556+ return assets
557+
558+
559+ @fixture
560+ def text_search_assets (api_root , transactions_api_full_url , alice_pubkey , alice_privkey , search_assets ):
550561 # check if the fixture was already executed
551562 response = requests .get (api_root + "/assets" , params = {"search" : "planetmint" })
552563 response = response .json ()
@@ -557,20 +568,15 @@ def text_search_assets(api_root, transactions_api_full_url, alice_pubkey, alice_
557568 return assets
558569
559570 # define the assets that will be used by text_search tests
560- assets = [
561- {"msg" : "Hello Planetmint 1!" },
562- {"msg" : "Hello Planetmint 2!" },
563- {"msg" : "Hello Planetmint 3!" },
564- ]
565571
566572 # write the assets to Planetmint
567573 assets_by_txid = {}
568- for asset in assets :
574+ for asset in search_assets :
569575 tx = Transaction .create (
570576 tx_signers = [alice_pubkey ],
571577 recipients = [([alice_pubkey ], 1 )],
572578 asset = asset ,
573- metadata = { "But here's my number" : " So call me maybe"} ,
579+ metadata = " So call me maybe" ,
574580 )
575581 tx_signed = tx .sign ([alice_privkey ])
576582 requests .post (transactions_api_full_url , json = tx_signed .to_dict ())
0 commit comments