Skip to content

Commit

Permalink
Merge pull request #2815 from Pedro-vk/patch-2
Browse files Browse the repository at this point in the history
Fix error on contract method proxy when method parameter is null.
  • Loading branch information
nivida committed May 14, 2019
2 parents ce93e2d + f4a37ca commit 9714f30
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/src/proxies/MethodsProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class MethodsProxy {
method.setArguments(methodArguments);

// If no parameters are given for the eth_call or eth_send* methods then it will set a empty options object.
if (typeof method.parameters[0] === 'undefined') {
if (!method.parameters[0]) {
method.parameters[0] = {};
}

Expand Down
41 changes: 41 additions & 0 deletions packages/web3-eth-contract/tests/src/proxies/MethodsProxyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,47 @@ describe('MethodsProxyTest', () => {
expect(methodOptionsValidatorMock.validate).toHaveBeenCalledWith(abiItemModelMock, callMethodMock);
});

it('calls a call method over the proxy should allow null parameters', async () => {
abiModelMock.hasMethod.mockReturnValueOnce(true);

abiModelMock.getMethod.mockReturnValueOnce(abiItemModelMock);

const callMethodMock = {};
callMethodMock.parameters = [null];
callMethodMock.setArguments = jest.fn();
callMethodMock.execute = jest.fn(() => {
return Promise.resolve(true);
});

methodFactoryMock.createMethodByRequestType.mockReturnValueOnce(callMethodMock);

methodEncoderMock.encode.mockReturnValueOnce('0x0');

methodOptionsMapperMock.map.mockReturnValueOnce({options: true});

await expect(methodsProxy.myMethod(true).call({options: false})).resolves.toEqual(true);

expect(abiModelMock.hasMethod).toHaveBeenCalledWith('myMethod');

expect(abiModelMock.getMethod).toHaveBeenCalledWith('myMethod');

expect(abiItemModelMock.contractMethodParameters[0]).toEqual(true);

expect(methodFactoryMock.createMethodByRequestType).toHaveBeenCalledWith(
abiItemModelMock,
contractMock,
'call'
);

expect(callMethodMock.parameters[0]).toEqual({options: true});

expect(methodEncoderMock.encode).toHaveBeenCalledWith(abiItemModelMock, contractMock.data);

expect(methodOptionsMapperMock.map).toHaveBeenCalledWith(contractMock, {data: '0x0'});

expect(methodOptionsValidatorMock.validate).toHaveBeenCalledWith(abiItemModelMock, callMethodMock);
});

it('calls the constructor method over the proxy', async () => {
abiModelMock.hasMethod.mockReturnValueOnce(true);

Expand Down

0 comments on commit 9714f30

Please sign in to comment.