This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathaccount.test.js
89 lines (74 loc) · 3.26 KB
/
account.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
import { expect } from 'chai';
import { mock } from 'sinon';
import { getAccount, setSecondPassphrase, send,
extractPublicKey, extractAddress } from './account';
describe('Utils: Account', () => {
const address = '1449310910991872227L';
describe.skip('getAccount', () => {
let activePeerMock;
const activePeer = {
getAccount: () => { },
};
beforeEach(() => {
activePeerMock = mock(activePeer);
});
afterEach(() => {
activePeerMock.verify();
activePeerMock.restore();
});
it('should return a promise that is resolved when activePeer.getAccount() calls its callback with data.success == true', () => {
const account = { address, balance: 0, publicKey: null };
const response = { success: true, account };
activePeerMock.expects('getAccount').withArgs(address).callsArgWith(1, response);
const requestPromise = getAccount(activePeer, address);
return expect(requestPromise).to.eventually.eql({
...account,
serverPublicKey: null,
});
});
it('should return a promise that is resolved even when activePeer.getAccount() calls its callback with data.success == false and "Account not found"', () => {
const response = { success: false, error: 'Account not found' };
const account = { address, balance: 0 };
activePeerMock.expects('getAccount').withArgs(address).callsArgWith(1, response);
const requestPromise = getAccount(activePeer, address);
return expect(requestPromise).to.eventually.eql(account);
});
it('should otherwise return a promise that is rejected', () => {
const response = { success: false };
activePeerMock.expects('getAccount').withArgs(address).callsArgWith(1, response);
const requestPromise = getAccount(activePeer, address);
return expect(requestPromise).to.eventually.be.rejectedWith(response);
});
});
describe('setSecondPassphrase', () => {
it('should return a promise', () => {
const promise = setSecondPassphrase();
expect(typeof promise.then).to.be.equal('function');
});
});
describe('send', () => {
it('should return a promise', () => {
const promise = send();
expect(typeof promise.then).to.be.equal('function');
});
});
describe('extractPublicKey', () => {
it('should return a Hex string from any given string', () => {
const passphrase = 'field organ country moon fancy glare pencil combine derive fringe security pave';
const publicKey = 'a89751689c446067cc2107ec2690f612eb47b5939d5570d0d54b81eafaf328de';
expect(extractPublicKey(passphrase)).to.be.equal(publicKey);
});
});
describe('extractAddress', () => {
it('should return the account address from given passphrase', () => {
const passphrase = 'field organ country moon fancy glare pencil combine derive fringe security pave';
const derivedAddress = '440670704090200331L';
expect(extractAddress(passphrase)).to.be.equal(derivedAddress);
});
it('should return the account address from given public key', () => {
const publicKey = 'a89751689c446067cc2107ec2690f612eb47b5939d5570d0d54b81eafaf328de';
const derivedAddress = '440670704090200331L';
expect(extractAddress(publicKey)).to.be.equal(derivedAddress);
});
});
});