aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/test
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-04-11 10:47:17 +0800
committerJacob Evans <jacob@dekz.net>2018-04-11 10:47:17 +0800
commit20a1deb187d8fb38a42ae87fc8f046dff4b4ba61 (patch)
tree5aed7d4b910aa11c2a3c261a685ca864d428878c /packages/subproviders/test
parent9169913a2cbe9d421629db2e8169c0806044e3fc (diff)
downloaddexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.tar
dexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.tar.gz
dexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.tar.bz2
dexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.tar.lz
dexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.tar.xz
dexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.tar.zst
dexon-sol-tools-20a1deb187d8fb38a42ae87fc8f046dff4b4ba61.zip
Throw errors when the address is not specified or invalid
Diffstat (limited to 'packages/subproviders/test')
-rw-r--r--packages/subproviders/test/integration/ledger_subprovider_test.ts5
-rw-r--r--packages/subproviders/test/unit/ledger_subprovider_test.ts5
-rw-r--r--packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts2
-rw-r--r--packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts21
4 files changed, 27 insertions, 6 deletions
diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts
index 88a3c6db1..4a831af67 100644
--- a/packages/subproviders/test/integration/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts
@@ -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);
});
diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts
index d3a3fbe26..ad1154831 100644
--- a/packages/subproviders/test/unit/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts
@@ -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',
diff --git a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts
index 77e5d35ae..a1a5a2296 100644
--- a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts
+++ b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts
@@ -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 () => {
diff --git a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts
index 8aaddeaf4..b84aebb18 100644
--- a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts
+++ b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts
@@ -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);