Skip to content

Commit

Permalink
coverage increase (#7051)
Browse files Browse the repository at this point in the history
* coverage increase

* get Uncle tests

* lint err fix

* correction
  • Loading branch information
jdevcs committed May 24, 2024
1 parent 7537f03 commit 692987a
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3RequestManager } from 'web3-core';
import { ethRpcMethods } from '../../../src/index';

jest.mock('web3-validator');

describe('getUncleByBlockNumberAndIndex', () => {
let requestManagerSendSpy: jest.Mock;
let requestManager: Web3RequestManager;

beforeAll(() => {
requestManager = new Web3RequestManager('http://127.0.0.1:8545');
requestManagerSendSpy = jest.fn();
requestManager.send = requestManagerSendSpy;
});

it('should call requestManager.send with eth_getUncleByBlockNumberAndIndex method', async () => {
await ethRpcMethods.getUncleByBlockNumberAndIndex(requestManager, 0, '1' );
expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'eth_getUncleByBlockNumberAndIndex',
params: [0,'1'],
});
},
);

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3RequestManager } from 'web3-core';
import { EthPersonalAPI } from 'web3-types';
import { personalRpcMethods } from '../../../src/index';

describe('Eth Personal', () => {
let requestManagerSendSpy: jest.Mock;
let requestManager: Web3RequestManager<EthPersonalAPI>;

beforeAll(() => {
requestManager = new Web3RequestManager<EthPersonalAPI>('http://127.0.0.1:8545');
requestManagerSendSpy = jest.fn();
requestManager.send = requestManagerSendSpy;
});

it('should call requestManager.send with personal_listAccounts method', async () => {
await personalRpcMethods.getAccounts(requestManager);
expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_listAccounts',
params: [],
});
});

it('should call requestManager.send with personal_newAccount method', async () => {
const pass = "ABC123";
await personalRpcMethods.newAccount(requestManager, pass);
expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_newAccount',
params: [pass],
});
});

it('should call requestManager.send with personal_unlockAccount method', async () => {
const pass = "ABC123";
const address = "0x4106486FB42F3Abf07CC07ef5DEE38f60319e789";
const duration = 100;
await personalRpcMethods.unlockAccount(requestManager, address, pass, duration);

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_unlockAccount',
params: [address, pass, duration],
});
});

it('should call requestManager.send with personal_lockAccount method', async () => {
const address = "0x4106486FB42F3Abf07CC07ef5DEE38f60319e789";

await personalRpcMethods.lockAccount(requestManager, address );

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_lockAccount',
params: [address],
});
});

it('should call requestManager.send with personal_importRawKey method', async () => {
const passPhrase = "123456";
const keyData = "abe40cb08850da918ee951b237fa87946499b2d8643e4aa12b0610b050c731f6";
await personalRpcMethods.importRawKey(requestManager, keyData, passPhrase );

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_importRawKey',
params: [keyData,passPhrase],
});
});

it('should call requestManager.send with personal_sendTransaction method', async () => {
const passPhrase = "123456";
const tx = {
from: "0x0d4aa485ecbc499c70860feb7e5aaeaf5fd8172e",
gasPrice: "20000",
gas: "21000",
to: "0x4106486FB42F3Abf07CC07ef5DEE38f60319e789",
value: "1000000",
data: "",
nonce: 0,
};
await personalRpcMethods.sendTransaction(requestManager, tx, passPhrase );

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_sendTransaction',
params: [tx,passPhrase],
});
});

it('should call requestManager.send with personal_signTransaction method', async () => {
const passPhrase = "123456";
const tx = {
from: "0x0d4aa485ecbc499c70860feb7e5aaeaf5fd8172e",
gasPrice: "20000",
gas: "21000",
to: "0x4106486FB42F3Abf07CC07ef5DEE38f60319e789",
value: "1000000",
data: "",
nonce: 0,
};
await personalRpcMethods.signTransaction(requestManager, tx, passPhrase );

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_signTransaction',
params: [tx,passPhrase],
});
});

it('should call requestManager.send with personal_sign method', async () => {
const data = "Hello world";
const address = "0x0D4Aa485ECbC499c70860fEb7e5AaeAf5fd8172E";
const pass = "123456";

await personalRpcMethods.sign(requestManager, data,address,pass);

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_sign',
params: [ data,address,pass],
});
});

it('should call requestManager.send with personal_ecRecover method', async () => {
const data = "Hello world";
const signature = "0x5d21d01b3198ac34d0585a9d76c4d1c8123e5e06746c8962318a1c08ffb207596e6fce4a6f377b7c0fc98c5f646cd73438c80e8a1a95cbec55a84c2889dca0301b";

await personalRpcMethods.ecRecover(requestManager,data, signature);

expect(requestManagerSendSpy).toHaveBeenCalledWith({
method: 'personal_ecRecover',
params: [ data, signature],
});
});
});

1 comment on commit 692987a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 692987a Previous: 7537f03 Ratio
processingTx 8880 ops/sec (±3.76%) 9373 ops/sec (±3.87%) 1.06
processingContractDeploy 38813 ops/sec (±6.13%) 40940 ops/sec (±6.68%) 1.05
processingContractMethodSend 18943 ops/sec (±7.10%) 19530 ops/sec (±7.02%) 1.03
processingContractMethodCall 38006 ops/sec (±5.78%) 39078 ops/sec (±5.38%) 1.03
abiEncode 43737 ops/sec (±6.49%) 44890 ops/sec (±6.52%) 1.03
abiDecode 29525 ops/sec (±8.05%) 31234 ops/sec (±8.10%) 1.06
sign 1523 ops/sec (±3.37%) 1579 ops/sec (±3.33%) 1.04
verify 371 ops/sec (±0.54%) 381 ops/sec (±0.53%) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.