-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetStellarAccountActivationStatus.test.ts
More file actions
91 lines (78 loc) · 3 KB
/
Copy pathgetStellarAccountActivationStatus.test.ts
File metadata and controls
91 lines (78 loc) · 3 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {
ClientRequestMethod,
type GetStellarAccountActivationStatusJsonRpcRequest,
} from './api';
import { GetStellarAccountActivationStatusHandler } from './getStellarAccountActivationStatus';
import { KnownCaip2ChainId } from '../../api';
import { AccountService } from '../../services/account';
import { generateStellarKeyringAccount } from '../../services/account/__mocks__/account.fixtures';
import { NetworkService } from '../../services/network';
import { mockOnChainAccountService } from '../../services/on-chain-account/__mocks__/onChainAccount.fixtures';
import { getTestWallet } from '../../services/wallet/__mocks__/wallet.fixtures';
import { logger } from '../../utils/logger';
jest.mock('../../utils/logger');
describe('GetStellarAccountActivationStatusHandler', () => {
const accountId = '11111111-1111-4111-8111-111111111111';
const scope = KnownCaip2ChainId.Mainnet;
function buildRequest(): GetStellarAccountActivationStatusJsonRpcRequest {
return {
jsonrpc: '2.0',
id: 1,
method: ClientRequestMethod.GetStellarAccountActivationStatus,
params: { accountId, scope },
};
}
it('returns activated true when Horizon has the account', async () => {
const wallet = getTestWallet();
const account = generateStellarKeyringAccount(
accountId,
wallet.address,
'entropy-source-1',
0,
);
const resolveAccountSpy = jest
.spyOn(AccountService.prototype, 'resolveAccount')
.mockResolvedValue({ account });
const getAccountOrNullSpy = jest
.spyOn(NetworkService.prototype, 'getAccountOrNull')
.mockResolvedValue({} as never);
const { accountService } = mockOnChainAccountService();
const networkService = new NetworkService({ logger });
const handler = new GetStellarAccountActivationStatusHandler({
logger,
accountService,
networkService,
});
expect(await handler.handle(buildRequest())).toStrictEqual({
activated: true,
});
expect(resolveAccountSpy).toHaveBeenCalledWith({ accountId });
expect(getAccountOrNullSpy).toHaveBeenCalledWith(account.address, scope);
});
it('returns activated false when Horizon has no account', async () => {
const wallet = getTestWallet();
const account = generateStellarKeyringAccount(
accountId,
wallet.address,
'entropy-source-1',
0,
);
jest
.spyOn(AccountService.prototype, 'resolveAccount')
.mockResolvedValue({ account });
const getAccountOrNullSpy = jest
.spyOn(NetworkService.prototype, 'getAccountOrNull')
.mockResolvedValue(null);
const { accountService } = mockOnChainAccountService();
const networkService = new NetworkService({ logger });
const handler = new GetStellarAccountActivationStatusHandler({
logger,
accountService,
networkService,
});
expect(await handler.handle(buildRequest())).toStrictEqual({
activated: false,
});
expect(getAccountOrNullSpy).toHaveBeenCalledWith(account.address, scope);
});
});