Skip to content

Commit

Permalink
Merge branch '1.x' into add-string-event-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed May 5, 2020
2 parents a298c9e + 9313265 commit 3655531
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
11 changes: 10 additions & 1 deletion packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
*/

import * as net from 'net';
import { EventEmitter } from "events"
import {
HttpProviderBase,
HttpProviderOptions,
IpcProviderBase,
WebsocketProviderBase,
WebsocketProviderOptions
WebsocketProviderOptions,
JsonRpcPayload,
JsonRpcResponse
} from 'web3-core-helpers';
import { Method } from 'web3-core-method';
import BN = require('bn.js');
Expand Down Expand Up @@ -408,9 +411,15 @@ export interface LogsOptions {

export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis';

export interface AbstractProvider {
send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void;
sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void;
}

export type provider =
| HttpProvider
| IpcProvider
| WebsocketProvider
| AbstractProvider
| string
| null;
15 changes: 14 additions & 1 deletion packages/web3-eth-contract/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class Contract {

deploy(options: DeployOptions): ContractSendMethod;

methods: any;
methods: {
[key: string]: ContractSendMethod;
};

once(
event: string,
Expand Down Expand Up @@ -89,6 +91,11 @@ export interface ContractSendMethod {
callback?: (err: Error, transactionHash: string) => void
): PromiEvent<Contract>;

call(
options?: CallOptions,
callback?: (err: Error, result: any) => void
): Promise<any>;

estimateGas(
options: EstimateGasOptions,
callback?: (err: Error, gas: number) => void
Expand All @@ -108,6 +115,12 @@ export interface ContractSendMethod {
encodeABI(): string;
}

export interface CallOptions {
from?: string;
gasPrice?: string;
gas?: number;
}

export interface SendOptions {
from: string;
gasPrice?: string;
Expand Down
45 changes: 43 additions & 2 deletions packages/web3-providers-http/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,48 @@
* @author Josh Stevens <[email protected]>
* @date 2018
*/
import * as http from 'http';
import * as https from 'https';

import { HttpProviderBase } from 'web3-core-helpers';
import { HttpProviderBase, JsonRpcResponse } from 'web3-core-helpers';

export class HttpProvider extends HttpProviderBase {}
export interface HttpHeader {
name: string;
value: string;
}

export interface HttpProviderAgent {
baseUrl?: string;
http?: http.Agent;
https?: https.Agent;
}

export interface HttpProviderOptions {
withCredentials?: boolean;
timeout?: number;
headers?: HttpHeader[];
agent?: HttpProviderAgent;
keepAlive?: boolean;
}

export class HttpProvider extends HttpProviderBase {
host: string;

withCredentials: boolean;
timeout: number;
headers?: HttpHeader[];
agent?: HttpProviderAgent;
connected: boolean;

constructor(host?: string, options?: HttpProviderOptions);

send(
payload: object,
callback?: (
error: Error | null,
result: JsonRpcResponse | undefined
) => void
): void;
disconnect(): boolean;
supportsSubscriptions(): boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const httpProvider = new HttpProvider('http://localhost:8545', {
});

// $ExpectType void
httpProvider.send({} as any, (error: Error | null) => {});
httpProvider.send({}, (error: Error | null) => {});

// $ExpectType void
httpProvider.send({} as any, (error: Error | null, result: JsonRpcResponse | undefined) => {});
httpProvider.send({}, (error: Error | null, result: JsonRpcResponse | undefined) => {});

// $ExpectType boolean
httpProvider.disconnect();
10 changes: 10 additions & 0 deletions packages/web3/types/tests/web3-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import Web3 from 'web3';
import * as net from 'net';
import { AbstractProvider } from 'web3-core';
import { JsonRpcPayload, JsonRpcResponse } from "web3-core-helpers"
import { EventEmitter } from 'events';

// $ExpectType Utils
Web3.utils;
Expand Down Expand Up @@ -85,3 +88,10 @@ web3 = new Web3('https://localhost:5000/', netSocket);

// $ExpectType Web3
web3 = new Web3();

class CustomProvider implements AbstractProvider {
send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {}
sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {}
}
// $ExpectType Web3
web3 = new Web3(new CustomProvider());

0 comments on commit 3655531

Please sign in to comment.