Skip to content

Commit

Permalink
feat: actually test polyseeds in the integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Oct 21, 2024
1 parent 31c31a5 commit 1a45a7a
Show file tree
Hide file tree
Showing 46 changed files with 109 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ release/
build/
tests/monero-cli
tests/libs
tests/wallets/*
!tests/wallets/monero
tests/wallets
9 changes: 9 additions & 0 deletions impls/monero.ts/src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export const moneroSymbols = {
// void*
result: "pointer",
},
"MONERO_WalletManager_createWalletFromPolyseed": {
nonblocking: true,
// void* wm_ptr, const char* path, const char* password, int nettype,
// const char* mnemonic, const char* passphrase, bool newWallet,
// uint64_t restore_height, uint64_t kdf_rounds
parameters: ["pointer", "pointer", "pointer", "i32", "pointer", "pointer", "bool", "u64", "u64"],
// void*
result: "pointer",
},
"MONERO_WalletManager_blockchainHeight": {
nonblocking: true,
// void* wm_ptr
Expand Down
52 changes: 52 additions & 0 deletions impls/monero.ts/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,58 @@ export class Wallet {
return wallet;
}

static async recoverFromPolyseed(
walletManager: WalletManager,
path: string,
password: string,
mnemonic: string,
restoreHeight: bigint,
passphrase = "",
sanitizeError = true,
): Promise<Wallet> {
return await this.createFromPolyseed(
walletManager,
path,
password,
mnemonic,
restoreHeight,
passphrase,
sanitizeError,
false,
);
}

static async createFromPolyseed(
walletManager: WalletManager,
path: string,
password: string,
mnemonic: string,
restoreHeight: bigint,
passphrase = "",
sanitizeError = true,
newWallet = true,
): Promise<Wallet> {
// We assign holder of the pointer in Wallet constructor
const walletManagerPtr = walletManager.getPointer();

const walletPtr = await getSymbol("WalletManager_createWalletFromPolyseed")(
walletManagerPtr,
CString(path),
CString(password),
0,
CString(mnemonic),
CString(passphrase),
newWallet,
restoreHeight,
1n,
);

const wallet = new Wallet(walletManager, walletPtr as WalletPtr, walletManager.sanitizer);
await wallet.throwIfError(sanitizeError);

return wallet;
}

async close(store: boolean): Promise<void> {
await getSymbol("WalletManager_closeWallet")(
this.#walletManagerPtr,
Expand Down
56 changes: 47 additions & 9 deletions tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ async function getKey(wallet: Wallet, type: `${"secret" | "public"}${"Spend" | "
// TODO: Change for custom address on CI
const NODE_URL = "https://nodes.hashvault.pro:18081";

await getMoneroC(coin, "next");
// await getMoneroC(coin, "next");

interface WalletInfo {
coin: "monero" | "wownero";

name: string;
password: string;
seed: string;
offset?: unknown;
offset?: string;
address: string;
restoreHeight: bigint;

publicSpendKey: string;
secretSpendKey: string;
Expand All @@ -44,6 +45,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
password: "englishwallet",
seed:
"tortoise winter play argue laptop diary tell library travel cupboard view river embark rubber plunge student",
restoreHeight: 3254619n,
address: "49PL6qHMkc4Hw3dWT5wy5NbbVd2xda8zw3tLx2BoQsNZUWDQYYpwMEKjB9BLbEKSo3S3z34bncFw6ijToTwfiEJJ5m8aefx",
publicSpendKey: "ccd6846ab69fdd653a8d092d89590dced40aa2862f3c24113fedfcd6469162a4",
secretSpendKey: "37fd2e3e933c8468beb407e5350789e23bed5df33eeeb35d3b119401988e6709",
Expand All @@ -55,6 +57,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
name: "Chinese Traditional Wallet",
password: "chinesetraditionalwallet",
seed: "旗 铁 革 酯 紧 毅 饱 应 第 兄 植 隙 点 吐 童 赞",
restoreHeight: 3254619n,
address: "4AR8YW51Ga3DR4a47F5J8rXaqyBa8pnnF557pTyt52ZqNMFa3gfxvi13R7sbt5zHfjbF5aKsLFZQrRod3qcr5MQj4f91rLh",
publicSpendKey: "e80bab7b3e2d384a393b825cf4f2abb6d8d08f1742d87c1856c064a609a0647f",
secretSpendKey: "c7de78f9819db6755e14d2e1411f1591c2d0b3a6ee19049c30e270f81eb50401",
Expand All @@ -66,6 +69,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
name: "Chinese Simplified Wallet",
password: "chinesesimplifiedwallet",
seed: "纹 触 集 驶 朋 辨 你 版 是 益 驳 修 偏 汽 录 吨",
restoreHeight: 3254619n,
address: "47E7p1mFGNj59QNfjpXcopP1YZuGdn7NhYJv25xbPKdicnThww5DUv2aNMH7oPWsKZjQQmXMkBzUze2T6gAaXafLAF9E4Dz",
publicSpendKey: "93dec0155d30b818c7d64a0b0c3a678395e3e28bdd736abb2ef7c360b38449d5",
secretSpendKey: "60084b4ff3d99d6ca38876078721c13692635429c74ef5d71f03310cf2e0690b",
Expand All @@ -78,6 +82,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
password: "japanesewallet",
seed:
"きほん ことば そうび きどう なまえ ひさしぶり ごうけい ふひょう ぎゅうにく しはらい きびしい はんとし ととのえる たかい とかい るりがわら",
restoreHeight: 3254619n,
address: "45YYsW5do7NjGSaRZPAkPQ9mi4HQsMv3w86HFddtkZi4cCbqtFiVoqJjdFobCtCwpBPZWSnUtmrU2G9fLpEE7vsQU3aZyeE",
publicSpendKey: "677ac034b7c3e9fcb178370e3df067346ff5703db8273e2a65010862a85935d2",
secretSpendKey: "1fe9110cc46c58ed0f5cb6c6e189e246f6c3cfbf459de2ed1565838b6e08780e",
Expand All @@ -89,6 +94,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
name: "Korean Wallet",
password: "koreanwallet",
seed: "단골 운전 일대 제작 구역 보자기 대한민국 답장 쇼핑 논문 편견 대전 충돌 강당 형제 볼펜",
restoreHeight: 3254619n,
address: "42DNYppLMXki8j3urYuXaTU1S9EBrSJ71aVNbzr4fKfnXryMwJ2rFt6Y5eCP9vpej9AdrZqNFXDFB1VmkjzjX5e5URJ9q8c",
publicSpendKey: "0f96caeac7cd4ff5eb55810b4eb87ca1779637e949d138c837fe9a776b3c51b8",
secretSpendKey: "d86c40f13694e7511499cdb22db4e96ee2990cfffde52274248bb8818a36c406",
Expand All @@ -101,6 +107,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
password: "portugesewallet",
seed:
"inscrito raposa vermelho medusa apetite bacharel quantia usado poupar pilotar sigilo ideia robalo ignorado desgaste intimar",
restoreHeight: 3254619n,
address: "43xw29tpLnU5VaPZ8Nuzz7DqrnUip5tmWBn3aukkZAyzgHTscJHvESy6pmYutLebQAB9TJgGhoCAWhPK6WJ39CpiD29fbwj",
publicSpendKey: "3dcbbde593acc11adc291eeeec8bc44cc7943192d54fb1406de435b4d7b73dea",
secretSpendKey: "9b94f57038b07b8280f27cedbed6e53472b48fe4683de15cc9e034fdddfcbb05",
Expand All @@ -113,6 +120,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
password: "czechwallet",
seed:
"ulice louskat odmlka parodie dominant slanina sukno vodivost zimnice vykonat sundat kalibr dobro moucha kometa legenda",
restoreHeight: 3254619n,
address: "499LrJgGPkFA1BPvF4xqr5bwZfKyCZah1C2CEhvqpW7YGQddwWYyR2L1F1TJhqyxxwa4TXKYZM4bb8ukq3kein1cPMNLLi4",
publicSpendKey: "c6796799947e0c35d3720af264d6a6d0e5a574cea1cde441e343b828a00c875c",
secretSpendKey: "61f9c86a71744a101c36b5628c1c4324e49e84861f136cbd2d0f1477ba5ace0b",
Expand All @@ -124,6 +132,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
name: "Spanish Wallet",
password: "spanishwallet",
seed: "rehén torpedo remo existir fuente dama culpa riqueza cebolla supremo vereda odio novio sumar espía margen",
restoreHeight: 3254619n,
address: "41xeBwVJEpVVrJntrvUXafJR4mk9x3tfW3zXxamh8G951SM9BbBLgJSgzwdCywLRrbZvipLL2Azu9jKbu4Y9Hey3MUF6f19",
publicSpendKey: "08e31c09ad35beac7bcb9e4a689e40681df1b42cd2686511e344d02606bfc802",
secretSpendKey: "19ae689bdd594fde5d06b66e4c7a89d9783c02694ae615e33928b38f0c52120c",
Expand All @@ -136,6 +145,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
password: "italianwallet",
seed:
"fuso rinvenire astenuto camicia erboso icona bollito esito spettrale abisso dogma appunto prefisso gracile podismo araldica",
restoreHeight: 3254619n,
address: "46Kkbh8jLorHRKJEV7C4hNczZknHeB6w4GHpLWkpfThMdPLeeU8MFRmDfMqioYyacCTAG9wZ9y9UHZDNhehEssDVHePj3Ja",
publicSpendKey: "7c0b928d9d8349622a07673a9721e9d72f60ccfc8e83935b699c379999104cd9",
secretSpendKey: "673b61bdb369cc61a022e0eab47e5e41cf86e99a80979f75ebcda1219ee0ab01",
Expand All @@ -150,6 +160,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
password: "englishwallet",
seed: "loud fix cattle broken right main web rather write aunt left nation broken ship program ten",
offset: "englishoffset",
restoreHeight: 3263855n,
address: "4B2QGWy9as7bwwLNq2DQ26Q3woahpTLbR7d8vJE1uKL5gobU9iMydFqbVrYa9ixfrnAvnuwT9BXpkBx1APocbJfb2drFuQi",
publicSpendKey: "f817ca86625d1ed0ef81ccb8a4e82b89cfc3345512c7b82798ba2f5982b7daed",
secretSpendKey: "39ae15e92e08a0903652b4b0f187d740d2a5bf08e77879babb345b9a78ca6504",
Expand All @@ -168,13 +179,25 @@ Deno.test("0001-polyseed.patch", async (t) => {
loadWowneroDylib(dylib);
}

await Deno.remove("tests/wallets/", { recursive: true }).catch(() => {});
await Deno.mkdir("tests/wallets/");

for (const walletInfo of WALLETS) {
if (walletInfo.coin !== coin) continue;

await t.step(walletInfo.name, async () => {
const walletManager = await WalletManager.new();
const path = `tests/wallets/monero/${walletInfo.name}/${walletInfo.name}`;
const wallet = await Wallet.open(walletManager, path, walletInfo.password);
const path = `tests/wallets/${walletInfo.name}`;

const wallet = await Wallet.recoverFromPolyseed(
walletManager,
path,
walletInfo.password,
walletInfo.seed,
walletInfo.restoreHeight,
walletInfo.offset,
);

await wallet.initWallet(NODE_URL);

assertEquals(await wallet.address(), walletInfo.address);
Expand All @@ -184,15 +207,17 @@ Deno.test("0001-polyseed.patch", async (t) => {

assertEquals(await getKey(wallet, "publicViewKey"), walletInfo.publicViewKey);
assertEquals(await getKey(wallet, "secretViewKey"), walletInfo.secretViewKey);

await wallet.store();
});
}

dylib.close();
});

Deno.test("0002-wallet-background-sync-with-just-the-view-key.patch", async () => {
await Deno.remove("tests/wallets/tmp", { recursive: true }).catch(() => {});
await Deno.mkdir("tests/wallets/tmp");
await Deno.remove("tests/wallets/", { recursive: true }).catch(() => {});
await Deno.mkdir("tests/wallets/");

let dylib: Dylib;
if (coin === "monero") {
Expand All @@ -204,7 +229,7 @@ Deno.test("0002-wallet-background-sync-with-just-the-view-key.patch", async () =
}

const walletManager = await WalletManager.new();
const wallet = await Wallet.create(walletManager, "tests/wallets/tmp/squirrel", "belka");
const wallet = await Wallet.create(walletManager, "tests/wallets/squirrel", "belka");
await wallet.initWallet(NODE_URL);

const walletInfo = {
Expand All @@ -221,7 +246,7 @@ Deno.test("0002-wallet-background-sync-with-just-the-view-key.patch", async () =

const backgroundWallet = await Wallet.open(
walletManager,
"tests/wallets/tmp/squirrel.background",
"tests/wallets/squirrel.background",
"background-belka",
);
await backgroundWallet.initWallet(NODE_URL);
Expand All @@ -241,7 +266,7 @@ Deno.test("0002-wallet-background-sync-with-just-the-view-key.patch", async () =

await backgroundWallet.close(true);

const reopenedWallet = await Wallet.open(walletManager, "tests/wallets/tmp/squirrel", "belka");
const reopenedWallet = await Wallet.open(walletManager, "tests/wallets/squirrel", "belka");
await reopenedWallet.throwIfError();
await reopenedWallet.refreshAsync();

Expand All @@ -259,3 +284,16 @@ Deno.test("0002-wallet-background-sync-with-just-the-view-key.patch", async () =

dylib.close();
});

Deno.test("0009-Add-recoverDeterministicWalletFromSpendKey.patch", async (t) => {
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);
}

await dylib.close();
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Czech Wallet/#_Czech Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Czech Wallet/Czech Wallet
Binary file not shown.
Binary file removed tests/wallets/monero/Czech Wallet/Czech Wallet.keys
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/English Wallet/#_English Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/English Wallet/English Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/French Wallet/#_French Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/French Wallet/French Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Italian Wallet/#_Italian Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Italian Wallet/Italian Wallet
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Korean Wallet/#_Korean Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Korean Wallet/Korean Wallet
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Spanish Wallet/#_Spanish Wallet
Binary file not shown.
Binary file not shown.
Binary file removed tests/wallets/monero/Spanish Wallet/Spanish Wallet
Binary file not shown.
Binary file not shown.

0 comments on commit 1a45a7a

Please sign in to comment.