Throw errors when the address is not specified or invalid

This commit is contained in:
Jacob Evans
2018-04-11 12:47:17 +10:00
parent 9169913a2c
commit 20a1deb187
9 changed files with 67 additions and 42 deletions

View File

@@ -55,7 +55,10 @@ describe('LedgerSubprovider', () => {
});
it('signs a personal message', async () => {
const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(data);
const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(
data,
fixtureData.TEST_RPC_ACCOUNT_0,
);
expect(ecSignatureHex.length).to.be.equal(132);
expect(ecSignatureHex).to.be.equal(fixtureData.PERSONAL_MESSAGE_SIGNED_RESULT);
});

View File

@@ -82,7 +82,7 @@ describe('LedgerSubprovider', () => {
});
it('signs a personal message', async () => {
const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(data);
const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(data, FAKE_ADDRESS);
expect(ecSignatureHex).to.be.equal(
'0xa6cc284bff14b42bdf5e9286730c152be91719d478605ec46b3bebcd0ae491480652a1a7b742ceb0213d1e744316e285f41f878d8af0b8e632cbca4c279132d001',
);
@@ -94,7 +94,7 @@ describe('LedgerSubprovider', () => {
return expect(
Promise.all([
ledgerSubprovider.getAccountsAsync(),
ledgerSubprovider.signPersonalMessageAsync(data),
ledgerSubprovider.signPersonalMessageAsync(data, FAKE_ADDRESS),
]),
).to.be.rejectedWith(LedgerSubproviderErrors.MultipleOpenConnectionsDisallowed);
});
@@ -168,6 +168,7 @@ describe('LedgerSubprovider', () => {
gasPrice: '0x00',
nonce: '0x00',
gas: '0x00',
from: FAKE_ADDRESS,
};
const payload = {
jsonrpc: '2.0',

View File

@@ -36,7 +36,7 @@ describe('MnemonicWalletSubprovider', () => {
});
it('signs a personal message', async () => {
const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
const ecSignatureHex = await subprovider.signPersonalMessageAsync(data);
const ecSignatureHex = await subprovider.signPersonalMessageAsync(data, fixtureData.TEST_RPC_ACCOUNT_0);
expect(ecSignatureHex).to.be.equal(fixtureData.PERSONAL_MESSAGE_SIGNED_RESULT);
});
it('signs a transaction', async () => {

View File

@@ -32,7 +32,7 @@ describe('PrivateKeyWalletSubprovider', () => {
});
it('signs a personal message', async () => {
const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
const ecSignatureHex = await subprovider.signPersonalMessageAsync(data);
const ecSignatureHex = await subprovider.signPersonalMessageAsync(data, fixtureData.TEST_RPC_ACCOUNT_0);
expect(ecSignatureHex).to.be.equal(fixtureData.PERSONAL_MESSAGE_SIGNED_RESULT);
});
it('signs a transaction', async () => {
@@ -128,6 +128,23 @@ describe('PrivateKeyWalletSubprovider', () => {
});
provider.sendAsync(payload, callback);
});
it('should throw if `address` param is not an address from private key when calling personal_sign', (done: DoneCallback) => {
const nonHexMessage = 'hello world';
const payload = {
jsonrpc: '2.0',
method: 'personal_sign',
params: [nonHexMessage, fixtureData.TEST_RPC_ACCOUNT_1],
id: 1,
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.not.be.a('null');
expect(err.message).to.be.equal(
`${WalletSubproviderErrors.FromAddressMissingOrInvalid}: ${fixtureData.TEST_RPC_ACCOUNT_1}`,
);
done();
});
provider.sendAsync(payload, callback);
});
it('should throw if `from` param missing when calling eth_sendTransaction', (done: DoneCallback) => {
const tx = {
to: '0xafa3f8684e54059998bc3a7b0d2b0da075154d66',
@@ -175,7 +192,7 @@ describe('PrivateKeyWalletSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.not.be.a('null');
expect(err.message).to.be.equal(`${WalletSubproviderErrors.AddressNotFound}: 0x0`);
expect(err.message).to.be.equal(`${WalletSubproviderErrors.FromAddressMissingOrInvalid}: 0x0`);
done();
});
provider.sendAsync(payload, callback);