Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wownero typescript bindings, regression tests #71

Merged
merged 7 commits into from
Oct 16, 2024
Merged
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
30 changes: 28 additions & 2 deletions .github/workflows/full_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ jobs:
key: depends-${{ github.job }}-${{ matrix.coin }}-${{ hashFiles('*/contrib/depends/packages/*.mk') }}
- name: build
run: |
./build_single.sh ${{ matrix.coin }} aarch64-host-apple-darwin -j$(sysctl -n hw.logicalcpu)
./build_single.sh ${{ matrix.coin }} aarch64-host-apple-darwin -j$(sysctl -n hw.logicalcpu)
- name: rename artifacts
run: |
mkdir release/gh/
Expand Down Expand Up @@ -448,7 +448,7 @@ jobs:
key: depends-${{ github.job }}-${{ matrix.coin }}-${{ hashFiles('*/contrib/depends/packages/*.mk') }}
- name: build
run: |
./build_single.sh ${{ matrix.coin }} host-apple-ios -j$(sysctl -n hw.logicalcpu)
./build_single.sh ${{ matrix.coin }} host-apple-ios -j$(sysctl -n hw.logicalcpu)
- name: rename artifacts
run: |
mkdir release/gh/
Expand Down Expand Up @@ -586,6 +586,32 @@ jobs:
cd impls/monero.ts
deno run --unstable-ffi --allow-ffi checksum.ts

regression_check:
strategy:
matrix:
coin: [monero, wownero]
needs: [
lib_linux
]
runs-on: ubuntu-24.04
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: linux ${{ matrix.coin }}
path: release/${{ matrix.coin }}

- name: Run regression tests
run: COIN="${{ matrix.coin }}" deno test -A tests/

comment_pr:
name: comment on pr
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
release/
build/
build/
tests/monero-cli
tests/libs
tests/wallets
17 changes: 12 additions & 5 deletions impls/monero.ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
This library does not ship with `monero_c` libraries.\
To use these bindings you have to bring your own `monero_c` libraries.\
There are at least two ways to do so:

- Ahead-of-time, during builds where you only ship necessary library for a given platform.\
See [monero-tui](https://github.com/Im-Beast/monero-tui/blob/main/.github/workflows/dev-build.yml) build workflow as an example of doing so.
See [monero-tui](https://github.com/Im-Beast/monero-tui/blob/main/.github/workflows/dev-build.yml) build workflow as
an example of doing so.
```ts
import { loadDylib, Wallet, WalletManager } from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";
import {
loadMoneroDylib,
Wallet,
WalletManager,
} from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";

// Try to load dylib from the default lib/* path
loadDylib();
// You can also use loadWowneroDylib for Wownero
loadMoneroDylib();

const wm = await WalletManager.new();
const wallet = await Wallet.create(wm, "./my_wallet", "password");
Expand All @@ -27,11 +34,11 @@ There are at least two ways to do so:
```ts
import { dlopen } from "jsr:@denosaurs/plug";
// It's recommened to put the monero.ts github link into your import_map to reduce the url clutter
import { loadDylib, symbols, Wallet, WalletManager } from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";
import { loadMoneroDylib, symbols, Wallet, WalletManager } from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";

// Load dylib loaded by plug
const lib = await dlopen(..., symbols);
loadDylib(lib);
loadMoneroDylib(lib);

const wm = await WalletManager.new();
const wallet = await Wallet.create(wm, "./my_wallet", "password");
Expand Down
12 changes: 6 additions & 6 deletions impls/monero.ts/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { moneroChecksum } from "./checksum_monero.ts";
import { readCString } from "./src/utils.ts";
import { dylib, loadDylib } from "./src/bindings.ts";
import { getSymbol, readCString } from "./src/utils.ts";
import { dylib, loadMoneroDylib } from "./src/bindings.ts";

loadDylib();
loadMoneroDylib();

export class ChecksumError extends Error {
readonly code: number;
Expand All @@ -21,7 +21,7 @@ export class ChecksumError extends Error {
* @returns {ChecksumError} which contains information about why checksum failed
*/
export async function validateChecksum(): Promise<ChecksumError | null> {
const cppHeaderHash = await readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_h(), false);
const cppHeaderHash = await readCString(await getSymbol("checksum_wallet2_api_c_h")!(), false);
const tsHeaderHash = moneroChecksum.wallet2_api_c_h_sha256;

const errors: string[] = [];
Expand All @@ -32,14 +32,14 @@ export async function validateChecksum(): Promise<ChecksumError | null> {
errorCode++;
}

const cppSourceHash = await readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_cpp(), false);
const cppSourceHash = await readCString(await getSymbol("checksum_wallet2_api_c_cpp")!(), false);
const tsSourceHash = moneroChecksum.wallet2_api_c_cpp_sha256;
if (cppSourceHash !== tsSourceHash) {
errors.push(`ERR: CPP source file check mismatch ${cppSourceHash} == ${tsSourceHash}`);
errorCode++;
}

const cppExportHash = await readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_exp(), false);
const cppExportHash = await readCString(await getSymbol("checksum_wallet2_api_c_exp")!(), false);
const tsExportHash = moneroChecksum.wallet2_api_c_exp_sha256;
if (cppExportHash !== tsExportHash) {
if (Deno.build.os !== "darwin") {
Expand Down
Loading
Loading