Skip to content

Commit

Permalink
Resolve test snapshot issue between node 18 vs 20 & 21 (#6794)
Browse files Browse the repository at this point in the history
* resolve snapshot issue between node 18 vs 20 & 21

* update a comment

---------

Co-authored-by: Alex <[email protected]>
  • Loading branch information
Muhammad-Altabba and Alex authored Feb 12, 2024
1 parent 9d65c38 commit a0d4d2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
},
"registeredSubscriptions": {},
"requestManager": Web3RequestManager {
"_emitter": EventEmitter {
"_emitter": {
"_events": {
"BEFORE_PROVIDER_CHANGE": [Function],
"PROVIDER_CHANGED": [Function],
},
"_eventsCount": 2,
"_maxListeners": undefined,
Symbol(kCapture): false,
Symbol(shapeMode): false,
},
"_provider": HttpProvider {
"clientUrl": "http://test/abc",
Expand All @@ -59,14 +60,15 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
"_subscriptions": Map {},
"registeredSubscriptions": {},
"requestManager": Web3RequestManager {
"_emitter": EventEmitter {
"_emitter": {
"_events": {
"BEFORE_PROVIDER_CHANGE": [Function],
"PROVIDER_CHANGED": [Function],
},
"_eventsCount": 2,
"_maxListeners": undefined,
Symbol(kCapture): false,
Symbol(shapeMode): false,
},
"_provider": HttpProvider {
"clientUrl": "http://test/abc",
Expand Down
20 changes: 20 additions & 0 deletions packages/web3-core/test/unit/web3_context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ describe('Web3Context', () => {
it('should return correct context object', () => {
const context = new Context1('http://test/abc');

// The following is because a specific property is different in node 18 than it is in node 20 and 21
// So the problematic property is removed from the object and then added to ensure its presence and its location
// And the snapshot is updated to reflect the change.
// Once node 18 is no longer supported, this can be removed. And the snapshot need to be updated then.

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const symbolForShapeMode = Object.getOwnPropertySymbols(
(context.getContextObject().requestManager as any)._emitter,
).find(s => s.description === 'shapeMode');
if (symbolForShapeMode) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (context.getContextObject().requestManager as any)._emitter[symbolForShapeMode];
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(context.getContextObject().requestManager as any)._emitter = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(context.getContextObject().requestManager as any)._emitter,
[Symbol.for('shapeMode')]: false,
};

expect(context.getContextObject()).toMatchSnapshot();
});
});
Expand Down

1 comment on commit a0d4d2e

@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: a0d4d2e Previous: 6c075db Ratio
processingTx 9665 ops/sec (±3.91%) 9301 ops/sec (±4.81%) 0.96
processingContractDeploy 40185 ops/sec (±7.40%) 39129 ops/sec (±7.62%) 0.97
processingContractMethodSend 20811 ops/sec (±6.78%) 19443 ops/sec (±5.19%) 0.93
processingContractMethodCall 41701 ops/sec (±6.50%) 38971 ops/sec (±6.34%) 0.93
abiEncode 47325 ops/sec (±7.65%) 44252 ops/sec (±6.92%) 0.94
abiDecode 32388 ops/sec (±7.60%) 30419 ops/sec (±8.89%) 0.94
sign 1623 ops/sec (±2.82%) 1656 ops/sec (±4.08%) 1.02
verify 400 ops/sec (±0.71%) 373 ops/sec (±0.78%) 0.93

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

Please sign in to comment.