Throw and handle errors from Providers.

In web3 wrapper when a response contains an error field we throw this rather than return response.result which is often undefined.
In Signature Utils we handle the error thrown when a user rejects the signing dialogue to prevent double signing.
Exposed the ZeroExTransaction JSON schema.
In Website only use the MetamaskSubprovider if we can detect the provider is Metamask
This commit is contained in:
Jacob Evans
2018-10-09 18:26:13 +11:00
parent e1236a4846
commit 9e8031d5e3
23 changed files with 208 additions and 150 deletions

View File

@@ -1,5 +1,5 @@
import * as chai from 'chai';
import { BlockParamLiteral } from 'ethereum-types';
import { BlockParamLiteral, JSONRPCErrorCallback, JSONRPCRequestPayload } from 'ethereum-types';
import * as Ganache from 'ganache-core';
import * as _ from 'lodash';
import 'mocha';
@@ -78,6 +78,19 @@ describe('Web3Wrapper tests', () => {
const signatureLength = 132;
expect(signature.length).to.be.equal(signatureLength);
});
it('should throw if the provider returns an error', async () => {
const message = '0xdeadbeef';
const signer = addresses[1];
const fakeProvider = {
async sendAsync(payload: JSONRPCRequestPayload, callback: JSONRPCErrorCallback): Promise<void> {
callback(new Error('User denied message signature'));
},
};
const errorWeb3Wrapper = new Web3Wrapper(fakeProvider);
expect(errorWeb3Wrapper.signMessageAsync(signer, message)).to.be.rejectedWith(
'User denied message signature',
);
});
});
describe('#getBlockNumberAsync', () => {
it('get block number', async () => {