-
Notifications
You must be signed in to change notification settings - Fork 16
/
balance.spec.js
71 lines (56 loc) · 1.74 KB
/
balance.spec.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
// Copyright 2017-2018 @polkadot/client-db authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { hexToU8a, u8aToHex } from '@polkadot/util';
import testingPairs from '@polkadot/keyring/testingPairs';
import db from './index';
const keyring = testingPairs();
describe.skip('balance', () => {
let staking;
describe('get', () => {
beforeEach(() => {
staking = db({
get: (key) => {
switch (u8aToHex(key)) {
case '0x93b3a06afc9ac6777adff1f6ad2cd5d9':
return hexToU8a('0x4500000000000000');
case '0x8e4b46d94b25bb2f5c9fa65f60263160':
return hexToU8a('0x2a00000000000000');
default:
return new Uint8Array([]);
}
}
}).staking;
});
it('returns balances', () => {
expect(
staking.freeBalanceOf.get(keyring.alice.publicKey()).toNumber()
).toEqual(42);
expect(
staking.freeBalanceOf.get(keyring.bob.publicKey()).toNumber()
).toEqual(69);
});
it('returns zero balances', () => {
expect(
staking.freeBalanceOf.get(keyring.charlie.publicKey()).toNumber()
).toEqual(0);
});
});
describe('set', () => {
beforeEach(() => {
const store = {};
staking = db({
get: (key) => store[u8aToHex(key)] || new Uint8Array([]),
put: (key, value) => {
store[u8aToHex(key)] = value;
}
}).staking;
});
it('sets balances', () => {
staking.freeBalanceOf.set(123, keyring.alice.publicKey());
expect(
staking.freeBalanceOf.get(keyring.alice.publicKey()).toNumber()
).toEqual(123);
});
});
});