UNPKG

1.88 kBJavaScriptView Raw
1/* global ORE_NETWORK_URI:true */
2/* global ORE_OWNER_ACCOUNT_NAME:true */
3/* global ORE_TESTA_ACCOUNT_NAME:true */
4const { expectFetch, mock, mockInfo } = require('../helpers/fetch');
5const { mockAction, mockOptions } = require('../helpers/eos');
6const { constructOrejs, mockGetBlock, mockGetInfo, mockGetTransaction } = require('../helpers/orejs');
7
8describe('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});