summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/compare.ts50
-rwxr-xr-xtests/regression.test.ts4
2 files changed, 32 insertions, 22 deletions
diff --git a/tests/compare.ts b/tests/compare.ts
index 9a8fa8d..d09bdd9 100755
--- a/tests/compare.ts
+++ b/tests/compare.ts
@@ -1,21 +1,15 @@
-import { loadDylib, symbols as bindingsSymbols } from "../impls/monero.ts/src/bindings.ts";
+import { moneroSymbols as symbols, type MoneroTsDylib, type WowneroTsDylib } from "../impls/monero.ts/src/symbols.ts";
+import { loadMoneroDylib, loadWowneroDylib } from "../impls/monero.ts/src/bindings.ts";
import { Wallet, WalletManager } from "../impls/monero.ts/mod.ts";
import { readCString } from "../impls/monero.ts/src/utils.ts";
import { assertEquals } from "jsr:@std/assert";
-const version = Deno.args[0];
-const walletInfo = JSON.parse(Deno.args[1]);
+const coin = Deno.args[0] as "monero" | "wownero";
+const version = Deno.args[1];
+const walletInfo = JSON.parse(Deno.args[2]);
-// Those don't exist on older versions of monero_c
-// @ts-expect-error -
-delete bindingsSymbols.MONERO_checksum_wallet2_api_c_h;
-// @ts-expect-error -
-delete bindingsSymbols.MONERO_checksum_wallet2_api_c_cpp;
-// @ts-expect-error -
-delete bindingsSymbols.MONERO_checksum_wallet2_api_c_exp;
-
-const symbols = {
- ...bindingsSymbols,
+const moneroSymbols = {
+ ...symbols,
"MONERO_Wallet_secretViewKey": {
nonblocking: true,
@@ -48,19 +42,35 @@ const symbols = {
},
} as const;
-const dylib = Deno.dlopen(`tests/libs/${version}/monero_libwallet2_api_c.so`, symbols);
-loadDylib(dylib as Deno.DynamicLibrary<typeof bindingsSymbols>);
+type ReplaceMonero<T extends string> = T extends `MONERO${infer Y}` ? `WOWNERO${Y}` : never;
+type WowneroSymbols = { [Key in keyof typeof moneroSymbols as ReplaceMonero<Key>]: (typeof moneroSymbols)[Key] };
+const wowneroSymbols = Object.fromEntries(
+ Object.entries(moneroSymbols).map(([key, value]) => [key.replace("MONERO", "WOWNERO"), value]),
+) as WowneroSymbols;
+
+let getKey: (wallet: Wallet, type: `${"secret" | "public"}${"Spend" | "View"}Key`) => Promise<string | null>;
+
+if (coin === "monero") {
+ const dylib = Deno.dlopen(`tests/libs/${version}/monero_libwallet2_api_c.so`, moneroSymbols);
+ loadMoneroDylib(dylib as MoneroTsDylib);
+
+ getKey = async (wallet, type) =>
+ await readCString(await dylib.symbols[`MONERO_Wallet_${type}` as const](wallet.getPointer()));
+} else {
+ const dylib = Deno.dlopen(`tests/libs/${version}/wownero_libwallet2_api_c.so`, wowneroSymbols);
+ loadWowneroDylib(dylib as WowneroTsDylib);
+
+ getKey = async (wallet, type) =>
+ await readCString(
+ await dylib.symbols[`WOWNERO_Wallet_${type}` as const](wallet.getPointer()),
+ );
+}
const walletManager = await WalletManager.new();
const wallet = await Wallet.open(walletManager, walletInfo.path, walletInfo.password);
assertEquals(await wallet.address(), walletInfo.address);
-const getKey = async (wallet: Wallet, type: `${"secret" | "public"}${"Spend" | "View"}Key`) =>
- await readCString(
- await dylib.symbols[`MONERO_Wallet_${type}` as const](wallet.getPointer()),
- );
-
assertEquals(await getKey(wallet, "publicSpendKey"), walletInfo.publicSpendKey);
assertEquals(await getKey(wallet, "secretSpendKey"), walletInfo.secretSpendKey);
diff --git a/tests/regression.test.ts b/tests/regression.test.ts
index 2a0d369..82a9f95 100755
--- a/tests/regression.test.ts
+++ b/tests/regression.test.ts
@@ -17,7 +17,7 @@ Deno.test(`Regression tests (${coin})`, async (t) => {
const walletInfo = await createWalletViaCli(coin, "dog", "sobaka");
for (const version of ["next", latestTag, "next"]) {
- await $`deno run -A ./tests/compare.ts ${version} ${JSON.stringify(walletInfo)}`;
+ await $`deno run -A ./tests/compare.ts ${coin} ${version} ${JSON.stringify(walletInfo)}`;
}
});
@@ -28,7 +28,7 @@ Deno.test(`Regression tests (${coin})`, async (t) => {
for (const version of tags.toReversed()) {
if (version !== "next" && version !== tags[0]) await getMoneroC(coin, version);
- await $`deno run -A ./tests/compare.ts ${version} ${JSON.stringify(walletInfo)}`;
+ await $`deno run -A ./tests/compare.ts ${coin} ${version} ${JSON.stringify(walletInfo)}`;
}
await Deno.remove("./tests/wallets", { recursive: true }).catch(() => {});