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

batch request fixed for SendRawTransactionMethod #2870

Merged
merged 1 commit into from
Jun 4, 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-providers/src/batch-request/BatchRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class BatchRequest {
let mappedResult;

// TODO: Find a better handling for custom behaviours in a batch request (afterBatchRequest?)
if (method.Type === 'eth-send-transaction-method') {
if (method.Type === 'eth-send-transaction-method' || method.Type === 'observed-transaction-method') {
mappedResult = responseItem.result;
} else {
mappedResult = method.afterExecution(responseItem.result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,30 @@ describe('BatchRequestTest', () => {
expect(JsonRpcMapper.toPayload).toHaveBeenCalledWith('rpc_method', [true]);
});

it('calls execute with the SendRawTransactionMethod and returns a resolved promise', async () => {
JsonRpcResponseValidator.validate.mockReturnValueOnce(true);

JsonRpcMapper.toPayload.mockReturnValueOnce({});

providerMock.sendPayload = jest.fn((payload) => {
expect(payload).toEqual([{}]);

return Promise.resolve([{result: true}]);
});

abstractMethodMock.Type = 'observed-transaction-method';
batchRequest.add(abstractMethodMock);

await expect(batchRequest.execute()).resolves.toEqual({
methods: [abstractMethodMock],
response: [true]
});

expect(JsonRpcResponseValidator.validate).toHaveBeenCalled();

expect(JsonRpcMapper.toPayload).toHaveBeenCalledWith('rpc_method', [true]);
});

it('calls execute with accounts defined and returns a resolved promise', async () => {
JsonRpcResponseValidator.validate.mockReturnValueOnce(false);

Expand Down