| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import nock from 'nock';
- import { BankClient } from '../src/index';
- import { StorageNode } from '../src/storage-node';
- import { IWebClient } from '../src/webclient';
- import { WebClientNode } from '../src/webclient-node';
- import { CryptoNode } from './../src/crypto-node';
- import { IWebClientOptions } from './../src/webclient-options';
- describe('BankClient', () => {
- const storage = new StorageNode('bankConfig');
- const cryptoNode = new CryptoNode();
- test('should successfully bootstrap', async () => {
- class FakeWebClient implements IWebClient {
- public requestJSON(options: object): Promise<object> {
- throw new Error("Method not implemented.");
- }
- public request(options: IWebClientOptions): Promise<string> {
- throw new Error("Method not implemented.");
- }
- }
- const bankClient = new BankClient('/urlBase', '/ipfsBase', storage, new FakeWebClient(), cryptoNode);
- const strapped = await bankClient.bootstrap();
- expect(strapped).toBeDefined();
- });
- test('should return hardcoded nonce', async () => {
- class FakeWebClient implements IWebClient {
- public requestJSON(options: object): Promise<object> {
- throw new Error("Method not implemented.");
- }
- public request(options: IWebClientOptions): Promise<string> {
- return Promise.resolve('42');
- }
- }
- const bankClient = new BankClient('/urlBase', '/ipfsBase', storage, new FakeWebClient(), cryptoNode);
- await bankClient.bootstrap();
- const nonce = await bankClient.getNonce();
- expect(nonce).toEqual(42);
- });
- describe('get nonce', () => {
- test('should work with real http client', async () => {
- const webClient = new WebClientNode();
- const bankClient = new BankClient('http://127.0.0.1:8000', '/ipfsBase', storage, webClient, cryptoNode);
- await bankClient.bootstrap();
- nock('http://127.0.0.1:8000')
- .get('/bank/nonce')
- .reply(200, "42");
- const nonce = await bankClient.getNonce();
- expect(nonce).toEqual(42);
- });
- });
- describe('get balance', () => {
- test('should work with real http client', async () => {
- const webClient = new WebClientNode();
- const bankClient = new BankClient('http://127.0.0.1:8000', '/ipfsBase', storage, webClient, cryptoNode);
- await bankClient.bootstrap();
- nock('http://127.0.0.1:8000')
- .post('/bank/getbalance')
- .reply(200, {
- balance: 42
- });
- nock('http://127.0.0.1:8000')
- .get('/bank/nonce')
- .reply(200, "42");
- const balance = await bankClient.getBalance();
- expect(balance).toEqual(42);
- });
- });
- });
|