diff --git a/.circleci/config.yml b/.circleci/config.yml index 12de424902..6a6a5311a6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -383,38 +383,38 @@ workflows: main: jobs: - build - - build-website: - requires: - - build - - test-contracts-ganache: - requires: - - build + # - build-website: + # requires: + # - build + # - test-contracts-ganache: + # requires: + # - build # TODO(albrow): Tests always fail on Geth right now because our fork # is outdated. Uncomment once we have updated our Geth fork. # - test-contracts-geth: # requires: # - build - - test-rest: - requires: - - build + # - test-rest: + # requires: + # - build - static-tests: requires: - build - test-publish: requires: - build - - test-doc-generation: - requires: - - build - - submit-coverage: - requires: - - test-rest - - test-python - - static-tests-python: - requires: - - test-python - - test-python: - requires: - - build + # - test-doc-generation: + # requires: + # - build + # - submit-coverage: + # requires: + # - test-rest + # - test-python + # - static-tests-python: + # requires: + # - test-python + # - test-python: + # requires: + # - build # skip python tox run for now, as we don't yet have multiple test environments to support. #- test-rest-python diff --git a/packages/base-contract/tsconfig.json b/packages/base-contract/tsconfig.json index 718e623c74..bf70fcb4cd 100644 --- a/packages/base-contract/tsconfig.json +++ b/packages/base-contract/tsconfig.json @@ -4,5 +4,6 @@ "outDir": "lib", "rootDir": "." }, + "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], "include": ["src/**/*", "test/**/*"] } diff --git a/packages/typescript-typings/types/ethereumjs-account/index.d.ts b/packages/typescript-typings/types/ethereumjs-account/index.d.ts new file mode 100644 index 0000000000..0e7d7cb3b6 --- /dev/null +++ b/packages/typescript-typings/types/ethereumjs-account/index.d.ts @@ -0,0 +1,31 @@ +declare module 'ethereumjs-account' { + export class Account { + public nonce!: Buffer; + public balance!: Buffer; + public stateRoot!: Buffer; + public codeHash!: Buffer; + constructor(data?: any); + serialize(): Buffer; + getCode(trie: Trie, cb: TrieGetCb): void; + setCode(trie: Trie, code: Buffer, cb: (err: any, codeHash: Buffer) => void): void; + getStorage(trie: Trie, key: Buffer | string, cb: TrieGetCb); + setStorage(trie: Trie, key: Buffer | string, val: Buffer | string, cb: () => void); + isEmpty(): boolean; + } + + interface TrieGetCb { + (err: any, value: Buffer | null): void; + } + interface TriePutCb { + (err?: any): void; + } + + interface Trie { + root: Buffer; + copy(): Trie; + getRaw(key: Buffer, cb: TrieGetCb): void; + putRaw(key: Buffer | string, value: Buffer, cb: TriePutCb): void; + get(key: Buffer | string, cb: TrieGetCb): void; + put(key: Buffer | string, value: Buffer | string, cb: TriePutCb): void; + } +} diff --git a/packages/typescript-typings/types/ethereumjs-blockchain/index.d.ts b/packages/typescript-typings/types/ethereumjs-blockchain/index.d.ts new file mode 100644 index 0000000000..49fa42ebf7 --- /dev/null +++ b/packages/typescript-typings/types/ethereumjs-blockchain/index.d.ts @@ -0,0 +1,103 @@ +declare module 'ethereumjs-blockchain' { + import BN = require('bn.js'); + import Common from 'ethereumjs-common'; + import Block from 'ethereumjs-block'; + + interface BlockchainInterface { + putBlock(block: Block, cb: any, isGenesis?: boolean): void; + delBlock(blockHash: Buffer, cb: any): void; + getBlock(blockTag: Buffer | number | BN, cb: (err: Error | null, block?: Block) => void): void; + iterator(name: string, onBlock: any, cb: any): void; + getDetails(_: string, cb: any): void; + } + + interface BlockchainOptions { + chain?: string | number; + hardfork?: string | null; + common?: Common; + db?: any; + validate?: boolean; + validatePow?: boolean; + validateBlocks?: boolean; + } + + export class Blockchain implements BlockchainInterface { + _common: Common; + _genesis: any; + _headBlock: any; + _headHeader: any; + _heads: any; + _initDone: boolean; + _initLock: any; + _putSemaphore: any; + _staleHeadBlock: any; + _staleHeads: any; + db: any; + dbManager: DBManager; + ethash: any; + public readonly validate: boolean; + private readonly _validatePow: boolean; + private readonly _validateBlocks: boolean; + + constructor(opts: BlockchainOptions); + meta(): any; + _init(cb: any): void; + _setCanonicalGenesisBlock(cb: any): void; + putGenesis(genesis: any, cb: any): void; + getHead(name: any, cb?: any): void; + getLatestHeader(cb: any): void; + getLatestBlock(cb: any); + putBlocks(blocks: Array, cb: any); + putBlock(block: object, cb: any, isGenesis?: boolean); + putHeaders(headers: Array, cb: any); + putHeader(header: object, cb: any); + _putBlockOrHeader(item: any, cb: any, isGenesis?: boolean); + getBlock(blockTag: Buffer | number | BN, cb: any); + _getBlock(blockTag: Buffer | number | BN, cb: any); + getBlocks(blockId: Buffer | number, maxBlocks: number, skip: number, reverse: boolean, cb: any); + getDetails(_: string, cb: any); + selectNeededHashes(hashes: Array, cb: any); + _saveHeadOps(); + _saveHeads(cb: any); + _deleteStaleAssignments(number: BN, headHash: Buffer, ops: any, cb: any); + _rebuildCanonical(header: any, ops: any, cb: any); + delBlock(blockHash: Buffer, cb: any); + _delBlock(blockHash: Buffer | typeof Block, cb: any); + _delChild(hash: Buffer, number: BN, headHash: Buffer, ops: any, cb: any); + _iterator(name: string, func: any, cb: any); + _batchDbOps(dbOps: any, cb: any): void; + _hashToNumber(hash: Buffer, cb: any): void; + _numberToHash(number: BN, cb: any): void; + _lookupByHashNumber(hash: Buffer, number: BN, cb: any, next: any): void; + _getHeader(hash: Buffer, number: any, cb?: any): void; + _getCanonicalHeader(number: BN, cb: any): void; + _getTd(hash: any, number: any, cb?: any): void; + _lockUnlock(fn: any, cb: any): void; + } + + class DBManager { + _cache: { [k: string]: Cache }; + _common: any; + _db: any; + constructor(db: any, common: any); + getHeads(): Promise; + getHeadHeader(): Promise; + getHeadBlock(): Promise; + getBlock(blockTag: Buffer | BN | number): Promise; + getBody(hash: Buffer, number: BN): Promise; + getHeader(hash: Buffer, number: BN); + getTd(hash: Buffer, number: BN): Promise; + hashToNumber(hash: Buffer): Promise; + numberToHash(number: BN): Promise; + get(key: string | Buffer, opts: any = {}): Promise; + batch(ops: Array): Promise; + } + + class Cache { + _cache: LRU; + constructor(opts: LRU.Options); + set(key: string | Buffer, value: V): void; + get(key: string | Buffer): V | undefined; + del(key: string | Buffer): void; + } +} diff --git a/packages/typescript-typings/types/ethereumjs-common/index.d.ts b/packages/typescript-typings/types/ethereumjs-common/index.d.ts new file mode 100644 index 0000000000..a5dafe8fc3 --- /dev/null +++ b/packages/typescript-typings/types/ethereumjs-common/index.d.ts @@ -0,0 +1,81 @@ +declare module 'ethereumjs-common' { + export class Common { + private _hardfork: string | null; + private _supportedHardforks: Array; + private _chainParams: Chain; + forCustomChain( + baseChain: string | number, + customChainParams: Partial, + hardfork?: string | null, + supportedHardforks?: Array, + ): Common; + _getChainParams(chain: string | number): Chain; + constructor(chain: string | number | object, hardfork?: string | null, supportedHardforks?: Array); + setChain(chain: string | number | object): any; + setHardfork(hardfork: string | null): void; + _chooseHardfork(hardfork?: string | null, onlySupported?: boolean): string; + _getHardfork(hardfork: string): any; + _isSupportedHardfork(hardfork: string | null): boolean; + param(topic: string, name: string, hardfork?: string): any; + paramByBlock(topic: string, name: string, blockNumber: number): any; + hardforkIsActiveOnBlock(hardfork: string | null, blockNumber: number, opts?: hardforkOptions): boolean; + activeOnBlock(blockNumber: number, opts?: hardforkOptions): boolean; + hardforkGteHardfork(hardfork1: string | null, hardfork2: string, opts?: hardforkOptions): boolean; + gteHardfork(hardfork: string, opts?: hardforkOptions): boolean; + hardforkIsActiveOnChain(hardfork?: string | null, opts?: hardforkOptions): boolean; + activeHardforks(blockNumber?: number | null, opts?: hardforkOptions): Array; + activeHardfork(blockNumber?: number | null, opts?: hardforkOptions): string; + hardforkBlock(hardfork?: string): number; + isHardforkBlock(blockNumber: number, hardfork?: string): boolean; + consensus(hardfork?: string): string; + finality(hardfork?: string): string; + genesis(): any; + hardforks(): any; + bootstrapNodes(): any; + hardfork(): string | null; + chainId(): number; + chainName(): string; + networkId(): number; + } + + interface hardforkOptions { + onlySupported?: boolean; + onlyActive?: boolean; + } + + interface Chain { + name: string; + chainId: number; + networkId: number; + comment: string; + url: string; + genesis: GenesisBlock; + hardforks: Hardfork[]; + bootstrapNodes: BootstrapNode[]; + } + + interface GenesisBlock { + hash: string; + timestamp: string | null; + gasLimit: number; + difficulty: number; + nonce: string; + extraData: string; + stateRoot: string; + } + interface Hardfork { + name: string; + block: number | null; + consensus: string; + finality: any; + } + interface BootstrapNode { + ip: string; + port: number | string; + network?: string; + chainId?: number; + id: string; + location: string; + comment: string; + } +} diff --git a/packages/typescript-typings/types/ethereumjs-vm/index.d.ts b/packages/typescript-typings/types/ethereumjs-vm/index.d.ts new file mode 100644 index 0000000000..64dae3ac8a --- /dev/null +++ b/packages/typescript-typings/types/ethereumjs-vm/index.d.ts @@ -0,0 +1,318 @@ +declare module 'ethereumjs-vm' { + import BN = require('bn.js'); + import Blockchain from 'ethereumjs-blockchain'; + import Common from 'ethereumjs-common'; + import Account from 'ethereumjs-account'; + + export function runCall(opts: RunCallOpts): Promise; + + interface RunCallOpts { + block?: any; + gasPrice?: Buffer; + origin?: Buffer; + caller?: Buffer; + gasLimit?: Buffer; + to?: Buffer; + value?: Buffer; + data?: Buffer; + code?: Buffer; + depth?: number; + compiled?: boolean; + static?: boolean; + salt?: Buffer; + selfdestruct?: { [k: string]: boolean }; + delegatecall?: boolean; + } + + interface EVMResult { + gasUsed: BN; + createdAddress?: Buffer; + execResult: ExecResult; + } + + interface ExecResult { + runState?: RunState; + exceptionError?: VmError; + gas?: BN; + gasUsed: BN; + returnValue: Buffer; + logs?: any[]; + gasRefund?: BN; + selfdestruct?: { [k: string]: Buffer }; + } + interface RunState { + programCounter: number; + opCode: number; + memory: Memory; + memoryWordCount: BN; + highestMemCost: BN; + stack: Stack; + code: Buffer; + validJumps: number[]; + _common: Common; + stateManager: StateManager; + eei: EEI; + } + + class Memory { + _store: number[]; + constructor(); + extend(offset: number, size: number): void; + write(offset: number, size: number, value: Buffer): void; + read(offset: number, size: number): Buffer; + } + + class Stack { + _store: BN[]; + constructor(); + length(): number; + push(value: BN): void; + pop(): BN; + popN(num: number): BN[]; + swap(position: number): void; + dup(position: number): void; + } + + class StateManager { + _common: Common; + _trie: any; + _storageTries: any; + _cache: Cache; + _touched: Set; + _touchedStack: Set[]; + _checkpointCount: number; + _originalStorageCache: Map>; + + constructor(opts: StateManagerOpts); + copy(): StateManager; + getAccount(address: Buffer, cb: any): void; + putAccount(address: Buffer, account: Account, cb: any): void; + putContractCode(address: Buffer, value: Buffer, cb: any): void; + getContractCode(address: Buffer, cb: any): void; + _lookupStorageTrie(address: Buffer, cb: any): void; + _getStorageTrie(address: Buffer, cb: any): void; + getContractStorage(address: Buffer, key: Buffer, cb: any): void; + getOriginalContractStorage(address: Buffer, key: Buffer, cb: any): void; + _modifyContractStorage(address: Buffer, modifyTrie: any, cb: any): void; + putContractStorage(address: Buffer, key: Buffer, value: Buffer, cb: any): void; + clearContractStorage(address: Buffer, cb: any): void; + checkpoint(cb: any): void; + commit(cb: any): void; + revert(cb: any): void; + getStateRoot(cb: any): void; + setStateRoot(stateRoot: Buffer, cb: any): void; + dumpStorage(address: Buffer, cb: any): void; + hasGenesisState(cb: any): void; + generateCanonicalGenesis(cb: any): void; + generateGenesis(initState: any, cb: any); + accountIsEmpty(address: Buffer, cb: any): void; + cleanupTouchedAccounts(cb: any): void; + _clearOriginalStorageCache(): void; + } + + class Cache { + _cache: any; + _checkpoints: any[]; + _trie: any; + constructor(trie: any); + put(key: Buffer, val: Account, fromTrie: boolean): void; + get(key: Buffer): Account; + lookup(key: Buffer): Account | undefined; + _lookupAccount(address: Buffer, cb: any): void; + getOrLoad(key: Buffer, cb: any): void; + warm(addresses: string[], cb: any): void; + flush(cb: any): void; + checkpoint(): void; + revert(): void; + commit(): void; + clear(): void; + del(key: Buffer): void; + _update(key: Buffer, val: Account, modified: boolean, deleted: boolean): void; + } + + interface StateManagerOpts { + common?: Common; + trie?: any; + } + + class EEI { + _env: Env; + _result: RunResult; + _state: PStateManager; + _evm: EVM; + _lastReturned: Buffer; + _common: Common; + _gasLeft: BN; + constructor(env: Env, state: PStateManager, evm: EVM, common: Common, gasLeft: BN); + useGas(amount: BN): void; + refundGas(amount: BN): void; + getAddress(): Buffer; + getExternalBalance(address: Buffer): Promise; + getSelfBalance(): BN; + getCaller(): BN; + getCallValue(): BN; + getCallData(): Buffer; + getCallDataSize(): BN; + getCodeSize(): BN; + getCode(): Buffer; + isStatic(): boolean; + getExternalCodeSize(address: BN): Promise; + getExternalCode(address: BN | Buffer): Promise; + getReturnDataSize(): BN; + getReturnData(): Buffer; + getTxGasPrice(): BN; + getTxOrigin(): BN; + getBlockNumber(): BN; + getBlockCoinbase(): BN; + getBlockTimestamp(): BN; + getBlockDifficulty(): BN; + getBlockGasLimit(): BN; + getChainId(): BN; + getBlockHash(num: BN): Promise; + storageStore(key: Buffer, value: Buffer): Promise; + storageLoad(key: Buffer): Promise; + getGasLeft(): BN; + finish(returnData: Buffer): void; + revert(returnData: Buffer): void; + selfDestruct(toAddress: Buffer): Promise; + _selfDestruct(toAddress: Buffer): Promise; + log(data: Buffer, numberOfTopics: number, topics: Buffer[]): void; + call(gasLimit: BN, address: Buffer, value: BN, data: Buffer): Promise; + callCode(gasLimit: BN, address: Buffer, value: BN, data: Buffer): Promise; + callStatic(gasLimit: BN, address: Buffer, value: BN, data: Buffer): Promise; + callDelegate(gasLimit: BN, address: Buffer, value: BN, data: Buffer): Promise; + _baseCall(msg: Message): Promise; + create(gasLimit: BN, value: BN, data: Buffer, salt: Buffer | null): Promise; + create2(gasLimit: BN, value: BN, data: Buffer, salt: Buffer): Promise; + isAccountEmpty(address: Buffer): Promise; + private _getReturnCode(results: EVMResult); + } + + interface Env { + blockchain: Blockchain; + address: Buffer; + caller: Buffer; + callData: Buffer; + callValue: BN; + code: Buffer; + isStatic: boolean; + depth: number; + gasPrice: Buffer; + origin: Buffer; + block: any; + contract: Account; + } + + interface RunResult { + logs: any; + returnValue?: Buffer; + gasRefund: BN; + selfdestruct: { [k: string]: Buffer }; + } + + class PStateManager { + _wrapped: StateManager; + constructor(wrapped: StateManager); + copy(): PStateManager; + getAccount(addr: Buffer): Promise; + putAccount(addr: Buffer, account: Account): Promise; + putContractCode(addr: Buffer, code: Buffer): Promise; + getContractCode(addr: Buffer): Promise; + getContractStorage(addr: Buffer, key: Buffer): Promise; + getOriginalContractStorage(addr: Buffer, key: Buffer): Promise; + putContractStorage(addr: Buffer, key: Buffer, value: Buffer): Promise; + clearContractStorage(addr: Buffer): Promise; + checkpoint(): Promise; + commit(): Promise; + revert(): Promise; + getStateRoot(): Promise; + setStateRoot(root: Buffer): Promise; + dumpStorage(address: Buffer): Promise; + hasGenesisState(): Promise; + generateCanonicalGenesis(): Promise; + generateGenesis(initState: any): Promise; + accountIsEmpty(address: Buffer): Promise; + cleanupTouchedAccounts(): Promise; + } + + interface StorageDump { + [key: string]: string; + } + + class EVM { + _vm: any; + _state: PStateManager; + _tx: TxContext; + _block: any; + constructor(vm: any, txContext: TxContext, block: any); + executeMessage(message: Message): Promise; + _executeCall(message: Message): Promise; + _executeCreate(message: Message): Promise; + runInterpreter(message: Message, opts: InterpreterOpts): Promise; + getPrecompile(address: Buffer): PrecompileFunc; + runPrecompile(code: PrecompileFunc, data: Buffer, gasLimit: BN): ExecResult; + _loadCode(message: Message): Promise; + _generateAddress(message: Message): Promise; + _reduceSenderBalance(account: Account, message: Message): Promise; + _addToBalance(toAccount: Account, message: Message): Promise; + _touchAccount(address: Buffer): Promise; + } + + class TxContext { + gasPrice: Buffer; + origin: Buffer; + constructor(gasPrice: Buffer, origin: Buffer); + } + + class Message { + to: Buffer; + value: BN; + caller: Buffer; + gasLimit: BN; + data: Buffer; + depth: number; + code: Buffer | PrecompileFunc; + _codeAddress: Buffer; + isStatic: boolean; + isCompiled: boolean; + salt: Buffer; + selfdestruct: any; + delegatecall: boolean; + constructor(opts: any); + codeAddress(): Buffer; + } + + interface InterpreterOpts { + pc?: number; + } + + interface PrecompileFunc { + (opts: PrecompileInput): ExecResult; + } + + interface PrecompileInput { + data: Buffer; + gasLimit: BN; + _common: Common; + } + + class VmError { + error: ERROR; + errorType: string; + constructor(error: ERROR); + } + + enum ERROR { + OUT_OF_GAS = 'out of gas', + STACK_UNDERFLOW = 'stack underflow', + STACK_OVERFLOW = 'stack overflow', + INVALID_JUMP = 'invalid JUMP', + INVALID_OPCODE = 'invalid opcode', + OUT_OF_RANGE = 'value out of range', + REVERT = 'revert', + STATIC_STATE_CHANGE = 'static state change', + INTERNAL_ERROR = 'internal error', + CREATE_COLLISION = 'create collision', + STOP = 'stop', + } +}