-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestMoneroWalletKeys.js
More file actions
130 lines (101 loc) · 4.16 KB
/
TestMoneroWalletKeys.js
File metadata and controls
130 lines (101 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const assert = require("assert");
const TestUtils = require("./utils/TestUtils");
const WalletEqualityUtils = require("./utils/WalletEqualityUtils");
const TestMoneroWalletCommon = require("./TestMoneroWalletCommon");
const monerojs = require("../../index");
const MoneroWalletConfig = monerojs.MoneroWalletConfig;
const GenUtils = monerojs.GenUtils;
const MoneroUtils = monerojs.MoneroUtils;
/**
* Tests the implementation of MoneroWallet which only manages keys using WebAssembly.
*/
class TestMoneroWalletKeys extends TestMoneroWalletCommon {
constructor(config) {
super(config);
}
async beforeAll(currentTest) {
await super.beforeAll(currentTest);
}
async beforeEach(currentTest) {
await super.beforeEach(currentTest);
}
async afterAll() {
console.log("After all");
await this.wallet.close();
}
async afterEach(currentTest) {
await super.afterEach(currentTest);
}
async getTestWallet() {
return TestUtils.getWalletKeys();
}
async getTestDaemon() {
return await TestUtils.getDaemonRpc();
}
async openWallet(config) {
throw new Error("TestMoneroWalletKeys.openWallet(config) not applicable, use createWallet()");
}
async createWallet(config) {
// assign defaults
config = new MoneroWalletConfig(config);
if (!config.getPassword()) config.setPassword(TestUtils.WALLET_PASSWORD);
if (config.getNetworkType() === undefined) config.setNetworkType(TestUtils.NETWORK_TYPE);
if (config.getServer()) throw new Error("Cannot initialize keys wallet with connection");
// create wallet
return await monerojs.createWalletKeys(config);
}
async closeWallet(wallet, save) {
await wallet.close(save);
}
async getMnemonicLanguages() {
return await monerojs.MoneroWalletKeys.getMnemonicLanguages();
}
runTests() {
let that = this;
describe("TEST MONERO WALLET KEYS", function() {
// register handlers to run before and after tests
before(async function() { await that.beforeAll(); });
beforeEach(async function() { await that.beforeEach(this.currentTest); });
after(async function() { await that.afterAll(); });
afterEach(async function() { await that.afterEach(this.currentTest); });
// run tests specific to keys wallet
that._testWalletKeys();
// run common tests
that.runCommonTests();
});
}
// ---------------------------------- PRIVATE -------------------------------
_testWalletKeys() {
let that = this;
let config = this.config;
let daemon = this.daemon;
describe("Tests specific to keys wallet", function() {
it("Has the same keys as the RPC wallet", async function() {
await WalletEqualityUtils.testWalletEqualityKeys(await TestUtils.getWalletRpc(), await that.getTestWallet());
});
it("Has the same keys as the RPC wallet with a seed offset", async function() {
// use common offset to compare wallet implementations
let seedOffset = "my super secret offset!";
// create rpc wallet with offset
let walletRpc = await TestUtils.getWalletRpc();
await walletRpc.createWallet({path: GenUtils.getUUID(), password: TestUtils.WALLET_PASSWORD, mnemonic: await walletRpc.getMnemonic(), restoreHeight: TestUtils.FIRST_RECEIVE_HEIGHT, seedOffset: seedOffset});
// create keys-only wallet with offset
let walletKeys = await monerojs.createWalletKeys({
networkType: TestUtils.NETWORK_TYPE,
mnemonic: TestUtils.MNEMONIC,
seedOffset: seedOffset
});
// deep compare
await WalletEqualityUtils.testWalletEqualityKeys(walletRpc, walletKeys);
});
it("Can get the address of a specified account and subaddress index", async function() {
for (let accountIdx= 0; accountIdx < 5; accountIdx++) {
for (let subaddressIdx = 0; subaddressIdx < 5; subaddressIdx++) {
await MoneroUtils.validateAddress(await that.wallet.getAddress(accountIdx, subaddressIdx), TestUtils.NETWORK_TYPE);
}
}
});
});
}
}
module.exports = TestMoneroWalletKeys