@mentaproject/client 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,8 +45,11 @@ describe('Account', () => {
45
45
  parse: jest.fn().mockImplementation((data) => new Transaction(mockMentaClient, data)),
46
46
  send: jest.fn(),
47
47
  } as any;
48
+ mockMentaClient.accounts = {
49
+ get: jest.fn().mockImplementation((address) => new Account(mockMentaClient, { address: address })),
50
+ } as any;
48
51
  mockPersistenceManager = new MockedPersistenceManager(mockMentaClient, {} as any) as jest.Mocked<PersistenceManager>;
49
- account = new Account(mockMentaClient, mockAddress, mockPersistenceManager);
52
+ account = new Account(mockMentaClient, { address: mockAddress }, mockPersistenceManager);
50
53
  });
51
54
 
52
55
  describe('constructor', () => {
@@ -151,7 +154,7 @@ describe('Account', () => {
151
154
  });
152
155
 
153
156
  it('should fetch transactions from remote if persistence is not configured', async () => {
154
- const localAccount = new Account(mockMentaClient, mockAddress); // No persistenceManager
157
+ const localAccount = new Account(mockMentaClient, { address: mockAddress }); // No persistenceManager
155
158
  const mockHashes: Hash[] = ['0x1', '0x2'];
156
159
  const mockBaseTx = {
157
160
  blockHash: '0xblockhash',
@@ -195,14 +198,14 @@ describe('Account', () => {
195
198
  });
196
199
 
197
200
  it('should throw an error if persistence manager is not configured', async () => {
198
- const localAccount = new Account(mockMentaClient, mockAddress);
201
+ const localAccount = new Account(mockMentaClient, { address: mockAddress });
199
202
  await expect(localAccount.syncTransactions()).rejects.toThrow('The persistence module is not configured.');
200
203
  });
201
204
  });
202
205
 
203
206
  describe('tokenTransactions', () => {
204
207
  it('should throw an error if persistence is not configured', async () => {
205
- const localAccount = new Account(mockMentaClient, mockAddress);
208
+ const localAccount = new Account(mockMentaClient, { address: mockAddress });
206
209
  await expect(localAccount.tokenTransactions(mockAddress)).rejects.toThrow('The persistence module is not configured.');
207
210
  });
208
211
 
@@ -218,12 +221,12 @@ describe('Account', () => {
218
221
  (coreActions.getBalance as jest.Mock).mockResolvedValue(100n);
219
222
  (coreActions.getTransactionCount as jest.Mock).mockResolvedValue(5);
220
223
 
221
- const json = await account.toJSON();
224
+ const json = await account.toJSON(1);
222
225
 
223
226
  expect(json.address).toBe(mockAddress);
224
227
  expect(json.isContract).toBe(true);
225
228
  expect(json.contractType).toBe('ERC20');
226
- expect(json.ETHBalance).toBe('100');
229
+ expect(json.ETHBalance).toBe('100n');
227
230
  expect(json.transactionCount).toBe(5);
228
231
  });
229
232
  });
@@ -3,7 +3,7 @@ import { MentaClient } from '../../src/structures/MentaClient';
3
3
  import { Account } from '../../src/structures/Account';
4
4
  import { Transaction } from '../../src/structures/Transaction';
5
5
  import { Address, Hash } from '@mentaproject/core/types';
6
- import { BlockData } from '../../src/types';
6
+ import { Block as RawBloc } from '@mentaproject/core';
7
7
 
8
8
  // Mocking MentaClient
9
9
  const mockMentaClient = {
@@ -21,7 +21,7 @@ describe('Block', () => {
21
21
  const mockMinerAddress: Address = '0xminer123';
22
22
  const mockTxHash: Hash = '0xhash123';
23
23
 
24
- const mockBlockData: BlockData = {
24
+ const mockBlockData: RawBloc = {
25
25
  number: 123n,
26
26
  hash: '0xblockhash',
27
27
  parentHash: '0xparenthash',
@@ -59,7 +59,7 @@ describe('Block', () => {
59
59
  expect(block).toBeInstanceOf(Block);
60
60
  expect(block.number).toBe(123n);
61
61
  expect(block.hash).toBe('0xblockhash');
62
- expect(Account).toHaveBeenCalledWith(mockMentaClient, mockMinerAddress);
62
+ expect(Account).toHaveBeenCalledWith(mockMentaClient, { address: mockMinerAddress });
63
63
  expect(block.miner).toBeInstanceOf(Account);
64
64
  });
65
65
 
@@ -88,9 +88,9 @@ describe('Block', () => {
88
88
  describe('toJSON', () => {
89
89
  it('should return a JSON representation of the block', async () => {
90
90
  const block = new Block(mockMentaClient, mockBlockData);
91
- const json = await block.toJSON();
91
+ const json = await block.toJSON(1);
92
92
 
93
- expect(json.number).toBe('123');
93
+ expect(json.number).toBe('123n');
94
94
  expect(json.hash).toBe('0xblockhash');
95
95
  expect(json.miner).toBeUndefined();
96
96
  });
@@ -13,15 +13,17 @@ jest.mock('@mentaproject/core/actions', () => ({
13
13
  getBlock: jest.fn(),
14
14
  }));
15
15
 
16
- // Mocking MentaClient
17
- const mockMentaClient = {
18
- rpc: {},
19
- } as unknown as MentaClient;
20
-
21
16
  // Mocking structures
22
17
  jest.mock('../../src/structures/Account');
23
18
  jest.mock('../../src/structures/Block');
24
19
 
20
+ const mockMentaClient = {
21
+ rpc: {},
22
+ accounts: {
23
+ get: jest.fn(),
24
+ },
25
+ } as unknown as MentaClient;
26
+
25
27
  describe('Transaction', () => {
26
28
  const mockTxHash: Hash = '0xabcdef123456';
27
29
  const mockFromAddress: Address = '0xfrom123';
@@ -50,6 +52,9 @@ describe('Transaction', () => {
50
52
 
51
53
  beforeEach(() => {
52
54
  jest.clearAllMocks();
55
+ (mockMentaClient.accounts.get as jest.Mock).mockImplementation(
56
+ (address: Address) => new Account(mockMentaClient, { address }),
57
+ );
53
58
  transaction = new Transaction(mockMentaClient, mockRawTx);
54
59
  });
55
60
 
@@ -58,8 +63,8 @@ describe('Transaction', () => {
58
63
  expect(transaction).toBeInstanceOf(Transaction);
59
64
  expect(transaction.hash).toBe(mockTxHash);
60
65
  expect(transaction.value).toBe(1000n);
61
- expect(Account).toHaveBeenCalledWith(mockMentaClient, mockFromAddress);
62
- expect(Account).toHaveBeenCalledWith(mockMentaClient, mockToAddress);
66
+ expect(mockMentaClient.accounts.get).toHaveBeenCalledWith(mockFromAddress);
67
+ expect(mockMentaClient.accounts.get).toHaveBeenCalledWith(mockToAddress);
63
68
  expect(transaction.from).toBeInstanceOf(Account);
64
69
  expect(transaction.to).toBeInstanceOf(Account);
65
70
  });
@@ -135,7 +140,7 @@ describe('Transaction', () => {
135
140
  jest.spyOn(transaction, 'receipt').mockResolvedValue({ toJSON: () => ({ receipt: 'data' }) } as any);
136
141
  jest.spyOn(transaction, 'calls').mockResolvedValue([{ toJSON: () => ({ call: 'data' }) } as any]);
137
142
 
138
- const json = await transaction.toJSON();
143
+ const json = await transaction.toJSON(1);
139
144
 
140
145
  expect(json.hash).toBe(mockTxHash);
141
146
  expect(json.block).toBeDefined();
@@ -34,16 +34,16 @@ describe('toJSON', () => {
34
34
  it('should convert bigints to strings', async () => {
35
35
  const obj = { a: 1n, b: { c: 2n } };
36
36
  const json = await toJSON({ obj });
37
- expect(json).toEqual({ a: '1', b: { c: '2' } });
37
+ expect(json).toEqual({ a: '1n', b: { c: '2n' } });
38
38
  });
39
39
 
40
40
  it('should handle nested class instances', async () => {
41
41
  const instance = new MockClass();
42
42
  const json = await toJSON({ obj: instance, depth: 1 });
43
43
  expect(json.a).toBe('a');
44
- expect(json.c).toBe('123');
44
+ expect(json.c).toBe('123n');
45
45
  expect(json.d).toEqual({ value: 'sub' });
46
- expect(json.e).toEqual({ f: '456' });
46
+ expect(json.e).toEqual({ f: '456n' });
47
47
  });
48
48
 
49
49
  it('should handle getters with depth > 0', async () => {
@@ -72,6 +72,6 @@ describe('toJSON', () => {
72
72
  it('should handle arrays with bigints', async () => {
73
73
  const obj = { data: [1n, 2n, { value: 3n }] };
74
74
  const json = await toJSON({ obj });
75
- expect(json).toEqual({ data: ['1', '2', { value: '3' }] });
75
+ expect(json).toEqual({ data: ['1n', '2n', { value: '3n' }] });
76
76
  });
77
77
  });