Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format repo, add new rules #7226

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ module.exports = {
typescript: {}, // this loads tsconfig.json to eslint
},
},
overrides: [
{
files: ['*.test.ts'],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['*.ts'],
rules: {
'default-param-last': 'off',
},
},
],
};
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
40 changes: 34 additions & 6 deletions fixtures/contracts/Basic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ contract Basic {
event StringEvent(string str);
event MultiValueEvent(string str, uint256 val, bool flag);
event MultiValueIndexedEvent(string str, uint256 indexed val, bool indexed flag);
event MultiValueIndexedEventWithStringIndexed(string indexed str, uint256 indexed val, bool indexed flag);
event MultiValueIndexedEventWithStringIndexed(
string indexed str,
uint256 indexed val,
bool indexed flag
);

constructor(uint256 _val, string memory _stringValue) {
intValue = _val;
Expand All @@ -29,11 +33,23 @@ contract Basic {
return boolValue;
}

function getValues() public view returns (uint256, string memory, bool) {
function getValues()
public
view
returns (
uint256,
string memory,
bool
)
{
return (intValue, stringValue, boolValue);
}

function setValues(uint256 _value, string memory _stringValue, bool _boolValue) public {
function setValues(
uint256 _value,
string memory _stringValue,
bool _boolValue
) public {
intValue = _value;
stringValue = _stringValue;
boolValue = _boolValue;
Expand All @@ -51,19 +67,31 @@ contract Basic {
revert('REVERTED WITH REVERT');
}

function firesMultiValueEvent(string memory str, uint256 val, bool flag) public {
function firesMultiValueEvent(
string memory str,
uint256 val,
bool flag
) public {
emit MultiValueEvent(str, val, flag);
}

function firesMultiValueIndexedEvent(string memory str, uint256 val, bool flag) public {
function firesMultiValueIndexedEvent(
string memory str,
uint256 val,
bool flag
) public {
emit MultiValueIndexedEvent(str, val, flag);
}

function firesStringEvent(string memory _str) public {
emit StringEvent(_str);
}

function firesMultiValueIndexedEventWithStringIndexed(string calldata str, uint256 val, bool flag) public {
function firesMultiValueIndexedEventWithStringIndexed(
string calldata str,
uint256 val,
bool flag
) public {
emit MultiValueIndexedEventWithStringIndexed(str, val, flag);
}
}
12 changes: 7 additions & 5 deletions fixtures/contracts/GreeterWithOverloading.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ contract GreeterWithOverloading {
return (true, greeting);
}

// function overlading with additional parameter
function setGreeting(string memory _greeting, bool _raiseEvents) public returns (bool, string memory) {
if(_raiseEvents) {
// function overlading with additional parameter
function setGreeting(string memory _greeting, bool _raiseEvents)
public
returns (bool, string memory)
{
if (_raiseEvents) {
emit GREETING_CHANGING(greeting, _greeting);
}
greeting = _greeting;
if(_raiseEvents) {
if (_raiseEvents) {
emit GREETING_CHANGED(greeting);
}
return (true, greeting);
Expand All @@ -41,4 +44,3 @@ contract GreeterWithOverloading {
counter = counter + 1;
}
}

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"tools/*"
]
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css,md}": "prettier --write"
},
"scripts": {
"version": "yarn run bootstrap && yarn build",
"bootstrap": "lerna bootstrap",
Expand Down Expand Up @@ -93,11 +96,10 @@
"test:blackbox:infura:ws": "yarn pre-blackbox && ./scripts/verdaccio.sh startBackgroundAndPublish && lerna run test:blackbox:infura:ws --stream && yarn post-blackbox",
"test:manual:long-connection-ws": "node packages/web3/test/stress/long_ws_tests/nodejs_test/long_connection_ws.js",
"test:stress": "yarn test:stress:geth:ws && yarn test:stress:geth:http && yarn test:stress:geth:ipc && yarn test:e2e:stress:geth:ws:chrome",
"husky:install": "husky install",
"husky:uninstall": "husky uninstall",
"postinstall": "yarn build",
"compile:contracts": "node ./scripts/compile_contracts.js && yarn format && yarn lint:fix",
"publish:canary": "lerna publish --canary --dist-tag dev --preid dev.$(git rev-parse --short HEAD) --exact --graph-type all --force-publish \"*\" --no-verify-access --yes"
"publish:canary": "lerna publish --canary --dist-tag dev --preid dev.$(git rev-parse --short HEAD) --exact --graph-type all --force-publish \"*\" --no-verify-access --yes",
"prepare": "husky install"
},
"devDependencies": {
"@cypress/webpack-preprocessor": "^5.12.0",
Expand All @@ -120,6 +122,7 @@
"husky": "^8.0.3",
"jest": "^29.7.0",
"lerna": "^6.6.2",
"lint-staged": "^15.2.9",
"npm-auth-to-token": "^1.0.0",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.20",
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Documentation:

### Fixed

- Fix `Web3Config` to properly update within other web3 packages when `setConfig` is used (#6555)
- Fix `Web3Config` to properly update within other web3 packages when `setConfig` is used (#6555)

### Added

Expand All @@ -205,7 +205,7 @@ Documentation:

### Changed

- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622)
- Web3config `contractDataInputFill` has been defaulted to `data`, istead of `input`. (#6622)

## [4.4.0]

Expand Down Expand Up @@ -233,4 +233,4 @@ Documentation:

- `setConfig()` fix for `setMaxListenerWarningThreshold` fix (#5079)

## [Unreleased]
## [Unreleased]
11 changes: 6 additions & 5 deletions packages/web3-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export const isWeb3Provider = <API extends Web3APISpec>(
export const isMetaMaskProvider = <API extends Web3APISpec>(
provider: SupportedProviders<API>,
): provider is MetaMaskProvider<API> =>
typeof provider !== 'string' &&
'request' in provider &&
provider.request.constructor.name === 'AsyncFunction' && 'isMetaMask' in provider && provider.isMetaMask;

typeof provider !== 'string' &&
'request' in provider &&
provider.request.constructor.name === 'AsyncFunction' &&
'isMetaMask' in provider &&
provider.isMetaMask;

export const isLegacyRequestProvider = <API extends Web3APISpec>(
provider: SupportedProviders<API>,
Expand All @@ -62,7 +63,7 @@ export const isLegacySendAsyncProvider = <API extends Web3APISpec>(

export const isSupportedProvider = <API extends Web3APISpec>(
provider: SupportedProviders<API>,
): provider is SupportedProviders<API> =>
): provider is SupportedProviders<API> =>
provider &&
(isWeb3Provider(provider) ||
isEIP1193Provider(provider) ||
Expand Down
7 changes: 4 additions & 3 deletions packages/web3-core/src/web3_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ export abstract class Web3Config
for (const key of keys) {
this._triggerConfigChange(key, options[key]);

if(!isNullish(options[key]) &&
if (
!isNullish(options[key]) &&
typeof options[key] === 'number' &&
key === 'maxListenersWarningThreshold' )
{
key === 'maxListenersWarningThreshold'
) {
// additionally set in event emitter
this.setMaxListenerWarningThreshold(Number(options[key]));
}
Expand Down
21 changes: 14 additions & 7 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import { ExistingPluginNamespaceError } from 'web3-errors';
import {
EthExecutionAPI,
HexString, Numbers, SupportedProviders, Transaction, Web3AccountProvider, Web3APISpec, Web3BaseProvider, Web3BaseWallet,
Web3BaseWalletAccount
HexString,
Numbers,
SupportedProviders,
Transaction,
Web3AccountProvider,
Web3APISpec,
Web3BaseProvider,
Web3BaseWallet,
Web3BaseWalletAccount,
} from 'web3-types';
import { isNullish } from 'web3-utils';
import { BaseTransaction, TransactionFactory } from 'web3-eth-accounts';
Expand Down Expand Up @@ -130,7 +137,7 @@ export class Web3Context<
registeredSubscriptions,
accountProvider,
wallet,
requestManagerMiddleware
requestManagerMiddleware,
} = providerOrContext as Web3ContextInitOptions<API, RegisteredSubs>;

this.setConfig(config ?? {});
Expand All @@ -140,7 +147,7 @@ export class Web3Context<
new Web3RequestManager<API>(
provider,
config?.enableExperimentalFeatures?.useSubscriptionWhenCheckingBlockTimeout,
requestManagerMiddleware
requestManagerMiddleware,
);

if (subscriptionManager) {
Expand Down Expand Up @@ -221,7 +228,7 @@ export class Web3Context<

// @ts-expect-error No index signature with a parameter of type 'string' was found on type 'Web3Context<API, RegisteredSubs>'
this[ContextRef.name] = newContextChild;

return newContextChild;
}

Expand Down Expand Up @@ -359,10 +366,10 @@ export class Web3Context<
return true;
}

public setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>){
public setRequestManagerMiddleware(requestManagerMiddleware: RequestManagerMiddleware<API>) {
this.requestManager.setMiddleware(requestManagerMiddleware);
}

/**
* Will return the {@link Web3BatchRequest} constructor.
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ Documentation:

### Added

- Added `InvalidIntegerError` error for fromWei and toWei (#7052)
- Added `InvalidIntegerError` error for fromWei and toWei (#7052)

## [1.2.1]

### Fixed

- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)

## [1.3.0]

### Added

- Added optional `statusCode` property of response in ResponseError.
- Added optional `statusCode` property of response in ResponseError.

## [Unreleased]
## [Unreleased]
1 change: 0 additions & 1 deletion packages/web3-errors/src/error_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export const ERR_INVALID_INTEGER = 1015;
// Validation error codes
export const ERR_VALIDATION = 1100;


// Core error codes
export const ERR_CORE_HARDFORK_MISMATCH = 1101;
export const ERR_CORE_CHAIN_MISMATCH = 1102;
Expand Down
11 changes: 8 additions & 3 deletions packages/web3-errors/src/errors/response_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ResponseError<ErrorType = unknown, RequestType = unknown> extends B
response: JsonRpcResponse<unknown, ErrorType>,
message?: string,
request?: JsonRpcPayload<RequestType>,
statusCode?: number
statusCode?: number,
) {
super(
message ??
Expand Down Expand Up @@ -85,7 +85,12 @@ export class ResponseError<ErrorType = unknown, RequestType = unknown> extends B
}

public toJSON() {
return { ...super.toJSON(), data: this.data, request: this.request, statusCode: this.statusCode };
return {
...super.toJSON(),
data: this.data,
request: this.request,
statusCode: this.statusCode,
};
}
}

Expand All @@ -111,4 +116,4 @@ export class InvalidResponseError<ErrorType = unknown, RequestType = unknown> ex
this.cause = errorOrErrors as Error | undefined;
}
}
}
}
1 change: 0 additions & 1 deletion packages/web3-errors/src/errors/schema_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ export class SchemaFormatError extends BaseWeb3Error {
public toJSON() {
return { ...super.toJSON(), type: this.type };
}

}
1 change: 0 additions & 1 deletion packages/web3-errors/src/errors/utils_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class InvalidIntegerError extends InvalidValueError {

public constructor(value: unknown) {
super(value, 'not a valid unit. Must be a positive integer');

}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
export * from './errors/core_errors.js';
export * from './errors/rpc_errors.js';
export * from './errors/rpc_error_messages.js';
export * from './errors/schema_errors.js';
export * from './errors/schema_errors.js';

Check warning on line 33 in packages/web3-errors/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/web3-errors/src/index.ts#L33

Added line #L33 was not covered by tests
7 changes: 2 additions & 5 deletions packages/web3-errors/test/unit/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ describe('errors', () => {
} as JsonRpcError<contractErrors.ProviderErrorData>).toJSON(),
).toMatchSnapshot();
});
it('should return correctly when data is undefined', () => {
it('should return correctly when data is undefined', () => {
expect(
new contractErrors.Eip838ExecutionError({
data: undefined,
Expand Down Expand Up @@ -391,10 +391,7 @@ describe('errors', () => {

describe('SchemaFormatError', () => {
it('should have valid json structure', () => {
expect(
new schemaErrors.SchemaFormatError("unsupported"
).toJSON(),
).toMatchSnapshot();
expect(new schemaErrors.SchemaFormatError('unsupported').toJSON()).toMatchSnapshot();
});
});
});
2 changes: 1 addition & 1 deletion packages/web3-eth-abi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ Documentation:

- fix encodedata in EIP-712 (#7095)

## [Unreleased]
## [Unreleased]
Loading
Loading