stellar-plus
Version:
beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain
73 lines (72 loc) • 3.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const stellar_sdk_1 = require("@stellar/stellar-sdk");
const _1 = require(".");
jest.mock('@stellar/stellar-sdk', () => ({
Horizon: {
Server: jest.fn(),
},
Transaction: jest.fn(() => {
return {
networkPassphrase: 'networkPassphrase',
toXDR: jest.fn(() => {
return 'toXDR';
}),
};
}),
TransactionBuilder: {
fromXDR: jest.fn(() => {
return {};
}),
buildFeeBumpTransaction: jest.fn(() => {
return {};
}),
},
}));
const MOCKED_BUMP_FEE = '101';
const MOCKED_TRANSACTION = {
networkPassphrase: 'networkPassphrase',
toXDR: jest.fn(() => 'toXDR'),
};
const MOCKED_FEE_BUMPED_TRANSACTION = {};
const MOCKED_BT_INPUT = {
innerTransaction: MOCKED_TRANSACTION,
feeBumpHeader: {
header: {
source: 'source',
fee: MOCKED_BUMP_FEE,
timeout: 2,
},
signers: [],
},
};
const MOCKED_BT_OUTPUT = MOCKED_FEE_BUMPED_TRANSACTION;
describe('FeeBumpPipeline', () => {
let feeBumpPipeline;
beforeEach(() => {
jest.clearAllMocks();
});
describe('Wrap Transaction', () => {
beforeEach(() => {
feeBumpPipeline = new _1.FeeBumpPipeline();
jest.clearAllMocks();
});
it('should wrap transaction successfully', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
yield expect(feeBumpPipeline.execute(MOCKED_BT_INPUT)).resolves.toEqual(MOCKED_BT_OUTPUT);
expect(stellar_sdk_1.TransactionBuilder.fromXDR).toHaveBeenCalledTimes(1);
expect(stellar_sdk_1.TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledTimes(1);
expect(stellar_sdk_1.TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledWith(MOCKED_BT_INPUT.feeBumpHeader.header.source, MOCKED_BT_INPUT.feeBumpHeader.header.fee, {}, 'networkPassphrase');
}));
it('should throw error', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const mockedInput = Object.assign(Object.assign({}, MOCKED_BT_INPUT), { feeBumpHeader: Object.assign(Object.assign({}, MOCKED_BT_INPUT.feeBumpHeader), { header: Object.assign(Object.assign({}, MOCKED_BT_INPUT.feeBumpHeader.header), { fee: '0' }) }) });
stellar_sdk_1.TransactionBuilder.buildFeeBumpTransaction.mockImplementationOnce(() => {
throw new Error('Error building fee bump transaction!');
});
yield expect(feeBumpPipeline.execute(mockedInput)).rejects.toThrow('Unexpected error!');
expect(stellar_sdk_1.TransactionBuilder.fromXDR).toHaveBeenCalledTimes(1);
expect(stellar_sdk_1.TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledTimes(1);
expect(stellar_sdk_1.TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledWith(MOCKED_BT_INPUT.feeBumpHeader.header.source, '0', {}, 'networkPassphrase');
}));
});
});