mirror of
https://github.com/planetmint/planetmint.git
synced 2026-03-03 16:00:21 +00:00
Ipld (#256)
* added ipld dep Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * Cid tx schema (#252) * changed asset and metadata schema to string Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * updated fixtures and adjusted some models and test cases Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * adjusted dependencies, fixtures and added comments Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * alignd TX inputs to be CID compatible Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * converted assets to CIDs Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * added multihashes Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * fixed data packaging for IPLD compatible test cases for the unit tests Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * Transaction hierarchy (#254) * removed Transaction class from models.py, adjusted imports and function calls Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * removed comments Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * removed empty lines Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * resolved linting error Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * adjusted import path Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added missing argument to mock Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * resolved linting error Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * adjusted mock func signature Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * fixed all unit tests Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * fixed zenroom acceptance test Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * adjusted common tx schema, fixed election validate Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * fixed an planetmint-ipld dependency that solved a package namespace collision in the dependencies of IPLD Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * disabled integration and acceptance tests as they rely on planetmint driver. Plan is to resolve this circular dependency Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * adjusted acceptance tests to IPLD requirements Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * blackified Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * added missing imports Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> * blackified little changes Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com> Co-authored-by: Jürgen Eckel <eckelj@users.noreply.github.com> * increased version enforce ipld encodings to metadata and asset["data"] Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com> Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> Co-authored-by: Lorenz Herzberger <64837895+LaurentMontBlanc@users.noreply.github.com>
This commit is contained in:
@@ -17,3 +17,4 @@ RUN pip install --upgrade \
|
||||
planetmint-driver>=0.9.2 \
|
||||
blns
|
||||
RUN pip install base58>=2.1.1 pynacl==1.4.0 zenroom==2.1.0.dev1655293214 pyasn1==0.4.8 cryptography==3.4.7
|
||||
RUN pip install planetmint-ipld>=0.0.3
|
||||
|
||||
@@ -23,6 +23,7 @@ import os
|
||||
# For this test case we import and use the Python Driver.
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from ipld import multihash, marshal
|
||||
|
||||
|
||||
def test_get_tests():
|
||||
@@ -41,7 +42,7 @@ def test_get_tests():
|
||||
# ## Alice registers her bike in Planetmint
|
||||
# Alice has a nice bike, and here she creates the "digital twin"
|
||||
# of her bike.
|
||||
bike = {"data": {"bicycle": {"serial_number": 420420}}}
|
||||
bike = {"data": multihash(marshal({"bicycle": {"serial_number": 420420}}))}
|
||||
|
||||
# She prepares a `CREATE` transaction...
|
||||
prepared_creation_tx = bdb.transactions.prepare(operation="CREATE", signers=alice.public_key, asset=bike)
|
||||
|
||||
@@ -23,6 +23,7 @@ import os
|
||||
# For this test case we import and use the Python Driver.
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from ipld import multihash, marshal
|
||||
|
||||
|
||||
def test_basic():
|
||||
@@ -41,7 +42,7 @@ def test_basic():
|
||||
# ## Alice registers her bike in Planetmint
|
||||
# Alice has a nice bike, and here she creates the "digital twin"
|
||||
# of her bike.
|
||||
bike = {"data": {"bicycle": {"serial_number": 420420}}}
|
||||
bike = {"data": multihash(marshal({"bicycle": {"serial_number": 420420}}))}
|
||||
|
||||
# She prepares a `CREATE` transaction...
|
||||
prepared_creation_tx = bdb.transactions.prepare(operation="CREATE", signers=alice.public_key, asset=bike)
|
||||
|
||||
@@ -28,6 +28,7 @@ from planetmint_driver.exceptions import BadRequest
|
||||
# For this test case we import and use the Python Driver.
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from ipld import multihash, marshal
|
||||
|
||||
|
||||
def test_divisible_assets():
|
||||
@@ -48,10 +49,14 @@ def test_divisible_assets():
|
||||
# the bike for one hour.
|
||||
|
||||
bike_token = {
|
||||
"data": {
|
||||
"token_for": {"bike": {"serial_number": 420420}},
|
||||
"description": "Time share token. Each token equals one hour of riding.",
|
||||
},
|
||||
"data": multihash(
|
||||
marshal(
|
||||
{
|
||||
"token_for": {"bike": {"serial_number": 420420}},
|
||||
"description": "Time share token. Each token equals one hour of riding.",
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
# She prepares a `CREATE` transaction and issues 10 tokens.
|
||||
|
||||
@@ -14,6 +14,7 @@ import queue
|
||||
import planetmint_driver.exceptions
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from ipld import multihash, marshal
|
||||
|
||||
|
||||
def test_double_create():
|
||||
@@ -23,7 +24,9 @@ def test_double_create():
|
||||
results = queue.Queue()
|
||||
|
||||
tx = bdb.transactions.fulfill(
|
||||
bdb.transactions.prepare(operation="CREATE", signers=alice.public_key, asset={"data": {"uuid": str(uuid4())}}),
|
||||
bdb.transactions.prepare(
|
||||
operation="CREATE", signers=alice.public_key, asset={"data": multihash(marshal({"uuid": str(uuid4())}))}
|
||||
),
|
||||
private_keys=alice.private_key,
|
||||
)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import os
|
||||
# For this test case we import and use the Python Driver.
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from ipld import multihash, marshal
|
||||
|
||||
|
||||
def test_multiple_owners():
|
||||
@@ -41,7 +42,7 @@ def test_multiple_owners():
|
||||
# high rents anymore. Bob suggests to get a dish washer for the
|
||||
# kitchen. Alice agrees and here they go, creating the asset for their
|
||||
# dish washer.
|
||||
dw_asset = {"data": {"dish washer": {"serial_number": 1337}}}
|
||||
dw_asset = {"data": multihash(marshal({"dish washer": {"serial_number": 1337}}))}
|
||||
|
||||
# They prepare a `CREATE` transaction. To have multiple owners, both
|
||||
# Bob and Alice need to be the recipients.
|
||||
|
||||
@@ -29,6 +29,7 @@ import pytest
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from planetmint_driver.exceptions import BadRequest
|
||||
from ipld import multihash, marshal
|
||||
|
||||
naughty_strings = blns.all()
|
||||
skipped_naughty_strings = [
|
||||
@@ -118,8 +119,8 @@ def send_naughty_tx(asset, metadata):
|
||||
@pytest.mark.parametrize("naughty_string", naughty_strings, ids=naughty_strings)
|
||||
def test_naughty_keys(naughty_string):
|
||||
|
||||
asset = {"data": {naughty_string: "nice_value"}}
|
||||
metadata = {naughty_string: "nice_value"}
|
||||
asset = {"data": multihash(marshal({naughty_string: "nice_value"}))}
|
||||
metadata = multihash(marshal({naughty_string: "nice_value"}))
|
||||
|
||||
send_naughty_tx(asset, metadata)
|
||||
|
||||
@@ -127,7 +128,7 @@ def test_naughty_keys(naughty_string):
|
||||
@pytest.mark.parametrize("naughty_string", naughty_strings, ids=naughty_strings)
|
||||
def test_naughty_values(naughty_string):
|
||||
|
||||
asset = {"data": {"nice_key": naughty_string}}
|
||||
metadata = {"nice_key": naughty_string}
|
||||
asset = {"data": multihash(marshal({"nice_key": naughty_string}))}
|
||||
metadata = multihash(marshal({"nice_key": naughty_string}))
|
||||
|
||||
send_naughty_tx(asset, metadata)
|
||||
|
||||
@@ -21,6 +21,7 @@ import queue
|
||||
import json
|
||||
from threading import Thread, Event
|
||||
from uuid import uuid4
|
||||
from ipld import multihash, marshal
|
||||
|
||||
# For this script, we need to set up a websocket connection, that's the reason
|
||||
# we import the
|
||||
@@ -91,7 +92,9 @@ def test_stream():
|
||||
for _ in range(10):
|
||||
tx = bdb.transactions.fulfill(
|
||||
bdb.transactions.prepare(
|
||||
operation="CREATE", signers=alice.public_key, asset={"data": {"uuid": str(uuid4())}}
|
||||
operation="CREATE",
|
||||
signers=alice.public_key,
|
||||
asset={"data": multihash(marshal({"uuid": str(uuid4())}))},
|
||||
),
|
||||
private_keys=alice.private_key,
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ from cryptoconditions.types.zenroom import ZenroomSha256
|
||||
from zenroom import zencode_exec
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from ipld import multihash, marshal
|
||||
|
||||
|
||||
def test_zenroom_signing(
|
||||
@@ -66,8 +67,8 @@ def test_zenroom_signing(
|
||||
metadata = {"result": {"output": ["ok"]}}
|
||||
|
||||
script_ = {
|
||||
"code": {"type": "zenroom", "raw": "test_string", "parameters": [{"obj": "1"}, {"obj": "2"}]},
|
||||
"state": "dd8bbd234f9869cab4cc0b84aa660e9b5ef0664559b8375804ee8dce75b10576",
|
||||
"code": {"type": "zenroom", "raw": "test_string", "parameters": [{"obj": "1"}, {"obj": "2"}]}, # obsolete
|
||||
"state": "dd8bbd234f9869cab4cc0b84aa660e9b5ef0664559b8375804ee8dce75b10576", #
|
||||
"input": zenroom_script_input,
|
||||
"output": ["ok"],
|
||||
"policies": {},
|
||||
@@ -75,9 +76,9 @@ def test_zenroom_signing(
|
||||
|
||||
token_creation_tx = {
|
||||
"operation": "CREATE",
|
||||
"asset": {"data": {"test": "my asset"}},
|
||||
"asset": {"data": multihash(marshal({"test": "my asset"}))},
|
||||
"metadata": multihash(marshal(metadata)),
|
||||
"script": script_,
|
||||
"metadata": metadata,
|
||||
"outputs": [
|
||||
output,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user