1 |
|
2 |
|
3 |
|
4 | const { expectFetch, mock, mockInfo } = require('../helpers/fetch');
|
5 | const { mockAction, mockOptions } = require('../helpers/eos');
|
6 | const { constructOrejs, mockGetBlock, mockGetInfo, mockGetTransaction } = require('../helpers/orejs');
|
7 |
|
8 | describe('ore', () => {
|
9 | let orejs;
|
10 |
|
11 | beforeAll(() => {
|
12 | orejs = constructOrejs();
|
13 | });
|
14 |
|
15 | describe('getOreBalance', () => {
|
16 | let oreBalance;
|
17 |
|
18 | beforeEach(() => {
|
19 | oreBalance = 30;
|
20 |
|
21 | fetch.resetMocks();
|
22 | fetch.mockResponses(mock([`${oreBalance}.0000 ORE`]));
|
23 | orejs = constructOrejs({ fetch });
|
24 | });
|
25 |
|
26 | it('returns the ore balance', async () => {
|
27 | oreBalance = await orejs.getOreBalance(ORE_TESTA_ACCOUNT_NAME);
|
28 | expect(oreBalance).toEqual(oreBalance);
|
29 | });
|
30 | });
|
31 |
|
32 | describe('transferOre', () => {
|
33 | let oreBalance;
|
34 | let spyTransaction;
|
35 | let transaction;
|
36 |
|
37 | beforeEach(() => {
|
38 | oreBalance = 10;
|
39 | transaction = mockGetTransaction(orejs);
|
40 | spyTransaction = jest.spyOn(orejs.eos, 'transact');
|
41 | });
|
42 |
|
43 | describe('when authorized', () => {
|
44 | it('returns', async () => {
|
45 | const result = await orejs.transferOre(ORE_OWNER_ACCOUNT_NAME, ORE_TESTA_ACCOUNT_NAME, oreBalance);
|
46 | expect(spyTransaction).toHaveBeenCalledWith({ actions: [mockAction({ account: 'eosio.token', name: 'transfer' })] }, mockOptions());
|
47 | });
|
48 | });
|
49 |
|
50 | describe('when unauthorized', () => {
|
51 | xit('throws', () => {
|
52 | mockGetInfo(orejs);
|
53 | mockGetBlock(orejs);
|
54 | contract.approve.mockImplementationOnce(() => Promise.reject(new Error('unauthorized')));
|
55 |
|
56 | const result = orejs.transferOre(ORE_TESTA_ACCOUNT_NAME, ORE_TESTA_ACCOUNT_NAME, oreBalance);
|
57 | expect(result).rejects.toThrow(/unauthorized/);
|
58 | });
|
59 | });
|
60 | });
|
61 | });
|