Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 8017efa

Browse files
author
Samuel Furter
committed
Parameters amount in EcRecoverMethod fixed, PersonalSignMethod optional parameter password fixed, and related tests updated
1 parent 22a190c commit 8017efa

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

packages/web3-core-method/src/methods/personal/EcRecoverMethod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class EcRecoverMethod extends AbstractMethod {
3131
* @constructor
3232
*/
3333
constructor(utils, formatters, moduleInstance) {
34-
super('personal_ecRecover', 3, utils, formatters, moduleInstance);
34+
super('personal_ecRecover', 2, utils, formatters, moduleInstance);
3535
}
3636

3737
/**

packages/web3-core-method/src/methods/personal/PersonalSignMethod.js

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @date 2018
2121
*/
2222

23+
import isFunction from 'lodash/isFunction'
2324
import AbstractMethod from '../../../lib/methods/AbstractMethod';
2425

2526
export default class PersonalSignMethod extends AbstractMethod {
@@ -44,5 +45,10 @@ export default class PersonalSignMethod extends AbstractMethod {
4445
beforeExecution(moduleInstance) {
4546
this.parameters[0] = this.formatters.inputSignFormatter(this.parameters[0]);
4647
this.parameters[1] = this.formatters.inputAddressFormatter(this.parameters[1]);
48+
49+
if (isFunction(this.parameters[2])) {
50+
this.callback = this.parameters[2];
51+
delete this.parameters[2];
52+
}
4753
}
4854
}

packages/web3-core-method/tests/src/methods/personal/EcRecoverMethodTest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('EcRecoverMethodTest', () => {
2020

2121
expect(method.rpcMethod).toEqual('personal_ecRecover');
2222

23-
expect(method.parametersAmount).toEqual(3);
23+
expect(method.parametersAmount).toEqual(2);
2424

2525
expect(method.utils).toEqual(null);
2626

packages/web3-core-method/tests/src/methods/personal/PersonalSignMethodTest.js

+23
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,27 @@ describe('PersonalSignMethodTest', () => {
4444

4545
expect(formatters.inputAddressFormatter).toHaveBeenCalledWith('0x0');
4646
});
47+
48+
it('calls beforeExecution with a callback instead of the optional paramter and it calls the inputSignFormatter and inputAddressFormatter', () => {
49+
const callback = jest.fn();
50+
method.parameters = ['sign', '0x0', callback];
51+
52+
formatters.inputSignFormatter.mockReturnValueOnce('signed');
53+
54+
formatters.inputAddressFormatter.mockReturnValueOnce('0x00');
55+
56+
method.beforeExecution({defaultBlock: 'latest'});
57+
58+
expect(method.callback).toEqual(callback);
59+
60+
expect(method.parameters[0]).toEqual('signed');
61+
62+
expect(method.parameters[1]).toEqual('0x00');
63+
64+
expect(method.parameters[2]).toEqual(undefined);
65+
66+
expect(formatters.inputSignFormatter).toHaveBeenCalledWith('sign');
67+
68+
expect(formatters.inputAddressFormatter).toHaveBeenCalledWith('0x0');
69+
});
4770
});

0 commit comments

Comments
 (0)