From d04dcf67ec042fca76b48ffc09ea9d2ea4b5106e Mon Sep 17 00:00:00 2001 From: cyan Date: Thu, 17 Oct 2024 10:50:22 +0200 Subject: initial work on docs (#69) * initial work on docs * fix DOCKER_VERSION * update location * add the path **properly** * Update docs workflow --- docs/.idea/.gitignore | 3 + docs/.idea/docs.iml | 8 +++ docs/.idea/modules.xml | 8 +++ docs/.idea/vcs.xml | 6 ++ docs/Writerside/assets/onefetch.png | Bin 0 -> 304229 bytes docs/Writerside/c.list | 6 ++ docs/Writerside/cfg/buildprofiles.xml | 13 ++++ docs/Writerside/cfg/glossary.xml | 7 +++ docs/Writerside/in.tree | 17 +++++ docs/Writerside/topics/Android.md | 52 ++++++++++++++++ docs/Writerside/topics/Building.md | 99 ++++++++++++++++++++++++++++++ docs/Writerside/topics/Linux.md | 71 +++++++++++++++++++++ docs/Writerside/topics/Using-prebuilds.md | 48 +++++++++++++++ docs/Writerside/topics/Windows.md | 63 +++++++++++++++++++ docs/Writerside/topics/about.md | 59 ++++++++++++++++++ docs/Writerside/topics/macOS.md | 86 ++++++++++++++++++++++++++ docs/Writerside/writerside.cfg | 11 ++++ docs/update_screenshot.sh | 14 +++++ 18 files changed, 571 insertions(+) create mode 100644 docs/.idea/.gitignore create mode 100644 docs/.idea/docs.iml create mode 100644 docs/.idea/modules.xml create mode 100644 docs/.idea/vcs.xml create mode 100644 docs/Writerside/assets/onefetch.png create mode 100644 docs/Writerside/c.list create mode 100644 docs/Writerside/cfg/buildprofiles.xml create mode 100644 docs/Writerside/cfg/glossary.xml create mode 100644 docs/Writerside/in.tree create mode 100644 docs/Writerside/topics/Android.md create mode 100644 docs/Writerside/topics/Building.md create mode 100644 docs/Writerside/topics/Linux.md create mode 100644 docs/Writerside/topics/Using-prebuilds.md create mode 100644 docs/Writerside/topics/Windows.md create mode 100644 docs/Writerside/topics/about.md create mode 100644 docs/Writerside/topics/macOS.md create mode 100644 docs/Writerside/writerside.cfg create mode 100755 docs/update_screenshot.sh (limited to 'docs') diff --git a/docs/.idea/.gitignore b/docs/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/docs/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/docs/.idea/docs.iml b/docs/.idea/docs.iml new file mode 100644 index 0000000..6102194 --- /dev/null +++ b/docs/.idea/docs.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/docs/.idea/modules.xml b/docs/.idea/modules.xml new file mode 100644 index 0000000..6049cfe --- /dev/null +++ b/docs/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/docs/.idea/vcs.xml b/docs/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/docs/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/docs/Writerside/assets/onefetch.png b/docs/Writerside/assets/onefetch.png new file mode 100644 index 0000000..4cf1288 Binary files /dev/null and b/docs/Writerside/assets/onefetch.png differ diff --git a/docs/Writerside/c.list b/docs/Writerside/c.list new file mode 100644 index 0000000..c4c77a2 --- /dev/null +++ b/docs/Writerside/c.list @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/docs/Writerside/cfg/buildprofiles.xml b/docs/Writerside/cfg/buildprofiles.xml new file mode 100644 index 0000000..332e47b --- /dev/null +++ b/docs/Writerside/cfg/buildprofiles.xml @@ -0,0 +1,13 @@ + + + + + + + + true + + + + diff --git a/docs/Writerside/cfg/glossary.xml b/docs/Writerside/cfg/glossary.xml new file mode 100644 index 0000000..22bec6b --- /dev/null +++ b/docs/Writerside/cfg/glossary.xml @@ -0,0 +1,7 @@ + + + + + Description of what "foo" is. + + \ No newline at end of file diff --git a/docs/Writerside/in.tree b/docs/Writerside/in.tree new file mode 100644 index 0000000..b803dbb --- /dev/null +++ b/docs/Writerside/in.tree @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/Writerside/topics/Android.md b/docs/Writerside/topics/Android.md new file mode 100644 index 0000000..c02b14f --- /dev/null +++ b/docs/Writerside/topics/Android.md @@ -0,0 +1,52 @@ +# Android + +Building on linux has been tested on +- `ubuntu:22.04` (docker tag) + +## Install dependencies + +```bash +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf \ + unzip python-is-python3 +``` + +## Prepare source + +> If you are running in docker or have not configured git you may need to do the following: +> ```bash +> git config --global --add safe.directory '*' +> git config --global user.email "ci@mrcyjanek.net" +> git config --global user.name "CI mrcyjanek.net" +> ``` + +```bash +$ git clone https://github.com/mrcyjanek/monero_c --recursive +$ cd monero_c +$ ./apply_patches.sh monero +``` + +## Building + + + + +$ ./build_single.sh monero x86_64-linux-android -j$(nproc) + + + + +$ ./build_single.sh monero aarch64-linux-android -j$(nproc) + + + + +$ ./build_single.sh monero armv7a-linux-androideabi -j$(nproc) + + + + +## Known issues + +None. Open an issue if you find something not working. \ No newline at end of file diff --git a/docs/Writerside/topics/Building.md b/docs/Writerside/topics/Building.md new file mode 100644 index 0000000..f44f1f3 --- /dev/null +++ b/docs/Writerside/topics/Building.md @@ -0,0 +1,99 @@ +# Building + +Building monero_c comes down to these simple steps: +```bash +$ git clone https://github.com/mrcyjanek/monero_c --recursive +$ ./apply_patches.sh monero # patch the libraries +$ ./build_single x86_64-linux-gnu -j$(nproc) +``` + +To get detailed information about building please select your host platform (the one that you will use to build the +monero wallet) + +- [I'm scared. How can I use prebuilds?](Using-prebuilds.md) +- [Linux](#linux) +- [macOS](#macos) +- [Windows](#windows) + +## Supported systems + +| Target | Builder | Notes | +|------------------|-----------------------------|----------------------------------------------------------------------------------| +| Windows | Linux, Docker, WSL2 | msys2 builds are not supported, there are hardcoded DLL paths in build_single.sh | +| macOS | Native, Linux, Docker, WSL2 | Native builds are being widely used, but are not endorsed by me personally. | +| iOS | macOS | | +| Android | Linux, Docker, WSL2 | | +| Linux | Native, Docker, WSL2 | | +| Linux/SailfishOS | Native, Docker | Required meego toolchain. | + +All supported systems are built on CI, so for the most up-to-date list of all supported systems, together with proper +dependencies please take a look at [full_check.yml](https://github.com/MrCyjaneK/monero_c/blob/master/.github/workflows/full_check.yaml) +file. + +### Linux + +Linux builds should be built on as old of a distro as possible - targeting `debian:oldoldstable`, main reason for that +is GLIBC compatibility (or lack of it). For some reason software compiled with newer GLIBC won't work on devices with +older GLIBC, so the solution is to simply build on the oldest possible os (or abandon GLIBC and use musl). + +- x86-64-linux-gnu +- i686-linux-gnu - deprecated by monero +- aarch64-linux-gnu + +[More details](Linux.md) + +#### SailfishOS + +Fully supported (except for armv7l devices). + +- i686-meego-linux-gnu +- aarch64-meego-linux-gnu + +More details: TBD + +#### Alpine Linux + +Requires dependency removed by upstream - it is preserved in `external/alpine/libexecinfo`. It could easily +be brought back - but since nobody uses it and nobody complained about it missing it kind of never landed in monero_c +after rewrite fully. That being said it should mostly work. + +- ~~x86_64-alpine-linux-musl~~ +- ~~aarch64-alpine-linux-musl~~ + +More details: TBD + +### Android + +Includes bumped NDK version + +- x86_64-linux-android +- ~~i686-linux-android~~ - unsupported, fails to build +- aarch64-linux-android +- armv7a-linux-androideabi + +[More details](Android.md) + +### Windows + +Msys2 shell is not supported, docker or WSL2 is requried to build + +- i686-w64-mingw32 - deprecated by monero +- x86_64-w64-mingw32 +- aarch64-w64-unknown - unsupported. + Though - if somebody can grab and send me a decent CopilotPC I'll be happy to work on that. As for now using x86_64 + build should be fine (but slower in runtime) solution. + +[More details](Windows.md) + +### macOS + +- x86_64-apple-darwin11 +- aarch64-apple-darwin11 +- host-apple-darwin +- x86_64-host-apple-darwin - alias for host-apple-darwin +- aarch64-host-apple-darwin alias for host-apple-darwin + +[More details](macOS.md) + +### iOS +- host-apple-ios - probably will be renamed to `aarch64-apple-ios` \ No newline at end of file diff --git a/docs/Writerside/topics/Linux.md b/docs/Writerside/topics/Linux.md new file mode 100644 index 0000000..7d3a2f1 --- /dev/null +++ b/docs/Writerside/topics/Linux.md @@ -0,0 +1,71 @@ +# Linux + +Building on linux has been tested on +- `debian:bullseye` (docker tag) + +## Install dependencies + + + + +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf + + + + +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf \ + gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + + + +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf \ + gcc-i686-linux-gnu g++-i686-linux-gnu + + + + +## Prepare source + +> If you are running in docker or have not configured git you may need to do the following: +> ```bash +> git config --global --add safe.directory '*' +> git config --global user.email "ci@mrcyjanek.net" +> git config --global user.name "CI mrcyjanek.net" +> ``` + +```bash +$ git clone https://github.com/mrcyjanek/monero_c --recursive +$ cd monero_c +$ ./apply_patches.sh monero +``` + +## Building + + + + +$ ./build_single.sh monero x86_64-linux-gnu -j$(nproc) + + + + +$ ./build_single.sh monero aarch64-linux-gnu -j$(nproc) + + + + +$ ./build_single.sh monero i686-linux-gnu -j$(nproc) + + + + +## Known issues + +None. Open an issue if you find something not working. \ No newline at end of file diff --git a/docs/Writerside/topics/Using-prebuilds.md b/docs/Writerside/topics/Using-prebuilds.md new file mode 100644 index 0000000..f4ff35e --- /dev/null +++ b/docs/Writerside/topics/Using-prebuilds.md @@ -0,0 +1,48 @@ +# Using prebuilds + +Prebuilds are more convenient way of using monero_c in your code (although these builds should **NOT** be used in +production). There are several ways in which you can use prebuilds + +## The monero_c way + +1. Go to https://github.com/MrCyjaneK/monero_c/releases +2. Click on the release that you are interested in +3. Download release-bundle.zip +4. Unzip it in monero_c directory + +That zip file contains all builds that monero_c supports prepared in the exactly same way as you would prepare them if +building on your own. This is the easiest way to get started. + +> Keep in mind that release-bundle.zip contains .xz files inside, so if you want to actually use them you need to use +> them you need to unxz them first +> ```bash +> $ unxz -f -k release/*/*.xz +> ``` + +## The monero_c way (different) + +Alternatively you can go to releases tab and grab whatever you need, there are over 40 libraries. Surely one will fit +your use case. + +## The build_moneroc.sh way + +This method is used by [xmruw](https://github.com/mrcyjanek/unnamed_monero_wallet) and +[monero-tui](https://github.com/Im-Beast/monero-tui). + +It supports both building and downloading prebuilds and putting them in correct location, [have a look at the code +yourself](https://github.com/MrCyjaneK/unnamed_monero_wallet/blob/master-rewrite/build_moneroc.sh) + +```bash +$ ./build_moneroc.sh + --prebuild # allow downloads of prebuilds + --coin # monero/wownero + --tag v0.18.3.3-RC45 # which tag to build / download + --triplet x86_64-linux-android # which triplet to build / download + --location android/.../jniLibs/x86_64 # where to but the libraries +``` + +## The cake wallet way + +There is a simple script in cake_wallet written in `dart` that runs on all platform (including windows) which downloads +all required libraries for selected platforms in one go. +[You can take look at it here](https://github.com/cake-tech/cake_wallet/blob/main/tool/download_moneroc_prebuilds.dart) \ No newline at end of file diff --git a/docs/Writerside/topics/Windows.md b/docs/Writerside/topics/Windows.md new file mode 100644 index 0000000..1cb931c --- /dev/null +++ b/docs/Writerside/topics/Windows.md @@ -0,0 +1,63 @@ +# Windows + +Building on windows has been tested on +- `debian:bullseye` (docker tag) +- `Ubuntu 22.04 WSL` + +## Install dependencies + + + + +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf \ + gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 + + + + +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf \ + gcc-mingw-w64-i686 g++-mingw-w64-i686 + + + + +## Prepare source + +> If you are running in docker or have not configured git you may need to do the following: +> ```bash +> git config --global --add safe.directory '*' +> git config --global user.email "ci@mrcyjanek.net" +> git config --global user.name "CI mrcyjanek.net" +> ``` + +```bash +$ git clone https://github.com/mrcyjanek/monero_c --recursive +$ cd monero_c +$ ./apply_patches.sh monero +``` + +## Building + + + + +$ ./build_single.sh monero x86_64-w64-mingw32 -j$(nproc) + + + + +$ ./build_single.sh monero i686-w64-mingw32 -j$(nproc) + + + + +## Known issues + +### Dynamically loaded dependencies + +There are some dynamically loaded dependencies which are copied over from the OS package repository. All of them are +available in `release/` directory. \ No newline at end of file diff --git a/docs/Writerside/topics/about.md b/docs/Writerside/topics/about.md new file mode 100644 index 0000000..448e70f --- /dev/null +++ b/docs/Writerside/topics/about.md @@ -0,0 +1,59 @@ +# About + +![monero_c onefetch](../assets/onefetch.png) + +## Goal + +The goal of monero_c is simple, at least on the surface +- Build monero for all platforms +- Access monero functions from all languages +- Bring in new features used by wallets but still not merged upstream + +To achieve these tasks some major changes had to happen to monero. + +## Building + +For the most part `contrib/depends` directory of `monero` was used, as it is in perfect shape (that being said it's +terrible to debug when something goes wrong). But it doesn't work with iOS, and it doesn't work on macOS, so some +dependencies had to be pulled as a submodules. But that being said, linux can be used to build for all platforms (except +for iOS - you need macOS for that, and you also need that 100EUR/year license to actually be able to do something with +said library). + +This is especially good because any device can run linux, on WSL2 or under docker. + +## Accessing monero functions + +Though just building the library is not enough, if you just `make wallet_api` in the upstream code you end up in a +place where you technically have the functions in a dynamic library, but you can only use C++ ABI to interact with it. +Which is not ideal. Of course, it is doable, if you want to deal with `__ZNK6Monero10WalletImpl7addressEjj` instead of +`MONERO_Wallet_address`, and make sure that the way you pass in variables is what C++ expects. +I went with the simplest and most standard way of doing that - C ABI (which is what monero should offer in the first +place). Now with any language that supports C interop you can just go ahead and use monero wallet. + +All functionality is simplified to use only the following types: + +- bool +- int +- uint64_t +- void* +- const char* +- void + +## Bring in new features + +There are some extra features inside of the code like +- Polyseed support +- Background sync +- Airgap functions +- Coin control +- UR support +- Ledger support (on android and iSO) +- many fixes + +These features land in the `patches` directory, and are applied to the upstream monero code. + +## Summary + +monero_c extends monero functionality and also simplifies it by a huge extent, if you want to use monero - monero_c is +probably the way to go. +Are you ready to start? Let's see how to build the binary. \ No newline at end of file diff --git a/docs/Writerside/topics/macOS.md b/docs/Writerside/topics/macOS.md new file mode 100644 index 0000000..367893b --- /dev/null +++ b/docs/Writerside/topics/macOS.md @@ -0,0 +1,86 @@ +# macOS + +Building on linux has been tested on +- `macos-14` (github runner) +- `MacOS 15.0.1 Sequoia` (Native) +- `debian:bookworm` (docker tag) + +## Install dependencies + + + + +$ # install xcode 15.4 (or current latest) +$ brew install ccache unbound boost@1.76 zmq autoconf automake libtool +$ brew link boost@1.76 + + + + +$ # install xcode 15.4 (or current latest) +$ brew install ccache unbound boost@1.76 zmq autoconf automake libtool +$ brew link boost@1.76 +$ arch -x86_64 brew install ccache unbound boost@1.76 zmq autoconf automake libtool +$ arch -x86_64 brew link boost@1.76 + + + + +$ apt update +$ apt install -y build-essential pkg-config autoconf libtool \ + ccache make cmake gcc g++ git curl lbzip2 libtinfo5 gperf \ + python-is-python3 + + + + +## Prepare source + +> If you are running in docker or have not configured git you may need to do the following: +> ```bash +> git config --global --add safe.directory '*' +> git config --global user.email "ci@mrcyjanek.net" +> git config --global user.name "CI mrcyjanek.net" +> ``` + +```bash +$ git clone https://github.com/mrcyjanek/monero_c --recursive +$ cd monero_c +$ ./apply_patches.sh monero +``` + +## Building + + + + +$ ./build_single.sh monero x86_64-host-apple-darwin -j$(nproc) + + + + +$ ./build_single.sh monero aarch64-host-apple-darwin -j$(nproc) + + + + +$ arch -x86_64 ./build_single.sh monero x86_64-host-apple-darwin -j$(nproc) + + + + +$ ./build_single.sh monero x86_64-apple-darwin11 -j$(nproc) + + + + +$ ./build_single.sh monero aarch64-apple-darwin-11 -j$(nproc) + + + + +## Known issues + +### Creating fat library + +[Check cake_wallet solution](https://github.com/cake-tech/cake_wallet/blob/main/scripts/macos/build_monero_all.sh) \ No newline at end of file diff --git a/docs/Writerside/writerside.cfg b/docs/Writerside/writerside.cfg new file mode 100644 index 0000000..98e1435 --- /dev/null +++ b/docs/Writerside/writerside.cfg @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/docs/update_screenshot.sh b/docs/update_screenshot.sh new file mode 100755 index 0000000..a404047 --- /dev/null +++ b/docs/update_screenshot.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -x -e +go install github.com/homeport/termshot/cmd/termshot@main +cargo install onefetch +COMMIT_COUNT=$(git log --pretty=format:'' | wc -l | xargs) +echo Commit count: $COMMIT_COUNT +if (( $COMMIT_COUNT % 69 == 0 )) +then + echo "easter egg, yay!" + termshot --show-cmd --filename Writerside/assets/onefetch.png -- "onefetch --number-of-authors 0 -a html | lolcat" +else + echo "normal. Yay." + termshot --show-cmd --filename Writerside/assets/onefetch.png -- "onefetch --number-of-authors 0 -a c++" +fi \ No newline at end of file -- cgit v1.2.3 From 85770ea6f1dab106754675f40e1334e575e03646 Mon Sep 17 00:00:00 2001 From: Mateusz Franik <47059999+Im-Beast@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:39:28 +0100 Subject: tests: run integration and regression tests on other platforms (#93) * tests: add script to download test dependencies from fallback mirrors * tests: use the new download_deps script, run tests on macos * ci: download proper artifact for macos * chore: make download_deps script download everything to dir named `monero_c` when ran directly * tests: await downloading deps * tests download proper monero_c version in prepareMoneroC * tests: fix typos * tests: add file data for more targets * tests: print why retrieving tags failed * chore: change mirror url endpoint from `monero_c` to `download_mirror` * tests: use cached releases endpoint to prevent ratelimits * ci: remove brew@1.76 dependency * tests: fix macos dylib path * feat!(monero.ts): make `createTransactionMultDest` optionally return `null` * feat(monero.ts): make `Wallet_reconnectDevice` symbol optional * tests: don't try to extract file if out already exists * tests: remove unnecesary directory rm calls * ci: set regression tests to use canary --- .github/workflows/full_check.yaml | 67 ++++++++++- .gitignore | 4 +- docs/Writerside/topics/macOS.md | 12 +- impls/monero.ts/src/symbols.ts | 2 + impls/monero.ts/src/wallet.ts | 6 +- tests/compare.ts | 17 +-- tests/deno.lock | 32 ++---- tests/download_deps.ts | 235 ++++++++++++++++++++++++++++++++++++++ tests/integration.test.ts | 28 +---- tests/regression.test.ts | 9 +- tests/utils.ts | 164 ++++++++++++++++++-------- 11 files changed, 451 insertions(+), 125 deletions(-) create mode 100644 tests/download_deps.ts (limited to 'docs') diff --git a/.github/workflows/full_check.yaml b/.github/workflows/full_check.yaml index 2f73515..e083dd6 100644 --- a/.github/workflows/full_check.yaml +++ b/.github/workflows/full_check.yaml @@ -271,7 +271,7 @@ jobs: xcode-version: '15.4' - name: install dependencies run: | - brew install ccache unbound boost@1.76 zmq autoconf automake libtool && brew link boost@1.76 + brew install ccache unbound zmq autoconf automake libtool - name: Patch sources run: | git config --global --add safe.directory '*' @@ -404,7 +404,8 @@ jobs: cd impls/monero.ts deno run --unstable-ffi --allow-ffi checksum.ts - regression_check: + regression_tests_linux: + name: linux regression tests strategy: fail-fast: false matrix: @@ -431,7 +432,35 @@ jobs: - name: Run regression tests run: COIN="${{ matrix.coin }}" deno test -A tests/regression.test.ts - integration_check: + regression_tests_macos: + name: macos regression tests + strategy: + matrix: + coin: [monero, wownero] + needs: [ + lib_macos + ] + runs-on: macos-14 + steps: + - uses: denoland/setup-deno@v2 + with: + deno-version: canary + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + + - uses: actions/download-artifact@v4 + with: + name: macos ${{ matrix.coin }} + path: release/${{ matrix.coin }} + + - name: Run regression tests + run: COIN="${{ matrix.coin }}" deno test -A tests/regression.test.ts + + integration_tests_linux: + name: linux integration tests strategy: matrix: coin: [monero, wownero] @@ -462,6 +491,38 @@ jobs: SECRET_WALLET_RESTORE_HEIGHT: ${{ secrets.SECRET_WALLET_RESTORE_HEIGHT }} + integration_tests_macos: + name: macos integration tests + strategy: + matrix: + coin: [monero, wownero] + needs: [ + lib_macos + ] + runs-on: macos-14 + steps: + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + + - uses: actions/download-artifact@v4 + with: + name: macos ${{ matrix.coin }} + path: release/${{ matrix.coin }} + + - name: Run integration tests + run: COIN="${{ matrix.coin }}" deno test -A tests/integration.test.ts + env: + SECRET_WALLET_PASSWORD: ${{ secrets.SECRET_WALLET_PASSWORD }} + SECRET_WALLET_MNEMONIC: ${{ secrets.SECRET_WALLET_MNEMONIC }} + SECRET_WALLET_RESTORE_HEIGHT: ${{ secrets.SECRET_WALLET_RESTORE_HEIGHT }} + + comment_pr: name: comment on pr runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 9159f7d..7dc5983 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ release/ build/ -tests/monero-cli -tests/wownero-cli -tests/libs +tests/dependencies tests/wallets diff --git a/docs/Writerside/topics/macOS.md b/docs/Writerside/topics/macOS.md index 367893b..52b6be8 100644 --- a/docs/Writerside/topics/macOS.md +++ b/docs/Writerside/topics/macOS.md @@ -11,17 +11,15 @@ Building on linux has been tested on $ # install xcode 15.4 (or current latest) -$ brew install ccache unbound boost@1.76 zmq autoconf automake libtool -$ brew link boost@1.76 +$ brew install ccache unbound zmq autoconf automake libtool $ # install xcode 15.4 (or current latest) -$ brew install ccache unbound boost@1.76 zmq autoconf automake libtool -$ brew link boost@1.76 -$ arch -x86_64 brew install ccache unbound boost@1.76 zmq autoconf automake libtool -$ arch -x86_64 brew link boost@1.76 +$ brew install ccache unbound zmq autoconf automake libtool +$ arch -x86_64 brew install ccache unbound zmq autoconf automake libtool +$ arch -x86_64 brew link @@ -83,4 +81,4 @@ $ ./build_single.sh monero aarch64-apple-darwin-11 -j$(nproc) ### Creating fat library -[Check cake_wallet solution](https://github.com/cake-tech/cake_wallet/blob/main/scripts/macos/build_monero_all.sh) \ No newline at end of file +[Check cake_wallet solution](https://github.com/cake-tech/cake_wallet/blob/main/scripts/macos/build_monero_all.sh) diff --git a/impls/monero.ts/src/symbols.ts b/impls/monero.ts/src/symbols.ts index 2c34a6e..91d95b2 100644 --- a/impls/monero.ts/src/symbols.ts +++ b/impls/monero.ts/src/symbols.ts @@ -1548,6 +1548,7 @@ export const moneroSymbols = { ], }, MONERO_Wallet_createTransactionMultDest: { + optional: true, nonblocking: true, result: "pointer", parameters: [ @@ -1956,6 +1957,7 @@ export const moneroSymbols = { ], }, MONERO_Wallet_reconnectDevice: { + optional: true, nonblocking: true, result: "bool", parameters: ["pointer"] as [ diff --git a/impls/monero.ts/src/wallet.ts b/impls/monero.ts/src/wallet.ts index 673ccab..92832da 100644 --- a/impls/monero.ts/src/wallet.ts +++ b/impls/monero.ts/src/wallet.ts @@ -286,8 +286,8 @@ export class Wallet { preferredInputs: string[] = [], mixinCount = 0, paymentId = "", - ): Promise { - const pendingTxPtr = await fns.Wallet_createTransactionMultDest( + ): Promise { + const pendingTxPtr = await fns.Wallet_createTransactionMultDest?.( this.#ptr, CString(destinationAddresses.join(SEPARATOR)), C_SEPARATOR, @@ -301,6 +301,8 @@ export class Wallet { CString(preferredInputs.join(SEPARATOR)), C_SEPARATOR, ); + + if (!pendingTxPtr) return null; return PendingTransaction.new(pendingTxPtr as PendingTransactionPtr); } diff --git a/tests/compare.ts b/tests/compare.ts index 2fd27b8..8c13fc5 100755 --- a/tests/compare.ts +++ b/tests/compare.ts @@ -1,24 +1,13 @@ import { assertEquals } from "jsr:@std/assert"; -import { - loadMoneroDylib, - loadWowneroDylib, - moneroSymbols, - WalletManager, - wowneroSymbols, -} from "../impls/monero.ts/mod.ts"; +import { WalletManager } from "../impls/monero.ts/mod.ts"; +import { loadDylib } from "./utils.ts"; const coin = Deno.args[0] as "monero" | "wownero"; const version = Deno.args[1]; const walletInfo = JSON.parse(Deno.args[2]); -if (coin === "monero") { - const dylib = Deno.dlopen(`tests/libs/${version}/monero_libwallet2_api_c.so`, moneroSymbols); - loadMoneroDylib(dylib); -} else { - const dylib = Deno.dlopen(`tests/libs/${version}/wownero_libwallet2_api_c.so`, wowneroSymbols); - loadWowneroDylib(dylib); -} +loadDylib(coin, version); const walletManager = await WalletManager.new(); const wallet = await walletManager.openWallet(walletInfo.path, walletInfo.password); diff --git a/tests/deno.lock b/tests/deno.lock index b67d77d..5ed1a7a 100644 --- a/tests/deno.lock +++ b/tests/deno.lock @@ -9,14 +9,12 @@ "jsr:@std/bytes@0.221": "0.221.0", "jsr:@std/fmt@0.221": "0.221.0", "jsr:@std/fmt@1": "1.0.2", - "jsr:@std/fs@1": "1.0.4", + "jsr:@std/fs@1": "1.0.5", "jsr:@std/io@0.221": "0.221.0", - "jsr:@std/path@1": "1.0.6", - "jsr:@std/path@1.0.8": "1.0.8", - "jsr:@std/path@^1.0.6": "1.0.6", - "jsr:@std/streams@0.221": "0.221.0", - "jsr:@std/streams@^1.0.7": "1.0.7", - "jsr:@std/tar@*": "0.1.2" + "jsr:@std/path@*": "1.0.8", + "jsr:@std/path@1": "1.0.8", + "jsr:@std/path@^1.0.7": "1.0.8", + "jsr:@std/streams@0.221": "0.221.0" }, "jsr": { "@david/dax@0.42.0": { @@ -28,7 +26,7 @@ "jsr:@std/fs", "jsr:@std/io", "jsr:@std/path@1", - "jsr:@std/streams@0.221" + "jsr:@std/streams" ] }, "@david/path@0.2.0": { @@ -56,10 +54,10 @@ "@std/fmt@1.0.2": { "integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7" }, - "@std/fs@1.0.4": { - "integrity": "2907d32d8d1d9e540588fd5fe0ec21ee638134bd51df327ad4e443aaef07123c", + "@std/fs@1.0.5": { + "integrity": "41806ad6823d0b5f275f9849a2640d87e4ef67c51ee1b8fb02426f55e02fd44e", "dependencies": [ - "jsr:@std/path@^1.0.6" + "jsr:@std/path@^1.0.7" ] }, "@std/io@0.221.0": { @@ -69,9 +67,6 @@ "jsr:@std/bytes" ] }, - "@std/path@1.0.6": { - "integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed" - }, "@std/path@1.0.8": { "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" }, @@ -80,15 +75,6 @@ "dependencies": [ "jsr:@std/io" ] - }, - "@std/streams@1.0.7": { - "integrity": "1a93917ca0c58c01b2bfb93647189229b1702677f169b6fb61ad6241cd2e499b" - }, - "@std/tar@0.1.2": { - "integrity": "98183102395decd6268253996177804f818580ef547a25b81da0e7cc334db708", - "dependencies": [ - "jsr:@std/streams@^1.0.7" - ] } } } diff --git a/tests/download_deps.ts b/tests/download_deps.ts new file mode 100644 index 0000000..808640e --- /dev/null +++ b/tests/download_deps.ts @@ -0,0 +1,235 @@ +import { join, resolve } from "jsr:@std/path"; +import { Coin, getMoneroCTags } from "./utils.ts"; + +export type Target = `${typeof Deno["build"]["os"]}_${typeof Deno["build"]["arch"]}`; + +interface FileInfo { + overrideMirrors?: string[]; + name: string; + sha256?: string; +} + +interface DownloadInfo { + mirrors: string[]; + file: + | FileInfo + | { [os in Target]?: FileInfo }; + outDir?: string; +} + +export function getFileInfo( + downloadInfo: DownloadInfo, + target: Target = `${Deno.build.os}_${Deno.build.arch}`, +): FileInfo { + const fileInfo = "name" in downloadInfo.file ? downloadInfo.file : downloadInfo.file[target]; + if (!fileInfo) { + throw new Error(`No fileInfo set for target: ${target}`); + } + return fileInfo; +} + +async function sha256(buffer: Uint8Array): Promise { + const hashed = new Uint8Array(await crypto.subtle.digest("SHA-256", buffer)); + return Array.from(hashed).map((i) => i.toString(16).padStart(2, "0")).join(""); +} + +export async function downloadDependencies(...infos: DownloadInfo[]): Promise { + return await downloadFiles("./tests/dependencies", `${Deno.build.os}_${Deno.build.arch}`, ...infos); +} + +export async function downloadFiles(outDir: string, target: Target, ...infos: DownloadInfo[]): Promise { + try { + await Deno.mkdir(outDir, { recursive: true }); + } catch (error) { + if (!(error instanceof Deno.errors.AlreadyExists)) { + throw error; + } + } + + for (const info of infos) { + const fileInfo = getFileInfo(info, target); + const fileName = fileInfo.name; + const filePath = join(outDir, info.outDir ?? "", fileName); + + file_might_exist: try { + const fileBuffer = await Deno.readFile(filePath); + + // File exists, make sure checksum matches + if (fileInfo.sha256) { + const fileChecksum = await sha256(fileBuffer); + if (fileChecksum !== fileInfo.sha256) { + console.log( + `File ${fileName} already exists, but checksum is mismatched (${fileChecksum} != ${fileInfo.sha256}), redownloading`, + ); + await Deno.remove(filePath); + break file_might_exist; + } + } + + console.log(`File ${fileName} already exists, skipping`); + continue; + } catch { /**/ } + + let buffer: Uint8Array | undefined; + + for (const mirror of fileInfo.overrideMirrors ?? info.mirrors) { + const url = `${mirror}/${fileName}`; + + const response = await fetch(url); + if (!response.ok) { + console.warn(`Could not reach file ${fileName} on mirror: ${mirror}`); + await response.body?.cancel(); + continue; + } + + const responseBuffer = await response.bytes(); + + if (fileInfo.sha256) { + const responseChecksum = await sha256(responseBuffer); + if (responseChecksum !== fileInfo.sha256) { + console.warn( + `Checksum mismatch on file ${fileName} on mirror: ${mirror} (${responseChecksum} != ${fileInfo.sha256})`, + ); + continue; + } + } + + buffer = responseBuffer; + } + + if (!buffer) { + throw new Error(`None of the mirrors for ${fileName} are available`); + } + + await Deno.mkdir(resolve(filePath, ".."), { + recursive: true, + }).catch(() => {}); + + await Deno.writeFile(filePath, buffer); + console.info("Downloaded file", fileInfo.name); + } +} + +export const wowneroCliInfo: DownloadInfo = { + mirrors: [ + "https://static.mrcyjanek.net/download_mirror/", + "https://codeberg.org/wownero/wownero/releases/download/v0.11.2.0/", + ], + file: { + linux_aarch64: { + name: "wownero-aarch64-linux-gnu-59db3fe8d.tar.bz2", + sha256: "07ce678302c07a6e79d90be65cbda243d843d414fbadb30f972d6c226575cfa7", + }, + linux_x86_64: { + name: "wownero-x86_64-linux-gnu-59db3fe8d.tar.bz2", + sha256: "03880967c70cc86558d962b8a281868c3934238ea457a36174ba72b99d70107e", + }, + + darwin_aarch64: { + name: "wownero-aarch64-apple-darwin11-59db3fe8d.tar.bz2", + sha256: "25ff454a92b1cf036df5f28cdd2c63dcaf4b03da7da9403087371f868827c957", + }, + darwin_x86_64: { + name: "wownero-x86_64-apple-darwin11-59db3fe8d.tar.bz2", + sha256: "7e9b6a84a560ed7a9ed7117c6f07fb228d77a06afac863d0ea1dbf833c4eddf6", + }, + + windows_x86_64: { + name: "wownero-x86_64-w64-mingw32-59db3fe8d.zip", + sha256: "7e0ed84afa51e3b403d635c706042859094eb6850de21c9e82cb0a104425510e", + }, + + android_aarch64: { + overrideMirrors: [ + "https://static.mrcyjanek.net/download_mirror/", + "https://codeberg.org/wownero/wownero/releases/download/v0.11.1.0/", + ], + name: "wownero-aarch64-linux-android-v0.11.1.0.tar.bz2", + sha256: "236188f8d8e7fad2ff35973f8c2417afffa8855d1a57b4c682fff5b199ea40f5", + }, + }, +}; + +export const moneroCliInfo: DownloadInfo = { + mirrors: [ + "https://static.mrcyjanek.net/download_mirror/", + "https://downloads.getmonero.org/cli/", + ], + file: { + linux_aarch64: { + name: "monero-linux-armv8-v0.18.3.4.tar.bz2", + sha256: "33ca2f0055529d225b61314c56370e35606b40edad61c91c859f873ed67a1ea7", + }, + linux_x86_64: { + name: "monero-linux-x64-v0.18.3.4.tar.bz2", + sha256: "51ba03928d189c1c11b5379cab17dd9ae8d2230056dc05c872d0f8dba4a87f1d", + }, + + darwin_aarch64: { + name: "monero-mac-armv8-v0.18.3.4.tar.bz2", + sha256: "44520cb3a05c2518ca9aeae1b2e3080fe2bba1e3596d014ceff1090dfcba8ab4", + }, + darwin_x86_64: { + name: "monero-mac-x64-v0.18.3.4.tar.bz2", + sha256: "32c449f562216d3d83154e708471236d07db7477d6b67f1936a0a85a5005f2b8", + }, + + windows_x86_64: { + name: "monero-win-x64-v0.18.3.4.zip", + sha256: "54a66db6c892b2a0999754841f4ca68511741b88ea3ab20c7cd504a027f465f5", + }, + + android_aarch64: { + name: "monero-android-armv8-v0.18.3.4.tar.bz2", + sha256: "d9c9249d1408822ce36b346c6b9fb6b896cda16714d62117fb1c588a5201763c", + }, + }, +}; + +export const dylibInfos: Record = { + monero: [], + wownero: [], +}; + +for (const tag of await getMoneroCTags()) { + for (const coin of ["monero", "wownero"] as const) { + dylibInfos[coin].push({ + mirrors: [ + `https://static.mrcyjanek.net/download_mirror/libs/${tag}/`, + `https://github.com/MrCyjaneK/monero_c/releases/download/${tag}/`, + ], + file: { + linux_aarch64: { name: `${coin}_aarch64-linux-gnu_libwallet2_api_c.so.xz` }, + linux_x86_64: { name: `${coin}_x86_64-linux-gnu_libwallet2_api_c.so.xz` }, + darwin_aarch64: { name: `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib.xz` }, + darwin_x86_64: { name: `${coin}_x86_64-apple-darwin11_libwallet2_api_c.dylib.xz` }, + windows_x86_64: { name: `${coin}_x86_64-w64-mingw32_libwallet2_api_c.dll.xz` }, + android_aarch64: { name: `${coin}_aarch64-linux-android_libwallet2_api_c.so.xz` }, + }, + outDir: `libs/${tag}`, + }); + } +} + +// Download files to the download_mirror folder +// (used on mirror to keep files up to date) +if (import.meta.main) { + const supportedTargets: Target[] = [ + "linux_x86_64", + "linux_aarch64", + "darwin_x86_64", + "darwin_aarch64", + "windows_x86_64", + "android_aarch64", + ]; + + for (const target of supportedTargets) { + await downloadFiles( + "./download_mirror", + target, + moneroCliInfo, + wowneroCliInfo, + ...Object.values(dylibInfos).flat(), + ); + } +} diff --git a/tests/integration.test.ts b/tests/integration.test.ts index 1a65009..100bd43 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -1,16 +1,7 @@ -import { - CoinsInfo, - type Dylib, - loadMoneroDylib, - loadWowneroDylib, - moneroSymbols, - Wallet, - WalletManager, - wowneroSymbols, -} from "../impls/monero.ts/mod.ts"; +import { CoinsInfo, Wallet, WalletManager } from "../impls/monero.ts/mod.ts"; import { assert, assertEquals } from "jsr:@std/assert"; -import { $, downloadCli, getMoneroC } from "./utils.ts"; +import { $, loadDylib, prepareCli, prepareMoneroC } from "./utils.ts"; const coin = Deno.env.get("COIN"); if (coin !== "monero" && coin !== "wownero") { @@ -53,7 +44,7 @@ const DESTINATION_ADDRESS = coin === "monero" ? MONERO_DESTINATION_ADDRESS : WOW const BILLION = 10n ** 9n; -await getMoneroC(coin, "next"); +await prepareMoneroC(coin, "next"); interface WalletInfo { name: string; @@ -74,14 +65,7 @@ async function clearWallets() { await Deno.mkdir("tests/wallets/"); } -let dylib: Dylib; -if (coin === "monero") { - dylib = Deno.dlopen(`tests/libs/next/monero_libwallet2_api_c.so`, moneroSymbols); - loadMoneroDylib(dylib); -} else { - dylib = Deno.dlopen(`tests/libs/next/wownero_libwallet2_api_c.so`, wowneroSymbols); - loadWowneroDylib(dylib); -} +loadDylib(coin, "next"); Deno.test("0001-polyseed.patch", async (t) => { const WALLETS: Record<"monero" | "wownero", WalletInfo[]> = { @@ -487,7 +471,7 @@ Deno.test("0004-coin-control.patch", { Deno.test("0009-Add-recoverDeterministicWalletFromSpendKey.patch", async () => { await Promise.all([ - downloadCli(coin), + prepareCli(coin), clearWallets(), ]); @@ -498,7 +482,7 @@ Deno.test("0009-Add-recoverDeterministicWalletFromSpendKey.patch", async () => { await Deno.remove("./tests/wallets/stoat"); - const cliPath = `./tests/${coin}-cli/${coin}-wallet-cli`; + const cliPath = `./tests/dependencies/${coin}-cli/${coin}-wallet-cli`; const moneroCliSeed = (await $.raw`${cliPath} --wallet-file ./tests/wallets/stoat --password gornostay --command seed` .stdinText(`gornostay\n`) .lines()).slice(-3).join(" "); diff --git a/tests/regression.test.ts b/tests/regression.test.ts index 82a9f95..797720f 100755 --- a/tests/regression.test.ts +++ b/tests/regression.test.ts @@ -1,4 +1,4 @@ -import { $, createWalletViaCli, downloadCli, getMoneroC, getMoneroCTags } from "./utils.ts"; +import { $, createWalletViaCli, getMoneroCTags, prepareCli, prepareMoneroC } from "./utils.ts"; const coin = Deno.env.get("COIN"); if (coin !== "monero" && coin !== "wownero") { @@ -11,7 +11,7 @@ Deno.test(`Regression tests (${coin})`, async (t) => { const tags = await getMoneroCTags(); const latestTag = tags[0]; - await Promise.all([getMoneroC(coin, "next"), await getMoneroC(coin, latestTag), downloadCli(coin)]); + await Promise.all([prepareMoneroC(coin, "next"), await prepareMoneroC(coin, latestTag), prepareCli(coin)]); await t.step("Simple (next, latest, next)", async () => { const walletInfo = await createWalletViaCli(coin, "dog", "sobaka"); @@ -27,13 +27,10 @@ Deno.test(`Regression tests (${coin})`, async (t) => { const walletInfo = await createWalletViaCli(coin, "cat", "koshka"); for (const version of tags.toReversed()) { - if (version !== "next" && version !== tags[0]) await getMoneroC(coin, version); + if (version !== "next" && version !== tags[0]) await prepareMoneroC(coin, version); await $`deno run -A ./tests/compare.ts ${coin} ${version} ${JSON.stringify(walletInfo)}`; } - - await Deno.remove("./tests/wallets", { recursive: true }).catch(() => {}); }); await Deno.remove("./tests/wallets", { recursive: true }).catch(() => {}); - await Deno.remove("./tests/libs", { recursive: true }).catch(() => {}); }); diff --git a/tests/utils.ts b/tests/utils.ts index cd05232..86501a8 100755 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,4 +1,18 @@ import { build$, CommandBuilder } from "jsr:@david/dax"; +import { dirname, join } from "jsr:@std/path"; +import { + downloadDependencies, + dylibInfos, + getFileInfo, + moneroCliInfo, + Target, + wowneroCliInfo, +} from "./download_deps.ts"; +import { loadMoneroDylib, loadWowneroDylib, moneroSymbols, wowneroSymbols } from "../impls/monero.ts/mod.ts"; + +export type Coin = "monero" | "wownero"; + +const target = `${Deno.build.os}_${Deno.build.arch}` as const; export const $ = build$({ commandBuilder: new CommandBuilder() @@ -8,34 +22,83 @@ export const $ = build$({ .stderr("inherit"), }); -type Coin = "monero" | "wownero"; +export const dylibNames = (coin: Coin, version: MoneroCVersion) => ({ + linux_x86_64: `${coin}_x86_64-linux-gnu_libwallet2_api_c.so`, + darwin_aarch64: version === "next" + ? `${coin}_aarch64-apple-darwin_libwallet2_api_c.dylib` + : `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib`, + windows_x86_64: `${coin}_x86_64-w64-mingw32_libwallet2_api_c.dll`, +} as Partial>); + +export const moneroTsDylibNames = (coin: Coin) => ({ + linux_x86_64: `${coin}_libwallet2_api_c.so`, + darwin_aarch64: `${coin}_aarch64-apple-darwin11_libwallet2_api_c.dylib`, + windows_x86_64: `${coin}_libwallet2_api_c.dll`, +} as Partial>); + +export function loadDylib(coin: Coin, version: MoneroCVersion) { + const dylibName = moneroTsDylibNames(coin)[target]!; + + if (coin === "monero") { + const dylib = Deno.dlopen(`tests/dependencies/libs/${version}/${dylibName}`, moneroSymbols); + loadMoneroDylib(dylib); + return dylib; + } else { + const dylib = Deno.dlopen(`tests/dependencies/libs/${version}/${dylibName}`, wowneroSymbols); + loadWowneroDylib(dylib); + return dylib; + } +} -export async function downloadMoneroCli() { - const MONERO_CLI_FILE_NAME = "monero-linux-x64-v0.18.3.4"; - const MONERO_WALLET_CLI_URL = `https://downloads.getmonero.org/cli/${MONERO_CLI_FILE_NAME}.tar.bz2`; +async function exists(path: string): Promise { + try { + await Deno.stat(path); + return true; + } catch (error) { + if (error instanceof Deno.errors.NotFound) { + return false; + } + throw error; + } +} - await $`wget -q -o /dev/null ${MONERO_WALLET_CLI_URL}`; - await $ - .raw`tar -xf ${MONERO_CLI_FILE_NAME}.tar.bz2 --one-top-level=monero-cli --strip-components=1 -C tests`; - await $.raw`rm ${MONERO_CLI_FILE_NAME}.tar.bz2`; +export async function extract(path: string, out: string) { + const outDir = out.endsWith("/") ? out : dirname(out); + await Deno.mkdir(outDir, { recursive: true }); + + if (path.endsWith(".tar.bz2")) { + let args = `-C ${dirname(out)}`; + if (outDir === out) { + args = `-C ${out} --strip-components=1`; + } + await $.raw`tar -xf ${path} ${args}`; + } else if (path.endsWith(".zip")) { + await $.raw`unzip ${path} -nu -d ${outDir}`; + } else if (path.endsWith(".xz")) { + await $.raw`xz -kd ${path}`; + await Deno.rename(path.slice(0, -3), out); + } else { + throw new Error("Unsupported archive file for:" + path); + } } -export async function downloadWowneroCli() { - const WOWNERO_CLI_FILE_NAME = "wownero-x86_64-linux-gnu-59db3fe8d"; - const WOWNERO_WALLET_CLI_URL = - `https://codeberg.org/wownero/wownero/releases/download/v0.11.2.0/wownero-x86_64-linux-gnu-59db3fe8d.tar.bz2`; +export async function prepareMoneroCli() { + await downloadDependencies(moneroCliInfo); + const path = join("./tests/dependencies", moneroCliInfo.outDir ?? "", getFileInfo(moneroCliInfo).name); + await extract(path, "./tests/dependencies/monero-cli/"); +} - await $`wget -q -o /dev/null ${WOWNERO_WALLET_CLI_URL}`; - await $ - .raw`tar -xf ${WOWNERO_CLI_FILE_NAME}.tar.bz2 --one-top-level=wownero-cli --strip-components=1 -C tests`; - await $.raw`rm ${WOWNERO_CLI_FILE_NAME}.tar.bz2`; +export async function prepareWowneroCli() { + await downloadDependencies(wowneroCliInfo); + const path = join("./tests/dependencies", wowneroCliInfo.outDir ?? "", getFileInfo(wowneroCliInfo).name); + await extract(path, "./tests/dependencies/wownero-cli/"); } -export function downloadCli(coin: Coin) { +export function prepareCli(coin: Coin) { if (coin === "wownero") { - return downloadWowneroCli(); + return prepareWowneroCli(); } - return downloadMoneroCli(); + return prepareMoneroCli(); } interface WalletInfo { @@ -54,7 +117,7 @@ export async function createWalletViaCli( password: string, ): Promise { const path = `./tests/wallets/${name}`; - const cliPath = `./tests/${coin}-cli/${coin}-wallet-cli`; + const cliPath = `./tests/dependencies/${coin}-cli/${coin}-wallet-cli`; await $ .raw`${cliPath} --generate-new-wallet ${path} --password ${password} --mnemonic-language English --command exit` @@ -97,35 +160,46 @@ export async function createWalletViaCli( export type MoneroCVersion = "next" | (string & {}); export async function getMoneroCTags(): Promise { - return (( - await (await fetch( - "https://api.github.com/repos/MrCyjanek/monero_c/releases", - )).json() - ) as { tag_name: string }[]) - .map(({ tag_name }) => tag_name); + const response = await fetch("https://static.mrcyjanek.net/monero_c/release.php"); + + if (!response.ok) { + throw new Error(`Could not receive monero_c release tags: ${await response.text()}`); + } + + const json = await response.json() as { tag_name: string }[]; + return json.map(({ tag_name }) => tag_name); } -export async function getMoneroC(coin: Coin, version: MoneroCVersion) { - const dylibName = `${coin}_x86_64-linux-gnu_libwallet2_api_c.so`; - const endpointDylibName = `${coin}_libwallet2_api_c.so`; + +export async function prepareMoneroC(coin: Coin, version: MoneroCVersion) { + const dylibName = dylibNames(coin, version)[target]; + const moneroTsDylibName = moneroTsDylibNames(coin)[target]; + + if (!dylibName || !moneroTsDylibName) { + throw new Error(`Missing dylib name value for target: ${target}`); + } + const releaseDylibName = dylibName.slice(`${coin}_`.length); if (version === "next") { - await $.raw`xz -kd release/${coin}/${releaseDylibName}.xz`; - await $`mkdir -p tests/libs/next`; - await $`mv release/${coin}/${releaseDylibName} tests/libs/next/${endpointDylibName}`; + const outFileDir = `./tests/dependencies/libs/${version}/${moneroTsDylibName}`; + + if (await exists(outFileDir)) { + return; + } + + await extract(`./release/${coin}/${releaseDylibName}.xz`, outFileDir); } else { - const downloadUrl = `https://github.com/MrCyjaneK/monero_c/releases/download/${version}/${dylibName}.xz`; - - const file = await Deno.open(`./tests/${dylibName}.xz`, { - create: true, - write: true, - }); - file.write(await (await fetch(downloadUrl)).bytes()); - file.close(); - - await $.raw`xz -d ./tests/${dylibName}.xz`; - await $.raw`mkdir -p ./tests/libs/${version}`; - await $ - .raw`mv ./tests/${dylibName} ./tests/libs/${version}/${endpointDylibName}`; + const outFileDir = `./tests/dependencies/libs/${version}/${moneroTsDylibName}`; + + if (await exists(outFileDir)) { + return; + } + + const downloadInfo = dylibInfos[coin].find((info) => info.outDir?.endsWith(version)); + if (downloadInfo) { + await downloadDependencies(downloadInfo); + } + + await extract(`./tests/dependencies/libs/${version}/${dylibName}.xz`, outFileDir); } } -- cgit v1.2.3