Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,25 @@ 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
needs:
- actionlint
- action-pin-policy
- tests
- micropython
permissions:
contents: read
steps:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions tools/micropython_tests.sh
Original file line number Diff line number Diff line change
@@ -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() { # <dir> <url> <sha>
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
Loading