diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bf1455..075e16c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,4 @@ jobs: # Fail if poetry.lock is stale vs pyproject.toml; install what is committed. - run: poetry check --lock - run: poetry install - # No pytest suite yet; import-smoke the built package so CI fails fast - # on broken codegen/spec dependencies. - - run: poetry run python -c "import utxorpc" + - run: poetry run pytest diff --git a/poetry.lock b/poetry.lock index baface5..e3b1a08 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,36 @@ -# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.5.1 and should not be changed by hand. + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["dev"] +markers = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "exceptiongroup" +version = "1.3.1" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +groups = ["dev"] +markers = "python_version == \"3.10\"" +files = [ + {file = "exceptiongroup-1.3.1-py3-none-any.whl", hash = "sha256:a7a39a3bd276781e98394987d3a5701d0c4edffb633bb7a5144577f82c773598"}, + {file = "exceptiongroup-1.3.1.tar.gz", hash = "sha256:8b412432c6055b0b7d14c310000ae93352ed6754f70fa8f7c34141f91c4e3219"}, +] + +[package.dependencies] +typing-extensions = {version = ">=4.6.0", markers = "python_version < \"3.13\""} + +[package.extras] +test = ["pytest (>=6)"] [[package]] name = "grpc-stubs" @@ -92,6 +124,18 @@ typing-extensions = ">=4.12,<5.0" [package.extras] protobuf = ["grpcio-tools (>=1.84.0)"] +[[package]] +name = "iniconfig" +version = "2.3.1" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7"}, + {file = "iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960"}, +] + [[package]] name = "librt" version = "0.16.0" @@ -324,6 +368,18 @@ files = [ {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, ] +[[package]] +name = "packaging" +version = "26.3" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.9" +groups = ["dev"] +files = [ + {file = "packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c"}, + {file = "packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79"}, +] + [[package]] name = "pathspec" version = "1.1.1" @@ -341,6 +397,18 @@ hyperscan = ["hyperscan (>=0.7)"] optional = ["typing-extensions (>=4)"] re2 = ["google-re2 (>=1.1)"] +[[package]] +name = "pluggy" +version = "1.7.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.10" +groups = ["dev"] +files = [ + {file = "pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec"}, + {file = "pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8"}, +] + [[package]] name = "protobuf" version = "7.36.2" @@ -359,6 +427,45 @@ files = [ {file = "protobuf-7.36.2.tar.gz", hash = "sha256:497d0463ff3316681da6c0b9e8d06cb465d61abce00b613ab42226175644d1bb"}, ] +[[package]] +name = "pygments" +version = "2.21.0" +description = "Pygments is a syntax highlighting package written in Python." +optional = false +python-versions = ">=3.9" +groups = ["dev"] +files = [ + {file = "pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9"}, + {file = "pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c"}, +] + +[package.extras] +windows-terminal = ["colorama (>=0.4.6)"] + +[[package]] +name = "pytest" +version = "8.4.2" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.9" +groups = ["dev"] +files = [ + {file = "pytest-8.4.2-py3-none-any.whl", hash = "sha256:872f880de3fc3a5bdc88a11b39c9710c3497a547cfa9320bc3c5e62fbf272e79"}, + {file = "pytest-8.4.2.tar.gz", hash = "sha256:86c0d0b93306b961d58d62a4db4879f27fe25513d4b969df351abdddb3c30e01"}, +] + +[package.dependencies] +colorama = {version = ">=0.4", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1", markers = "python_version < \"3.11\""} +iniconfig = ">=1" +packaging = ">=20" +pluggy = ">=1.5,<2" +pygments = ">=2.7.2" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} + +[package.extras] +dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "requests", "setuptools", "xmlschema"] + [[package]] name = "ruff" version = "0.14.14" @@ -463,4 +570,4 @@ protobuf = ">=7.34.1,<8" [metadata] lock-version = "2.1" python-versions = ">=3.10,<4.0" -content-hash = "73e6548192de3272678fd65c7af2309e16ad4e67e7e79dae9a59f18c6594c7cf" +content-hash = "86f2b0c0b8b70240edcc5835b7ec7c338534b2748b29dcdb687657e99c798cfc" diff --git a/pyproject.toml b/pyproject.toml index 86062cf..5190d5f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ protobuf = "^7.34.1" [tool.poetry.group.dev.dependencies] mypy = "^1.18.2" ruff = "^0.14.3" +pytest = "^8.4" [[tool.poetry.source]] name = "pypi" diff --git a/tests/test_cardano_vectors.py b/tests/test_cardano_vectors.py new file mode 100644 index 0000000..ad9f05b --- /dev/null +++ b/tests/test_cardano_vectors.py @@ -0,0 +1,29 @@ +"""Decodes the Cardano vectors with the spec's generated types.""" + +import csv +from pathlib import Path + +import pytest +from utxorpc_spec.utxorpc.v1alpha.cardano import cardano_pb2 as v1alpha +from utxorpc_spec.utxorpc.v1beta.cardano import cardano_pb2 as v1beta + +VECTORS = Path(__file__).parent / "vectors" / "cardano" + +with open(VECTORS / "vectors.tsv", newline="") as index: + ROWS = list(csv.DictReader(index, delimiter="\t")) + + +@pytest.mark.parametrize("row", ROWS, ids=[row["name"] for row in ROWS]) +@pytest.mark.parametrize("version,module", [("v1alpha", v1alpha), ("v1beta", v1beta)]) +def test_decodes_vector(version, module, row): + raw = (VECTORS / version / f"{row['name']}.pb").read_bytes() + + block = module.Block() + block.ParseFromString(raw) + + assert block.header.slot == int(row["slot"]) + assert block.header.hash.hex() == row["hash"] + assert len(block.body.tx) == int(row["tx_count"]) + if row["first_tx_hash"] != "-": + assert block.body.tx[0].hash.hex() == row["first_tx_hash"] + assert block.SerializeToString(deterministic=True) == raw diff --git a/tests/vectors/cardano/README.md b/tests/vectors/cardano/README.md new file mode 100644 index 0000000..0dffacd --- /dev/null +++ b/tests/vectors/cardano/README.md @@ -0,0 +1,4 @@ +# Cardano vectors + +Copied from [`conformance/vectors/cardano`](https://github.com/utxorpc/u5c-factory/tree/main/conformance/vectors/cardano) +in u5c-factory, where the blocks, their sources and the generator live. Don't edit by hand. diff --git a/tests/vectors/cardano/v1alpha/babbage-v7.pb b/tests/vectors/cardano/v1alpha/babbage-v7.pb new file mode 100644 index 0000000..3e23911 Binary files /dev/null and b/tests/vectors/cardano/v1alpha/babbage-v7.pb differ diff --git a/tests/vectors/cardano/v1alpha/babbage-v8.pb b/tests/vectors/cardano/v1alpha/babbage-v8.pb new file mode 100644 index 0000000..ae36695 Binary files /dev/null and b/tests/vectors/cardano/v1alpha/babbage-v8.pb differ diff --git a/tests/vectors/cardano/v1alpha/conway-v10.pb b/tests/vectors/cardano/v1alpha/conway-v10.pb new file mode 100644 index 0000000..7e66939 Binary files /dev/null and b/tests/vectors/cardano/v1alpha/conway-v10.pb differ diff --git a/tests/vectors/cardano/v1alpha/conway-v11.pb b/tests/vectors/cardano/v1alpha/conway-v11.pb new file mode 100644 index 0000000..9512932 Binary files /dev/null and b/tests/vectors/cardano/v1alpha/conway-v11.pb differ diff --git a/tests/vectors/cardano/v1alpha/conway-v12.pb b/tests/vectors/cardano/v1alpha/conway-v12.pb new file mode 100644 index 0000000..a7b2ecf Binary files /dev/null and b/tests/vectors/cardano/v1alpha/conway-v12.pb differ diff --git a/tests/vectors/cardano/v1alpha/conway-v9.pb b/tests/vectors/cardano/v1alpha/conway-v9.pb new file mode 100644 index 0000000..e6db60b Binary files /dev/null and b/tests/vectors/cardano/v1alpha/conway-v9.pb differ diff --git a/tests/vectors/cardano/v1alpha/dijkstra-v12.pb b/tests/vectors/cardano/v1alpha/dijkstra-v12.pb new file mode 100644 index 0000000..86c4df5 Binary files /dev/null and b/tests/vectors/cardano/v1alpha/dijkstra-v12.pb differ diff --git a/tests/vectors/cardano/v1beta/babbage-v7.pb b/tests/vectors/cardano/v1beta/babbage-v7.pb new file mode 100644 index 0000000..8bf80f1 Binary files /dev/null and b/tests/vectors/cardano/v1beta/babbage-v7.pb differ diff --git a/tests/vectors/cardano/v1beta/babbage-v8.pb b/tests/vectors/cardano/v1beta/babbage-v8.pb new file mode 100644 index 0000000..c3eb7f0 Binary files /dev/null and b/tests/vectors/cardano/v1beta/babbage-v8.pb differ diff --git a/tests/vectors/cardano/v1beta/conway-v10.pb b/tests/vectors/cardano/v1beta/conway-v10.pb new file mode 100644 index 0000000..3728eb3 Binary files /dev/null and b/tests/vectors/cardano/v1beta/conway-v10.pb differ diff --git a/tests/vectors/cardano/v1beta/conway-v11.pb b/tests/vectors/cardano/v1beta/conway-v11.pb new file mode 100644 index 0000000..440e3ba Binary files /dev/null and b/tests/vectors/cardano/v1beta/conway-v11.pb differ diff --git a/tests/vectors/cardano/v1beta/conway-v12.pb b/tests/vectors/cardano/v1beta/conway-v12.pb new file mode 100644 index 0000000..a7b2ecf Binary files /dev/null and b/tests/vectors/cardano/v1beta/conway-v12.pb differ diff --git a/tests/vectors/cardano/v1beta/conway-v9.pb b/tests/vectors/cardano/v1beta/conway-v9.pb new file mode 100644 index 0000000..68a82f1 Binary files /dev/null and b/tests/vectors/cardano/v1beta/conway-v9.pb differ diff --git a/tests/vectors/cardano/v1beta/dijkstra-v12.pb b/tests/vectors/cardano/v1beta/dijkstra-v12.pb new file mode 100644 index 0000000..c169ec2 Binary files /dev/null and b/tests/vectors/cardano/v1beta/dijkstra-v12.pb differ diff --git a/tests/vectors/cardano/vectors.tsv b/tests/vectors/cardano/vectors.tsv new file mode 100644 index 0000000..f1606f4 --- /dev/null +++ b/tests/vectors/cardano/vectors.tsv @@ -0,0 +1,8 @@ +name era protocol slot hash tx_count first_tx_hash +babbage-v7 Babbage 7 1029948 0ee46e356d778433273365b895b1aea1a81f33db4cc80e05b6ffca33e0f8b83b 1 3fad302595665b004971a6b76909854a39a0a7ecdbff3692f37b77ae37dbe882 +babbage-v8 Babbage 8 1363368 16202fe98de909fda9156919633459ed2368bb2db28393c934acf36e52f2f66b 4 05337a1c2ce0e1d6714eb1dd993c733c50436682a3079e9ef0939f3d6819e3ba +conway-v10 Conway 10 31412056 1240f59bd88d16f4f6e425ae60935926985478965e37b73b5b85276625bcbe82 1 ea3d309d4ef836cf0aea7e2b5f70537ca82e647754958ff191d5162b55036838 +conway-v11 Conway 11 202315107 d03a37835e9f1ffb70e8a476334c69183ab5491c911faa7ea0d6ba285dd7c8b4 4 cec3db3a981bde28ca7396ee4611686f701184394a9ff3810adb51f1346a6415 +conway-v12 Conway 12 86373 802112126cc600a6afc5193a0150aafd9f6563bec28207df7e6c20cc62e95f8e 0 - +conway-v9 Conway 9 22075282 9b51ccd4f161c08382a445684ff3eb788923608acbea283081fa5ccf663fef8d 1 ed8431dbe32cff36814ee838a7a002152d43a7465faaf05529907717c793527a +dijkstra-v12 Dijkstra 12 285530 294b3df1e6758e6f17f2b5a09ed469c6ec37c2db4d274264c8ee5edabe31229a 1 5bff1759d143172c5fd1fddc9910f1a7a1ea2c1666f0d1f0299371f9fa889b7c