summaryrefslogtreecommitdiff
path: root/tests/compare.ts
diff options
context:
space:
mode:
authorMateusz Franik <47059999+Im-Beast@users.noreply.github.com>2024-10-16 07:55:11 +0200
committerGitHub <noreply@github.com>2024-10-16 07:55:11 +0200
commitfd7bb6ae1c27ffe5d41f3a818ee9034d9bb76138 (patch)
tree01e57a1c483370a3f023ed27d401069502694396 /tests/compare.ts
parent44fd5e17bbce52caf681850ac79f463d9ce6bb31 (diff)
feat: wownero typescript bindings, regression tests (#71)
* regression tests * ci: move regression_check to full_check workflow, reuse artifact build * feat: support wownero in monero.ts bindings * ci: test wownero regressions as well * extract wownero-cli as wownero * actually load wownero when specified * fix: commitUR not being a symbol in wownero
Diffstat (limited to 'tests/compare.ts')
-rwxr-xr-xtests/compare.ts80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/compare.ts b/tests/compare.ts
new file mode 100755
index 0000000..d09bdd9
--- /dev/null
+++ b/tests/compare.ts
@@ -0,0 +1,80 @@
+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 coin = Deno.args[0] as "monero" | "wownero";
+const version = Deno.args[1];
+const walletInfo = JSON.parse(Deno.args[2]);
+
+const moneroSymbols = {
+ ...symbols,
+
+ "MONERO_Wallet_secretViewKey": {
+ nonblocking: true,
+ // void* wallet_ptr
+ parameters: ["pointer"],
+ // const char*
+ result: "pointer",
+ },
+ "MONERO_Wallet_publicViewKey": {
+ nonblocking: true,
+ // void* wallet_ptr
+ parameters: ["pointer"],
+ // const char*
+ result: "pointer",
+ },
+
+ "MONERO_Wallet_secretSpendKey": {
+ nonblocking: true,
+ // void* wallet_ptr
+ parameters: ["pointer"],
+ // const char*
+ result: "pointer",
+ },
+ "MONERO_Wallet_publicSpendKey": {
+ nonblocking: true,
+ // void* wallet_ptr
+ parameters: ["pointer"],
+ // const char*
+ result: "pointer",
+ },
+} as const;
+
+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);
+
+assertEquals(await getKey(wallet, "publicSpendKey"), walletInfo.publicSpendKey);
+assertEquals(await getKey(wallet, "secretSpendKey"), walletInfo.secretSpendKey);
+
+assertEquals(await getKey(wallet, "publicViewKey"), walletInfo.publicViewKey);
+assertEquals(await getKey(wallet, "secretViewKey"), walletInfo.secretViewKey);
+
+await wallet.store(walletInfo.path);