@helium/http
Version:
HTTP library for interacting with the Helium blockchain API
185 lines • 7.52 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const nock_1 = __importDefault(require("nock"));
const address_1 = __importStar(require("@helium/address"));
const Client_1 = __importDefault(require("../../Client"));
address_1.default.fromB58 = jest.fn(() => new address_1.default(0, address_1.NetTypes.MAINNET, 0, new Uint8Array()));
describe('list from account payment_v1', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/accounts/fake-address/pending_transactions')
.reply(200, {
data: [
{
updated_at: '2020-04-27T23:30:35.730237Z',
type: 'payment_v1',
txn: {
signature: 'fake-signature',
payer: 'fake-address',
payee: 'fake-address-2',
nonce: 1,
fee: 0,
amount: 1,
},
status: 'pending',
hash: 'fake-hash',
failed_reason: '',
created_at: '2020-04-27T23:30:35.365656Z',
},
],
});
it('lists all pending transactions for an account', async () => {
const client = new Client_1.default();
const list = await client.account('fake-address').pendingTransactions.list();
const [pendingTxn] = await list.take(1);
expect(pendingTxn.type).toBe('payment_v1');
expect(pendingTxn.txn.amount.integerBalance).toBe(1);
});
});
describe('list from account payment_v2', () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/accounts/fake-address/pending_transactions')
.reply(200, {
data: [
{
updated_at: '2020-04-27T23:30:35.730237Z',
type: 'payment_v2',
txn: {
signature: 'fake-signature',
payer: 'fake-address',
payments: [
{
payee: 'fake-address-2',
amount: 1,
},
],
nonce: 1,
fee: 0,
},
status: 'pending',
hash: 'fake-hash',
failed_reason: '',
created_at: '2020-04-27T23:30:35.365656Z',
},
],
});
it('lists all pending transactions for an account', async () => {
const client = new Client_1.default();
const list = await client.account('fake-address').pendingTransactions.list();
const [pendingTxn] = await list.take(1);
expect(pendingTxn.type).toBe('payment_v2');
expect(pendingTxn.txn.payments[0].amount.integerBalance).toBe(1);
expect(pendingTxn.txn.totalAmount.integerBalance).toBe(1);
});
});
describe('list without context', () => {
it('throws an error', async () => {
const client = new Client_1.default();
const makeList = async () => {
await client.pendingTransactions.list();
};
await expect(makeList()).rejects.toThrow();
});
});
describe('get pending transaction', () => {
it('gets a single pending transaction by hash', async () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/pending_transactions/fake-hash')
.reply(200, {
data: [{
updated_at: '2020-04-27T23:30:35.730237Z',
type: 'payment_v1',
txn: {
signature: 'fake-signature',
payer: 'fake-address',
payee: 'fake-address-2',
nonce: 1,
fee: 0,
amount: 1,
},
status: 'pending',
hash: 'fake-hash',
failed_reason: '',
created_at: '2020-04-27T23:30:35.365656Z',
}],
});
const client = new Client_1.default();
const list = await client.pendingTransactions.get('fake-hash');
const pendingTxns = await list.take(100);
expect(pendingTxns.length).toBe(1);
expect(pendingTxns[0].type).toBe('payment_v1');
expect(pendingTxns[0].txn.amount.integerBalance).toBe(1);
});
it('gets multiple pending transaction by hash', async () => {
(0, nock_1.default)('https://api.helium.io')
.get('/v1/pending_transactions/fake-hash')
.reply(200, {
data: [{
updated_at: '2020-04-27T23:30:35.730237Z',
type: 'payment_v1',
txn: {
signature: 'fake-signature',
payer: 'fake-address',
payee: 'fake-address-2',
nonce: 1,
fee: 0,
amount: 1,
},
status: 'pending',
hash: 'fake-hash',
failed_reason: '',
created_at: '2020-04-27T23:30:35.365656Z',
},
{
updated_at: '2020-04-27T23:30:35.730237Z',
type: 'payment_v1',
txn: {
signature: 'fake-signature',
payer: 'fake-address',
payee: 'fake-address-2',
nonce: 1,
fee: 0,
amount: 1,
},
status: 'failed',
hash: 'fake-hash',
failed_reason: 'invalid',
created_at: '2020-04-27T23:31:35.365656Z',
}],
});
const client = new Client_1.default();
const list = await client.pendingTransactions.get('fake-hash');
const pendingTxns = await list.take(100);
expect(pendingTxns.length).toBe(2);
expect(pendingTxns[0].type).toBe('payment_v1');
expect(pendingTxns[0].txn.amount.integerBalance).toBe(1);
expect(pendingTxns[0].status).toBe('pending');
expect(pendingTxns[1].status).toBe('failed');
});
});
//# sourceMappingURL=PendingTransactions.spec.js.map