summaryrefslogtreecommitdiff
path: root/tests/compare.ts
diff options
context:
space:
mode:
authorCzarek Nakamoto <cyjan@mrcyjanek.net>2024-12-04 12:26:45 -0500
committerCzarek Nakamoto <cyjan@mrcyjanek.net>2024-12-04 12:26:45 -0500
commitecc31787c2174a829848aac403bd13e663fe33c3 (patch)
tree7f505dc9bfe9c34c36c5043911be0cfc0d146a8d /tests/compare.ts
parent24076c5a32bbec3c77cc996cb74dd08d8077a7e0 (diff)
parent40c1a1bda4b6f125c702f5a37ecc48a6ebec24b8 (diff)
Merge branch 'develop' into zano
Diffstat (limited to 'tests/compare.ts')
-rwxr-xr-xtests/compare.ts76
1 files changed, 15 insertions, 61 deletions
diff --git a/tests/compare.ts b/tests/compare.ts
index d09bdd9..2fd27b8 100755
--- a/tests/compare.ts
+++ b/tests/compare.ts
@@ -1,80 +1,34 @@
-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";
+import {
+ loadMoneroDylib,
+ loadWowneroDylib,
+ moneroSymbols,
+ WalletManager,
+ wowneroSymbols,
+} from "../impls/monero.ts/mod.ts";
+
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()));
+ loadMoneroDylib(dylib);
} 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()),
- );
+ loadWowneroDylib(dylib);
}
const walletManager = await WalletManager.new();
-const wallet = await Wallet.open(walletManager, walletInfo.path, walletInfo.password);
+const wallet = await walletManager.openWallet(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 wallet.publicSpendKey(), walletInfo.publicSpendKey);
+assertEquals(await wallet.secretSpendKey(), walletInfo.secretSpendKey);
-assertEquals(await getKey(wallet, "publicViewKey"), walletInfo.publicViewKey);
-assertEquals(await getKey(wallet, "secretViewKey"), walletInfo.secretViewKey);
+assertEquals(await wallet.publicViewKey(), walletInfo.publicViewKey);
+assertEquals(await wallet.secretViewKey(), walletInfo.secretViewKey);
await wallet.store(walletInfo.path);