Skip to content

Commit

Permalink
replace web3 eventemitter for eventemitter3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Luu committed Feb 21, 2024
1 parent 6b95286 commit 97255b3
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/web3-eth-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"eslint-config-base-web3": "0.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"flatted": "^3.3.1",
"jest": "^29.7.0",
"jest-extended": "^3.0.1",
"prettier": "^2.7.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/web3-eth-contract/test/unit/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Web3ContractError } from 'web3-errors';
import { Web3Context , Web3ConfigEvent } from 'web3-core';
import { Web3ValidatorError } from 'web3-validator';
import { AbiItem } from 'web3-utils';
import { stringify } from 'flatted';
import {Abi} from '../fixtures/AbiItem'
import { Contract } from '../../src';
import { sampleStorageContractABI } from '../fixtures/storage';
Expand Down Expand Up @@ -755,7 +756,7 @@ describe('Contract', () => {

const clonnedContract = contract.clone();

expect(JSON.stringify(contract)).toStrictEqual(JSON.stringify(clonnedContract));
expect(stringify(contract)).toStrictEqual(stringify(clonnedContract));

contract.options.jsonInterface = GreeterAbi;
});
Expand All @@ -764,7 +765,7 @@ describe('Contract', () => {
const contract = new Contract(sampleStorageContractABI);

const clonnedContract = contract.clone();
expect(JSON.stringify(contract)).toStrictEqual(JSON.stringify(clonnedContract));
expect(stringify(contract)).toStrictEqual(stringify(clonnedContract));
});

it('should be able to update the jsonInterface', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/web3-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,8 @@ Documentation:

- Adds missing exported type `AbiItem` from 1.x to v4 for compatabiltiy (#6678)

## [Unreleased]
## [Unreleased]

### Fixed

- replaced our eventEmitter to EventEmitter3 to support react native builds (#6253)
2 changes: 1 addition & 1 deletion packages/web3-utils/src/chunk_response_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { JsonRpcResponse } from 'web3-types';
import { InvalidResponseError } from 'web3-errors';
import { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';
import { Timeout } from './promise_helpers.js';

export class ChunkResponseParser {
Expand Down
5 changes: 2 additions & 3 deletions packages/web3-utils/src/event_emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import EventEmitter3 from 'eventemitter3';
* It is used to provide the same interface for the browser environment.
*/
export class EventEmitter extends EventEmitter3 {
// must be defined for backwards compatibility
private maxListeners = Number.MAX_SAFE_INTEGER;

public setMaxListeners(maxListeners: number) {
Expand All @@ -35,6 +36,4 @@ export class EventEmitter extends EventEmitter3 {
return this.maxListeners;
}

}
// eslint-disable-next-line import/no-mutable-exports
// let EventEmitterType: typeof EventEmitter3;
}
2 changes: 1 addition & 1 deletion packages/web3-utils/src/web3_eip1193_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Web3APISpec,
Web3BaseProvider,
} from 'web3-types';
import { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';
import { EIP1193ProviderRpcError } from 'web3-errors';
import { toPayload } from './json_rpc.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 { EventEmitter } from 'events';
import { EventEmitter } from 'eventemitter3';
import { InvalidResponseError } from 'web3-errors';
import { ChunkResponseParser } from '../../src/chunk_response_parser';
import { hugeData } from '../fixtures/hugeData';
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5676,6 +5676,11 @@ eventemitter3@^4.0.0, eventemitter3@^4.0.4:
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

eventemitter3@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4"
integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==

events@^3.0.0, events@^3.2.0, events@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
Expand Down Expand Up @@ -6052,6 +6057,11 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2"
integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==

flatted@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.1.tgz#21db470729a6734d4997002f439cb308987f567a"
integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==

follow-redirects@^1.0.0, follow-redirects@^1.12.1:
version "1.15.1"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"
Expand Down

1 comment on commit 97255b3

@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: 97255b3 Previous: 6c075db Ratio
processingTx 9322 ops/sec (±3.59%) 9301 ops/sec (±4.81%) 1.00
processingContractDeploy 35235 ops/sec (±7.75%) 39129 ops/sec (±7.62%) 1.11
processingContractMethodSend 18393 ops/sec (±7.07%) 19443 ops/sec (±5.19%) 1.06
processingContractMethodCall 37285 ops/sec (±5.62%) 38971 ops/sec (±6.34%) 1.05
abiEncode 42004 ops/sec (±7.31%) 44252 ops/sec (±6.92%) 1.05
abiDecode 30044 ops/sec (±6.56%) 30419 ops/sec (±8.89%) 1.01
sign 1534 ops/sec (±5.08%) 1656 ops/sec (±4.08%) 1.08
verify 369 ops/sec (±0.48%) 373 ops/sec (±0.78%) 1.01

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

Please sign in to comment.