From c5975baea02d3e02f92513cc20085b0b1f090ecf Mon Sep 17 00:00:00 2001 From: notTanveer Date: Fri, 13 Nov 2026 18:59:35 +0530 Subject: [PATCH] test: run the test suite on MicroPython 1.11 in CI - Add tools/micropython_tests.sh to build the 1.11 unix port with the hashlib and secp256k1 usermods and run tests/run_tests.py - Pin micropython, f469-disco, secp256k1-embedded and secp256k1 by commit SHA - Add a micropython job to the CI workflow and require it before packaging --- .github/workflows/ci.yml | 12 ++++++++++ README.md | 8 ++++++- tools/micropython_tests.sh | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 tools/micropython_tests.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcc2c0f2..0abfaaf2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,6 +61,17 @@ jobs: - name: Tests run: pytest + micropython: + name: Tests (MicroPython 1.11) + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v6 + + - name: Build MicroPython and run tests + run: tools/micropython_tests.sh + package: name: Build and verify artifacts runs-on: ubuntu-latest @@ -68,6 +79,7 @@ jobs: - actionlint - action-pin-policy - tests + - micropython permissions: contents: read steps: diff --git a/README.md b/README.md index e9811121..4811e30a 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,13 @@ Run tests with desktop python: pytest ``` -Run tests with micropython: +Run tests with micropython (builds MicroPython 1.11 with the `hashlib` and `secp256k1` modules on first run, needs `git`, `make`, `python3` and a C compiler): + +```sh +tools/micropython_tests.sh +``` + +With your own build: ```sh cd tests diff --git a/tools/micropython_tests.sh b/tools/micropython_tests.sh new file mode 100755 index 00000000..4c0d1717 --- /dev/null +++ b/tools/micropython_tests.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Build the MicroPython 1.11 unix port with the hashlib and secp256k1 usermods +# embit needs, then run tests/run_tests.py on it. +# 1.11 is the oldest core embit runs on in the wild (Krux devices). +# +# The build is kept in $MP_BUILD_DIR and reused until one of the pins changes. +set -euo pipefail + +MICROPYTHON_SHA=6f75c4f3cd393131579db70cdf0b35d1fe5b95ab # v1.11 +F469_DISCO_SHA=989654e7bbffa255384c052fc5e4f387a2d8862a # usermods/uhashlib +SECP256K1_EMBEDDED_SHA=036f4656335fcbce978d38a7d1ea369c6d39d051 +SECP256K1_SHA=be8d9c262f46309d9b4165b0498b71d704aba8fe # submodule of secp256k1-embedded + +REPO="$(cd "$(dirname "$0")/.." && pwd)" +WORK="${MP_BUILD_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/embit-micropython-1.11}" +MP="$WORK/micropython/ports/unix/micropython" +PINS="$MICROPYTHON_SHA $F469_DISCO_SHA $SECP256K1_EMBEDDED_SHA $SECP256K1_SHA" + +fetch() { # + mkdir -p "$1" + git -C "$1" init -q + git -C "$1" fetch -q --depth 1 "$2" "$3" + git -C "$1" -c advice.detachedHead=false checkout -q FETCH_HEAD +} + +if [ ! -x "$MP" ] || [ "$(cat "$WORK/pins" 2>/dev/null)" != "$PINS" ]; then + fetch "$WORK/micropython" https://github.com/micropython/micropython "$MICROPYTHON_SHA" + fetch "$WORK/f469-disco" https://github.com/diybitcoinhardware/f469-disco "$F469_DISCO_SHA" + fetch "$WORK/usermods/secp256k1" https://github.com/diybitcoinhardware/secp256k1-embedded "$SECP256K1_EMBEDDED_SHA" + fetch "$WORK/usermods/secp256k1/secp256k1" https://github.com/bitcoin-core/secp256k1 "$SECP256K1_SHA" + rm -rf "$WORK/usermods/uhashlib" + cp -r "$WORK/f469-disco/usermods/uhashlib" "$WORK/usermods/uhashlib" + + make -C "$WORK/micropython/ports/unix" -j"$(getconf _NPROCESSORS_ONLN)" \ + USER_C_MODULES="$WORK/usermods" \ + CFLAGS_EXTRA='-DMODULE_HASHLIB_ENABLED=1 -DMODULE_SECP256K1_ENABLED=1 "-DMP_ROM_NONE=MP_ROM_PTR(&mp_const_none_obj)"' \ + MICROPY_PY_USSL=0 MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_THREAD=0 MICROPY_PY_JNI=0 \ + FROZEN_MPY_DIR= CWARN="-Wall -Wno-error" COPT="-Os -Wno-error" + echo "$PINS" > "$WORK/pins" +fi + +# The 1.11 unix port only has the u-prefixed module names. +mkdir -p "$WORK/shims" +for m in binascii io collections struct json os time re random errno zlib heapq select; do + echo "from u$m import *" > "$WORK/shims/$m.py" +done + +cd "$REPO/tests" +MICROPYPATH="$WORK/shims" "$MP" -X heapsize=16M run_tests.py