1 | const Ledger = require('../index.js')
|
2 | const crypto = require('brave-crypto')
|
3 | const test = require('tape')
|
4 |
|
5 | const options = { debugP: true, version: 'v2', environment: 'staging' }
|
6 |
|
7 | test('recoverWallet', async (t) => {
|
8 | t.plan(6)
|
9 | const client = new Ledger(null, options)
|
10 |
|
11 | client.sync(function () {
|
12 | const signingKey = client.getKeypair()
|
13 | const passPhrase = client.getWalletPassphrase()
|
14 | const addresses = client.getWalletAddresses()
|
15 |
|
16 | const client2 = new Ledger(null, options)
|
17 | client2.sync(function () {
|
18 | const signingKey2 = client2.getKeypair()
|
19 | const addresses2 = client2.getWalletAddresses()
|
20 |
|
21 | t.notEqual(crypto.uint8ToHex(signingKey.secretKey), crypto.uint8ToHex(signingKey2.secretKey))
|
22 | t.notEqual(crypto.uint8ToHex(signingKey.publicKey), crypto.uint8ToHex(signingKey2.publicKey))
|
23 | t.notDeepEqual(addresses, addresses2)
|
24 |
|
25 | client2.recoverWallet(null, passPhrase.join(' '), function () {
|
26 | const signingKey3 = client2.getKeypair()
|
27 | const addresses3 = client2.getWalletAddresses()
|
28 |
|
29 | t.equal(crypto.uint8ToHex(signingKey.secretKey), crypto.uint8ToHex(signingKey3.secretKey))
|
30 | t.equal(crypto.uint8ToHex(signingKey.publicKey), crypto.uint8ToHex(signingKey3.publicKey))
|
31 | t.deepEqual(addresses, addresses3)
|
32 | })
|
33 | })
|
34 | })
|
35 | })
|
36 |
|
37 | test('balance', async (t) => {
|
38 | t.plan(2)
|
39 | const client = new Ledger(null, options)
|
40 |
|
41 | client.sync(function () {
|
42 | client.getWalletProperties(function (err, resp) {
|
43 | t.false(err)
|
44 | t.equal(resp.probi, '0')
|
45 | })
|
46 | })
|
47 | })
|
48 |
|
49 | test('promotion', async (t) => {
|
50 | t.plan(7)
|
51 |
|
52 | const client = {
|
53 | sync: (callback) => {
|
54 | callback()
|
55 | },
|
56 | getPromotion: (lang, forPaymentId, callback) => {
|
57 | const resp = {
|
58 | promotionId: '5787de72e-174d-4fb3-bdf6-2e70b2b0ac86'
|
59 | }
|
60 | callback(null, resp)
|
61 | },
|
62 | setPromotion: (promotionId, callback) => {
|
63 | const resp = {
|
64 | probi: '10000000000000000000'
|
65 | }
|
66 | callback(null, resp)
|
67 | },
|
68 | getWalletProperties: (callback) => {
|
69 | const resp = {
|
70 | probi: '10000000000000000000'
|
71 | }
|
72 | callback(null, resp)
|
73 | },
|
74 | getPaymentId: () => {}
|
75 | }
|
76 |
|
77 | const client2 = {
|
78 | getPromotion: (lang, paymentId, callback) => {
|
79 | const err = {
|
80 | message: '404'
|
81 | }
|
82 | callback(err)
|
83 | }
|
84 | }
|
85 |
|
86 | client.sync(function () {
|
87 | client.getPromotion(null, null, function (err, resp) {
|
88 | t.false(err)
|
89 | t.true(resp.hasOwnProperty('promotionId'))
|
90 | const promotionId = resp.promotionId
|
91 | client.setPromotion(promotionId, function (err, resp) {
|
92 | t.false(err)
|
93 | t.true(resp.hasOwnProperty('probi'))
|
94 | const grantProbi = resp.probi
|
95 | client.getWalletProperties(function (err, resp) {
|
96 | t.false(err)
|
97 | t.equal(resp.probi, grantProbi)
|
98 | client2.getPromotion(null, client.getPaymentId(), function (err, resp) {
|
99 | t.true(err)
|
100 | })
|
101 | })
|
102 | })
|
103 | })
|
104 | })
|
105 | })
|