aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper/test
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-10-09 15:26:13 +0800
committerJacob Evans <jacob@dekz.net>2018-10-09 16:01:36 +0800
commit9e8031d5e3cf94cabe07685be510397367e90413 (patch)
tree548a3918ed9eb5325db3973d76924907b142aae0 /packages/web3-wrapper/test
parente1236a484623e9d2caab823c476175cb255ae816 (diff)
downloaddexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.tar
dexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.tar.gz
dexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.tar.bz2
dexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.tar.lz
dexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.tar.xz
dexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.tar.zst
dexon-sol-tools-9e8031d5e3cf94cabe07685be510397367e90413.zip
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
Diffstat (limited to 'packages/web3-wrapper/test')
-rw-r--r--packages/web3-wrapper/test/web3_wrapper_test.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts
index 385c469bf..164253777 100644
--- a/packages/web3-wrapper/test/web3_wrapper_test.ts
+++ b/packages/web3-wrapper/test/web3_wrapper_test.ts
@@ -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 () => {