Skip to content

Commit

Permalink
Merge branch '4.x' into feature/5406/4x-packages-badges
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba authored Mar 27, 2023
2 parents 02fb94c + c019149 commit 12b29da
Show file tree
Hide file tree
Showing 50 changed files with 1,046 additions and 232 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

# Automatically assigns members of the web3.js team to new pending PRs as reviewers
* @web3/web3-js
* @avkos @jdevcs @luu-alex @Muhammad-Altabba @nikoulai @spacesailor24
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,44 @@ should use 4.0.1-alpha.0 for testing.
- Fixed getPastEventsError (#5819)

## [Unreleased]

### Changed

#### web3-core

- If a transaction object with a `data` property is passed to `txInputOptionsFormatter`, it will now be replaced with `input` (#5915)

#### web3-errors

- `gasLimit` is no longer accepted as a parameter for `MissingGasError` and `TransactionGasMismatchError, and is also no longer included in error message (#5915)

#### web3-eth

- `signTransaction` will now return `gas` instead of `gasLimit` for returned transaction object regardless of what property name the provider uses (#5915)
- `formatTransaction` will now replace `data` transaction property with `input` (#5915)
- `isTransactionCall` will now check if `value.input` `isHexStrict` if provided (#5915)

#### web3-eth-contract

- `getSendTxParams` will now return `input` instead of `data` in returned transaction parameters object (#5915)
- `Contract` constructor will now thrown new `ContractTransactionDataAndInputError` if both `data` and `input` are passed in `ContractInitOptions` for `Contract` constructor (#5915)

#### web3-types

- `data` property in `TransactionOutput` was renamed to `input` (#5915)

### Added

#### web3-eth-contract

- `input` is now an acceptable property for `ContractInitOptions` in place of `data` (either can be used, but `input` is used withing the

### Removed

#### web3-eth-abi

- Removed `formatDecodedObject` function (#5934)

#### web3-eth-contract

- `data` was removed as a property of `ContractOptions` type (#5915)
58 changes: 58 additions & 0 deletions docs/docs/guides/web3_migration_guide/providers_migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,35 @@ const provider = new WebSocketProvider(
);
```

#### Legacy Event `close` has been deprecated

Following EIP-1193, the `close` event has been deprecated and is superceded by `disconnect`.
In 1.x, we listen for a `close` event:

```ts
const provider = new WebSocketProvider(host + port);
// we would use close to listen to the disconnect function
provider.on('close', function (err) {
console.log('closed');
resolve();
});
provider.disconnect(1012);
// would eventually log closed
```

In 4.x, we listen for a `disconnect` event:

```ts
const provider = new WebSocketProvider(host + port);
// we would use disconnect to listen to the disconnect function
provider.on('disconnect', function (err) {
console.log('closed');
resolve();
});
provider.disconnect(1012);
// would eventually log 'closed'
```

#### IpcProvider

The IPC provider is used in node.js dapps when running a local node. And it provide the most secure connection.
Expand Down Expand Up @@ -313,3 +342,32 @@ provider.on('error', error => {
}
});
```

#### Legacy Event `close` has been deprecated

Following EIP-1193, the `close` event has been deprecated and is superceded by `disconnect`.
In 1.x, we listen for a `close` event:

```ts
const provider = new IpcProvider(host + port);
// we would use close to listen to the disconnect function
provider.on('close', function (err) {
console.log('closed');
resolve();
});
provider.disconnect(1012);
// would eventually log closed
```

In 4.x, we listen for a `disconnect` event:

```ts
const provider = new IpcProvider(host + port);
// we would use disconnect to listen to the disconnect function
provider.on('disconnect', function (err) {
console.log('closed');
resolve();
});
provider.disconnect(1012);
// would eventually log 'closed'
```
4 changes: 4 additions & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support of `safe` and `finalized` block tags (#5823)

## [Unreleased]

### Changed

- If a transaction object with a `data` property is passed to `txInputOptionsFormatter`, it will now be replaced with `input` (#5915)
14 changes: 7 additions & 7 deletions packages/web3-core/src/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ export const txInputOptionsFormatter = (options: TransactionInput): Mutable<Tran
);
}

if (!options.data && options.input) {
modifiedOptions.data = options.input;
delete modifiedOptions.input;
if (!options.input && options.data) {
modifiedOptions.input = options.data;
delete modifiedOptions.data;
}

if (options.data && !options.data.startsWith('0x')) {
modifiedOptions.data = `0x${options.data}`;
if (options.input && !options.input.startsWith('0x')) {
modifiedOptions.input = `0x${options.input}`;
}

if (modifiedOptions.data && !isHexStrict(modifiedOptions.data)) {
throw new FormatterError('The data field must be HEX encoded data.');
if (modifiedOptions.input && !isHexStrict(modifiedOptions.input)) {
throw new FormatterError('The input field must be HEX encoded data.');
}

// allow both
Expand Down
20 changes: 10 additions & 10 deletions packages/web3-core/test/unit/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,24 @@ describe('formatters', () => {
);
});

it('should replace "data" with "input" if "input" is given and "data" is not', () => {
const result = txInputOptionsFormatter({ ...txInput, input: '0xff0011' });
it('should replace "input" with "data" if "data" is given and "input" is not', () => {
const result = txInputOptionsFormatter({ ...txInput, data: '0xff0011' });

expect(result).toEqual(expect.objectContaining({ data: '0xff0011' }));
expect(Object.keys(result)).not.toContain('input');
expect(result).toEqual(expect.objectContaining({ input: '0xff0011' }));
expect(Object.keys(result)).not.toContain('data');
});

it('should prefix "data" with "0x" if not already', () => {
expect(txInputOptionsFormatter({ ...txInput, data: 'ff0011' })).toEqual(
expect.objectContaining({ data: '0xff0011' }),
it('should prefix "input" with "0x" if not already', () => {
expect(txInputOptionsFormatter({ ...txInput, input: 'ff0011' })).toEqual(
expect.objectContaining({ input: '0xff0011' }),
);
});

it('should throw error if "data" is not a valid hex string', () => {
it('should throw error if "input" is not a valid hex string', () => {
jest.spyOn(utils, 'isHexStrict').mockReturnValue(false);

expect(() => txInputOptionsFormatter({ ...txInput, data: 'ff0011' })).toThrow(
'The data field must be HEX encoded data.',
expect(() => txInputOptionsFormatter({ ...txInput, input: 'ff0011' })).toThrow(
'The input field must be HEX encoded data.',
);
expect(utils.isHexStrict).toHaveBeenCalledWith('0xff0011');
});
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `TransactionRevertWithCustomError` was added to handle custom solidity errors (#5854)

## [Unreleased]

### Changed

- `gasLimit` is no longer accepted as a parameter for `MissingGasError` and `TransactionGasMismatchError, and is also no longer included in error message (#5915)
1 change: 1 addition & 0 deletions packages/web3-errors/src/error_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const ERR_CONTRACT_MISSING_ADDRESS = 307;
export const ERR_CONTRACT_MISSING_FROM_ADDRESS = 308;
export const ERR_CONTRACT_INSTANTIATION = 309;
export const ERR_CONTRACT_EXECUTION_REVERTED = 310;
export const ERR_CONTRACT_TX_DATA_AND_INPUT = 311;

// Transaction error codes
export const ERR_TX = 400;
Expand Down
14 changes: 13 additions & 1 deletion packages/web3-errors/src/errors/contract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import {
ERR_CONTRACT_REQUIRED_CALLBACK,
ERR_CONTRACT_RESERVED_EVENT,
ERR_CONTRACT_RESOLVER_MISSING,
ERR_CONTRACT_TX_DATA_AND_INPUT,
} from '../error_codes';
import { BaseWeb3Error } from '../web3_error_base';
import { BaseWeb3Error, InvalidValueError } from '../web3_error_base';

export class Web3ContractError extends BaseWeb3Error {
public code = ERR_CONTRACT;
Expand Down Expand Up @@ -172,3 +173,14 @@ export class ContractExecutionError extends Web3ContractError {
);
}
}

export class ContractTransactionDataAndInputError extends InvalidValueError {
public code = ERR_CONTRACT_TX_DATA_AND_INPUT;

public constructor(value: { data: HexString | undefined; input: HexString | undefined }) {
super(
`data: ${value.data ?? 'undefined'}, input: ${value.input ?? 'undefined'}`,
'You can\'t have "data" and "input" as properties of a contract at the same time, please use either "data" or "input" instead.',
);
}
}
26 changes: 12 additions & 14 deletions packages/web3-errors/src/errors/transaction_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ export class InvalidTransactionWithSender extends InvalidValueError {
public code = ERR_TX_INVALID_SENDER;

public constructor(value: unknown) {
super(value, 'invalid transaction with sender');
super(value, 'invalid transaction with invalid sender');
}
}
export class InvalidTransactionWithReceiver extends InvalidValueError {
public code = ERR_TX_INVALID_RECEIVER;

public constructor(value: unknown) {
super(value, 'invalid transaction with receiver');
super(value, 'invalid transaction with invalid receiver');
}
}
export class InvalidTransactionCall extends InvalidValueError {
Expand Down Expand Up @@ -310,17 +310,16 @@ export class MissingGasError extends InvalidValueError {

public constructor(value: {
gas: Numbers | undefined;
gasLimit: Numbers | undefined;
gasPrice: Numbers | undefined;
maxPriorityFeePerGas: Numbers | undefined;
maxFeePerGas: Numbers | undefined;
}) {
super(
`gas: ${value.gas ?? 'undefined'}, gasLimit: ${
value.gasLimit ?? 'undefined'
}, gasPrice: ${value.gasPrice ?? 'undefined'}, maxPriorityFeePerGas: ${
value.maxPriorityFeePerGas ?? 'undefined'
}, maxFeePerGas: ${value.maxFeePerGas ?? 'undefined'}`,
`gas: ${value.gas ?? 'undefined'}, gasPrice: ${
value.gasPrice ?? 'undefined'
}, maxPriorityFeePerGas: ${value.maxPriorityFeePerGas ?? 'undefined'}, maxFeePerGas: ${
value.maxFeePerGas ?? 'undefined'
}`,
'"gas" is missing',
);
}
Expand All @@ -331,17 +330,16 @@ export class TransactionGasMismatchError extends InvalidValueError {

public constructor(value: {
gas: Numbers | undefined;
gasLimit: Numbers | undefined;
gasPrice: Numbers | undefined;
maxPriorityFeePerGas: Numbers | undefined;
maxFeePerGas: Numbers | undefined;
}) {
super(
`gas: ${value.gas ?? 'undefined'}, gasLimit: ${
value.gasLimit ?? 'undefined'
}, gasPrice: ${value.gasPrice ?? 'undefined'}, maxPriorityFeePerGas: ${
value.maxPriorityFeePerGas ?? 'undefined'
}, maxFeePerGas: ${value.maxFeePerGas ?? 'undefined'}`,
`gas: ${value.gas ?? 'undefined'}, gasPrice: ${
value.gasPrice ?? 'undefined'
}, maxPriorityFeePerGas: ${value.maxPriorityFeePerGas ?? 'undefined'}, maxFeePerGas: ${
value.maxFeePerGas ?? 'undefined'
}`,
'transaction must specify legacy or fee market gas properties, not both',
);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/web3-eth-contract/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,17 @@ const transactionHash = receipt.transactionHash;
- `decodeErrorData` is no longer exported (method was moved to `web3-eth-abi` and renamed `decodeContractErrorData`) (#5844)

## [Unreleased]

### Added

- `input` is now an acceptable property for `ContractInitOptions` in place of `data` (either can be used, but `input` is used withing the
`Contract` class) (#5915)

### Changed

- `getSendTxParams` will now return `input` instead of `data` in returned transaction parameters object (#5915)
- `Contract` constructor will now thrown new `ContractTransactionDataAndInputError` if both `data` and `input` are passed in `ContractInitOptions` for `Contract` constructor (#5915)

### Removed

- `data` was removed as a property of `ContractOptions` type (#5915)
Loading

0 comments on commit 12b29da

Please sign in to comment.