Skip to content

Commit

Permalink
Merge pull request #2320 from ethereum/issue/2289
Browse files Browse the repository at this point in the history
CallMethod updated
  • Loading branch information
nivida authored Feb 4, 2019
2 parents e0a8e11 + 0c8fd5d commit 9feb075
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/web3-core-method/src/methods/CallMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @date 2018
*/

import isFunction from 'lodash/isFunction';
import AbstractCallMethod from '../../lib/methods/AbstractCallMethod';

export default class CallMethod extends AbstractCallMethod {
Expand All @@ -42,6 +43,13 @@ export default class CallMethod extends AbstractCallMethod {
*/
beforeExecution(moduleInstance) {
this.parameters[0] = this.formatters.inputCallFormatter(this.parameters[0], moduleInstance);

// Optional second parameter 'defaultBlock' could also be the callback
if (isFunction(this.parameters[1])) {
this.callback = this.parameters[1];
this.parameters[1] = moduleInstance.defaultBlock;
}

this.parameters[1] = this.formatters.inputDefaultBlockNumberFormatter(this.parameters[1], moduleInstance);
}
}
21 changes: 21 additions & 0 deletions packages/web3-core-method/tests/src/methods/CallMethodTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,25 @@ describe('CallMethodTest', () => {

expect(formatters.inputCallFormatter).toHaveBeenCalledWith({}, {});
});

it('calls beforeExecution with a callback instead of the optional paramter and it calls the inputCallFormatter and inputDefaultBlockNumberFormatter', () => {
const callback = jest.fn();
method.parameters = [{}, callback];

formatters.inputCallFormatter.mockReturnValueOnce({empty: true});

formatters.inputDefaultBlockNumberFormatter.mockReturnValueOnce('0x0');

method.beforeExecution({defaultBlock: 'latest'});

expect(method.callback).toEqual(callback);

expect(method.parameters[0]).toEqual({empty: true});

expect(method.parameters[1]).toEqual('0x0');

expect(formatters.inputCallFormatter).toHaveBeenCalledWith({}, {defaultBlock: 'latest'});

expect(formatters.inputDefaultBlockNumberFormatter).toHaveBeenCalledWith('latest', {defaultBlock: 'latest'});
});
});

0 comments on commit 9feb075

Please sign in to comment.