forked from ravenrebels/ravencoin-key
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
96 lines (81 loc) · 3.43 KB
/
test.js
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
const TelestaiKey = require("./dist/main");
test("Random mnemonic should contain 12 words", () => {
const mnemonic = TelestaiKey.generateMnemonic();
expect(mnemonic.split(" ").length).toBe(12);
});
test("Validate address on main-net", () => {
const network = "tls";
const mnemonic =
"orphan resemble brain dwarf bus fancy horn among cricket logic duty crater";
const address = TelestaiKey.getAddressPair(network, mnemonic, 0, 1);
expect(address.external.address).toBe("TxSKpGLR58VUFzBJ8pjkDgNnNKmvGyWL4t");
});
test("Validate Wallet Import Format (WIF) main-net ", () => {
const network = "tls";
const mnemonic =
"orphan resemble brain dwarf bus fancy horn among cricket logic duty crater";
const address = TelestaiKey.getAddressPair(network, mnemonic, 0, 1);
expect(address.internal.address).toBe("Td8haX27FhJ1TeTdj9z1DX6296FCqaRRxF");
expect(address.external.WIF).toBe("KybNCdSZVUdqCdaq95mtcskGd4K2cWvnYNZcJ3mo1gDY9ZtySiR6");
});
test("Validate get public address from Wallet Import Format (WIF) main-net ", () => {
const network = "tls";
const WIF = "L1CQvWc2hCVdLNKYeWDrMDfWvzUhpxQDGRMHJTBmUc1LpjqFd3qf";
const addressObject = TelestaiKey.getAddressByWIF(network, WIF);
expect(addressObject.address).toBe("ThYNJX9F4xSdiZMBQXWCTMYLxqpAhrzYV3");
});
test("Valid bytes to mnemonic", () => {
const hexString = "a10a95fb55808c5f15dc97ecbcd26cf0";
const bytes = Uint8Array.from(Buffer.from(hexString, "hex"));
const mnemonic = TelestaiKey.entropyToMnemonic(bytes);
expect(mnemonic).toBe(
"patient feed learn prison angle convince first napkin uncover track open theory"
);
});
test("Non valid bytes to mnemonic should fail", () => {
const hexString = "a10a94fb55808c5f15dc97ecbcd26cf0";
const bytes = Uint8Array.from(Buffer.from(hexString, "hex"));
const mnemonic = TelestaiKey.entropyToMnemonic(bytes);
expect(mnemonic).not.toBe(
"patient feed learn prison angle convince first napkin uncover track open theory"
);
});
describe("Validate diff languages", () => {
it("Should accept spanish mnemonic", () => {
const m =
"velero nuera pepino reír barro reforma negar rumbo atento separar pesa puma";
const valid = TelestaiKey.isMnemonicValid(m);
expect(valid).toBe(true);
});
it("Should accept French mnemonic", () => {
const m =
"vaseux mixte ozone quiétude besogne punaise membre réussir avarice samedi pantalon poney";
const valid = TelestaiKey.isMnemonicValid(m);
expect(valid).toBe(true);
});
});
it("Should accept Italian mnemonic", () => {
const m =
"veloce perforare recinto sciroppo bici scelto parabola sguardo avanzato sonnifero remoto rustico";
const valid = TelestaiKey.isMnemonicValid(m);
expect(valid).toBe(true);
});
describe("generateAddress", () => {
it("should generate an address with a mnemonic", () => {
const result = TelestaiKey.generateAddressObject();
expect(result).toHaveProperty("mnemonic");
expect(result.mnemonic).toBeDefined();
expect(result.network).toBe("tls");
expect(result).toHaveProperty("address");
});
// it("default network should be tls for Telestai", () => {
// const network = "tls-test";
// const result = TelestaiKey.generateAddressObject(network);
// expect(result.network).toBe(network);
// });
// it("Should handle tls", () => {
// const network = "tls-test";
// const result = TelestaiKey.generateAddressObject(network);
// expect(result.network).toBe(network);
// });
});