@ledgerhq/coin-mina
Version:
43 lines • 2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const getEstimatedFees_1 = __importDefault(require("./getEstimatedFees"));
const api_1 = require("../api");
const prepareTransaction_1 = require("./prepareTransaction");
jest.mock("../api");
jest.mock("./getEstimatedFees");
describe("prepareTransaction", () => {
let estimateFeesSpy;
let getNonceSpy;
beforeEach(() => {
getNonceSpy = jest.spyOn({ getNonce: api_1.getNonce }, "getNonce");
estimateFeesSpy = jest.spyOn({ estimateFees: getEstimatedFees_1.default }, "estimateFees");
estimateFeesSpy.mockResolvedValue({
fee: new bignumber_js_1.default(1),
accountCreationFee: new bignumber_js_1.default(1),
});
getNonceSpy.mockResolvedValue(1);
});
it("should update fee fields if it's different", async () => {
const oldTx = {
fees: { fee: new bignumber_js_1.default(0), accountCreationFee: new bignumber_js_1.default(0) },
};
const newTx = await (0, prepareTransaction_1.prepareTransaction)({}, oldTx);
expect(newTx.fees.fee).toEqual(new bignumber_js_1.default(1));
expect(newTx.fees.accountCreationFee).toEqual(new bignumber_js_1.default(1));
expect(getNonceSpy).toHaveBeenCalledTimes(1);
expect(getNonceSpy).toHaveBeenCalledWith(oldTx, undefined);
});
it("should update nonce if it's different", async () => {
const oldTx = {
nonce: 0,
fees: { fee: new bignumber_js_1.default(0), accountCreationFee: new bignumber_js_1.default(0) },
};
const newTx = await (0, prepareTransaction_1.prepareTransaction)({}, oldTx);
expect(newTx.nonce).toEqual(1);
});
});
//# sourceMappingURL=prepareTransaction.test.js.map