UNPKG

4.42 kBJavaScriptView Raw
1/* global ORE_NETWORK_URI:true */
2/* global ORE_OWNER_ACCOUNT_NAME:true */
3/* global ORE_TESTA_ACCOUNT_NAME:true */
4const ORE_TOKEN_CONTRACT = 'token.ore';
5const TOKEN_SYMBOL = 'LUME';
6
7const { expectFetch, mock, mockInfo } = require('./helpers/fetch');
8const { mockAction, mockOptions } = require('./helpers/eos');
9const { constructOrejs, mockGetBlock, mockGetInfo, mockGetTransaction } = require('./helpers/orejs');
10
11describe('ore', () => {
12 let orejs;
13
14 beforeAll(() => {
15 orejs = constructOrejs();
16 });
17
18 describe('getBalance', () => {
19 let oreBalance;
20
21 beforeEach(() => {
22 oreBalance = 30;
23
24 fetch.resetMocks();
25 fetch.mockResponses(mock([`${oreBalance}.0000 ${TOKEN_SYMBOL}`]));
26 orejs = constructOrejs({ fetch });
27 });
28
29 it('returns the ore balance', async () => {
30 oreBalance = await orejs.getBalance(ORE_TESTA_ACCOUNT_NAME, TOKEN_SYMBOL, ORE_TOKEN_CONTRACT);
31 expect(oreBalance).toEqual(oreBalance);
32 });
33 });
34
35 describe('approveTransfer', () => {
36 let oreBalance;
37 let memo;
38 let spyTransaction;
39 let transaction;
40
41 beforeEach(() => {
42 oreBalance = 10;
43 memo = `approve ${TOKEN_SYMBOL} transfer`;
44 fetch.resetMocks();
45 fetch.mockResponses(mock([`${oreBalance}.0000 ${TOKEN_SYMBOL}`]));
46 orejs = constructOrejs({ fetch });
47 transaction = mockGetTransaction(orejs);
48 spyTransaction = jest.spyOn(orejs.eos, 'transact');
49 });
50
51 describe('when authorized', () => {
52 it('returns', async () => {
53 mockGetInfo(orejs);
54 mockGetBlock(orejs);
55 const result = await orejs.approveTransfer(ORE_OWNER_ACCOUNT_NAME, ORE_TESTA_ACCOUNT_NAME, oreBalance, ORE_TOKEN_CONTRACT, memo);
56 expect(spyTransaction).toHaveBeenCalledWith({ actions: [mockAction({ account: ORE_TOKEN_CONTRACT, name: 'approve' })] }, mockOptions());
57 });
58 });
59 });
60
61 describe('createToken', () => {
62 let oreBalance;
63 let spyTransaction;
64 let transaction;
65
66 beforeEach(() => {
67 oreBalance = 10;
68 orejs = constructOrejs({ fetch });
69 transaction = mockGetTransaction(orejs);
70 spyTransaction = jest.spyOn(orejs.eos, 'transact');
71 });
72
73 describe('when authorized', () => {
74 it('returns', async () => {
75 const result = await orejs.createToken(ORE_OWNER_ACCOUNT_NAME, ORE_TESTA_ACCOUNT_NAME, oreBalance, ORE_TOKEN_CONTRACT);
76 expect(spyTransaction).toHaveBeenCalledWith({ actions: [mockAction({ account: ORE_TOKEN_CONTRACT, name: 'create' })] }, mockOptions());
77 });
78 });
79 });
80
81 describe('transferToken', () => {
82 let oreBalance;
83 let spyTransaction;
84 let transaction;
85 let memo;
86 let permission;
87
88 beforeEach(() => {
89 oreBalance = 10;
90 transaction = mockGetTransaction(orejs);
91 spyTransaction = jest.spyOn(orejs.eos, 'transact');
92 memo = 'some note';
93 permission = 'custom';
94 });
95
96 describe('when authorized', () => {
97 it('returns', async () => {
98 const result = await orejs.transferToken(ORE_OWNER_ACCOUNT_NAME, ORE_TESTA_ACCOUNT_NAME, oreBalance, ORE_TOKEN_CONTRACT, memo, permission);
99 expect(spyTransaction).toHaveBeenCalledWith({ actions: [mockAction({ account: ORE_TOKEN_CONTRACT, name: 'transfer' })] }, mockOptions());
100 });
101 });
102
103 describe('when not broadcast', () => {
104 it('returns', async () => {
105 const result = await orejs.transferToken(ORE_OWNER_ACCOUNT_NAME, ORE_TESTA_ACCOUNT_NAME, oreBalance, ORE_TOKEN_CONTRACT, memo, permission, false);
106 expect(spyTransaction).toHaveBeenCalledWith({ actions: [mockAction({ account: ORE_TOKEN_CONTRACT, name: 'transfer' })] }, mockOptions({ broadcast: false }));
107 });
108 });
109 });
110
111 describe('retireToken', () => {
112 let oreBalance;
113 let memo;
114 let spyTransaction;
115 let transaction;
116
117 beforeEach(() => {
118 oreBalance = 10;
119 memo = `retire ${TOKEN_SYMBOL}`;
120 orejs = constructOrejs({ fetch });
121 transaction = mockGetTransaction(orejs);
122 spyTransaction = jest.spyOn(orejs.eos, 'transact');
123 });
124
125 describe('when authorized', () => {
126 it('returns', async () => {
127 const result = await orejs.retireToken(ORE_TESTA_ACCOUNT_NAME, oreBalance, ORE_TOKEN_CONTRACT, memo);
128 expect(spyTransaction).toHaveBeenCalledWith({ actions: [mockAction({ account: ORE_TOKEN_CONTRACT, name: 'retire' })] }, mockOptions());
129 });
130 });
131 });
132});