Skip to content

Commit

Permalink
fix: type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Sep 6, 2024
1 parent 7361a79 commit 796660d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ExtensionObject, RequestManagerMiddleware } from './types.js';
import { Web3BatchRequest } from './web3_batch_request.js';
// eslint-disable-next-line import/no-cycle
import { Web3Config, Web3ConfigEvent, Web3ConfigOptions } from './web3_config.js';
// eslint-disable-next-line import/no-cycle
import { Web3RequestManager } from './web3_request_manager.js';
import { Web3SubscriptionConstructor } from './web3_subscriptions.js';
import { Web3SubscriptionManager } from './web3_subscription_manager.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-core/src/web3_request_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
} from './utils.js';
import { Web3EventEmitter } from './web3_event_emitter.js';
import { RequestManagerMiddleware } from './types.js';
import { Web3ConfigOptions } from './web3_config.js';
import { type Web3ConfigOptions } from './web3_config.js';

export enum Web3RequestManagerEvent {
PROVIDER_CHANGED = 'PROVIDER_CHANGED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
"config": {
"blockHeaderTimeout": 10,
"contractDataInputFill": "data",
"customTransactionSchema": undefined,
"defaultAccount": undefined,
"defaultBlock": "latest",
"defaultChain": "mainnet",
Expand Down Expand Up @@ -73,6 +74,7 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
"clientUrl": "http://test/abc",
"httpProviderOptions": undefined,
},
"config": {},
"useRpcCallSpecification": undefined,
},
"subscriptionManager": Web3SubscriptionManager {
Expand Down Expand Up @@ -108,6 +110,7 @@ exports[`Web3Context getContextObject should return correct context object 1`] =
"clientUrl": "http://test/abc",
"httpProviderOptions": undefined,
},
"config": {},
"useRpcCallSpecification": undefined,
},
"tolerateUnlinkedSubscription": false,
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth/test/fixtures/format_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ export const numbersAsBigIntTransaction: FormatType<
s: '0x7e1941b264348e80c78c4027afc65a87b0a5e43e86742b8ca0823584c6788fd0',
};

export type CustomFieldTransaction = Transaction & { feeCurrency: `0x${string}` };
export const customFieldTransaction: FormatType<
Transaction,
CustomFieldTransaction,
{ number: FMT_NUMBER.BIGINT; bytes: typeof DEFAULT_RETURN_FORMAT.bytes }
> = {
from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0',
Expand Down
25 changes: 17 additions & 8 deletions packages/web3-eth/test/unit/format_transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
numbersAsNumberTransaction,
bytesAsUint8ArrayTransaction,
customFieldTransaction,
CustomFieldTransaction,
} from '../fixtures/format_transaction';
import { objectBigintToString } from '../fixtures/system_test_utils';
import { transactionSchema } from '../../src';
Expand Down Expand Up @@ -120,17 +121,25 @@ describe('formatTransaction', () => {
});

it('Accepts a custom schema', () => {
expect(formatTransaction(customFieldTransaction).feeCurrency).toBeUndefined();
expect(
formatTransaction(customFieldTransaction, undefined, {
transactionSchema: {
...transactionSchema,
properties: {
...transactionSchema.properties,
feeCurrency: 'address',
formatTransaction<typeof DEFAULT_RETURN_FORMAT, CustomFieldTransaction>(
customFieldTransaction,
).feeCurrency,
).toBeUndefined();
expect(
formatTransaction<typeof DEFAULT_RETURN_FORMAT, CustomFieldTransaction>(
customFieldTransaction,
undefined,
{
transactionSchema: {
...transactionSchema,
properties: {
...transactionSchema.properties,
feeCurrency: { format: 'address' },
},
},
},
}).feeCurrency,
).feeCurrency,
).toBeDefined();
});
});

0 comments on commit 796660d

Please sign in to comment.