Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on contract method proxy when method parameter is null. #2815

Merged
merged 1 commit into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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