Skip to content

Commit 224d0d8

Browse files
committed
tests: fix mock methods
1 parent a73a361 commit 224d0d8

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

__tests__/wallet/partialTxProposal.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,12 @@ test('addSend', async () => {
123123
.mockImplementation(() => {});
124124
const spyOutput = jest.spyOn(PartialTxProposal.prototype, 'addOutput')
125125
.mockImplementation(() => {});
126-
const spyUtxos = jest.spyOn(HathorWallet.prototype, 'getAllUtxos')
127-
.mockImplementation(utxoMock);
128126

129127
const hwallet = fakeHathorWallet({
130128
getCurrentAddress: jest.fn(() => ({
131129
address: ADDR2,
132130
})),
131+
getAllUtxos: jest.fn(utxoMock),
133132
});
134133

135134
const proposal = new PartialTxProposal(testnet);
@@ -139,7 +138,6 @@ test('addSend', async () => {
139138
*/
140139
proposal.addSend(hwallet, FAKE_UID, 10);
141140
expect(spyReset).toHaveBeenCalledTimes(1);
142-
expect(spyUtxos).toBeCalledWith({ token: FAKE_UID });
143141
expect(spyInput).toBeCalledWith(
144142
hwallet,
145143
FAKE_TXID,
@@ -149,21 +147,21 @@ test('addSend', async () => {
149147
{ token: FAKE_UID, authorities: 0, markAsSelected: true },
150148
);
151149
expect(spyOutput).not.toHaveBeenCalled();
150+
expect(hwallet.getAllUtxos).toBeCalledWith({ token: FAKE_UID });
152151
expect(hwallet.getCurrentAddress).not.toHaveBeenCalled();
153152

154153
// Mock cleanup
155154
spyReset.mockClear();
156155
spyInput.mockClear();
157156
spyOutput.mockClear();
158-
spyUtxos.mockClear();
159157
hwallet.getCurrentAddress.mockClear();
158+
hwallet.getAllUtxos.mockClear();
160159

161160
/**
162161
* Add 1 input with change passing utxos and address
163162
*/
164163
proposal.addSend(hwallet, FAKE_UID, 4, { utxos, changeAddress: ADDR3 });
165164
expect(spyReset).toHaveBeenCalledTimes(1);
166-
expect(spyUtxos).not.toHaveBeenCalled();
167165
expect(spyInput).toBeCalledWith(
168166
hwallet,
169167
FAKE_TXID,
@@ -179,20 +177,21 @@ test('addSend', async () => {
179177
{ isChange: true },
180178
);
181179
expect(hwallet.getCurrentAddress).not.toHaveBeenCalled();
180+
expect(hwallet.getAllUtxos).not.toHaveBeenCalled();
182181

183182
// Mock cleanup
184183
spyReset.mockClear();
185184
spyInput.mockClear();
186185
spyOutput.mockClear();
187-
spyUtxos.mockClear();
186+
hwallet.getAllUtxos.mockClear();
188187
hwallet.getCurrentAddress.mockClear();
189188

190189
/**
191190
* Add 1 input with change without address and markAsSelected false
192191
*/
193192
proposal.addSend(hwallet, FAKE_UID, 8, { markAsSelected: false });
194193
expect(spyReset).toHaveBeenCalledTimes(1);
195-
expect(spyUtxos).toBeCalledWith({ token: FAKE_UID });
194+
expect(hwallet.getAllUtxos).toBeCalledWith({ token: FAKE_UID });
196195
expect(spyInput).toBeCalledWith(
197196
hwallet,
198197
FAKE_TXID,
@@ -213,7 +212,6 @@ test('addSend', async () => {
213212
spyReset.mockRestore();
214213
spyInput.mockRestore();
215214
spyOutput.mockRestore();
216-
spyUtxos.mockRestore();
217215
});
218216

219217
test('addReceive', async () => {
@@ -267,8 +265,7 @@ test('addReceive', async () => {
267265

268266
test('addInput', async () => {
269267
const spyReset = jest.spyOn(PartialTxProposal.prototype, 'resetSignatures');
270-
const spyInput = jest.spyOn(PartialTx.prototype, 'addInput')
271-
.mockImplementation(() => {});
268+
const spyInput = jest.spyOn(PartialTx.prototype, 'addInput');
272269

273270
const hwallet = fakeHathorWallet({
274271
markUtxoSelected: jest.fn((hash, index) => {}),

src/wallet/partialTxProposal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class PartialTxProposal {
137137
wallet: HathorWallet,
138138
token: string,
139139
value: number,
140-
{ timelock = null, address = null }: { timelock?: number|null, address?: string|null } = {}) {
140+
{ timelock = null, address = null }: { timelock?: number|null, address?: string|null } = {},
141+
) {
141142
this.resetSignatures();
142143

143144
// get an address of our wallet and add the output

0 commit comments

Comments
 (0)