How to use the @0x/utils.logUtils.warn function in @0x/utils

To help you get started, we’ve selected a few @0x/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / contracts / test-utils / src / assertions.ts View on Github external
// remove it, there is an uncaught exception and the Node process will
    // forcibly exit. It's possible this is a false positive in
    // make-promises-safe.
    p.catch(e => {
        _.noop(e);
    });

    if (nodeType === undefined) {
        nodeType = await web3Wrapper.getNodeTypeAsync();
    }
    switch (nodeType) {
        case NodeType.Ganache:
            const rejectionMessageRegex = new RegExp(`^VM Exception while processing transaction: revert ${reason}$`);
            return expect(p).to.be.rejectedWith(rejectionMessageRegex);
        case NodeType.Geth:
            logUtils.warn(
                'WARNING: Geth does not support revert reasons for sendTransaction. This test will pass if the transaction fails for any reason.',
            );
            return expectTransactionFailedWithoutReasonAsync(p);
        default:
            throw new Error(`Unknown node type: ${nodeType}`);
    }
}
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
// add input to the right version batch
            for (const resolvedContractSource of spyResolver.resolvedContractSources) {
                versionToInputs[solcVersion].standardInput.sources[resolvedContractSource.absolutePath] = {
                    content: resolvedContractSource.source,
                };
            }
            resolvedContractSources.push(...spyResolver.resolvedContractSources);
            versionToInputs[solcVersion].contractsToCompile.push(contractSource.path);
        }

        const dependencyNameToPath = getDependencyNameToPackagePath(resolvedContractSources);

        const compilerOutputs: StandardOutput[] = [];
        for (const solcVersion of _.keys(versionToInputs)) {
            const input = versionToInputs[solcVersion];
            logUtils.warn(
                `Compiling ${input.contractsToCompile.length} contracts (${
                    input.contractsToCompile
                }) with Solidity v${solcVersion}...`,
            );
            let compilerOutput;
            let fullSolcVersion;
            input.standardInput.settings.remappings = _.map(
                dependencyNameToPath,
                (dependencyPackagePath: string, dependencyName: string) => `${dependencyName}=${dependencyPackagePath}`,
            );
            if (this._useDockerisedSolc) {
                const dockerCommand = `docker run ethereum/solc:${solcVersion} --version`;
                const versionCommandOutput = execSync(dockerCommand).toString();
                const versionCommandOutputParts = versionCommandOutput.split(' ');
                fullSolcVersion = versionCommandOutputParts[versionCommandOutputParts.length - 1].trim();
                compilerOutput = await compileDockerAsync(solcVersion, input.standardInput);
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / event_watcher.ts View on Github external
private _onBlockAndLogStreamerError(err: Error): void {
        // Since Blockstream errors are all recoverable, we simply log them if the verbose
        // config is passed in.
        if (this._isVerbose) {
            logUtils.warn(err);
        }
    }
}
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / trace.ts View on Github external
);
                currentTraceSegment = [];
            }
        } else if (utils.isEndOpcode(structLog.op)) {
            const currentAddress = addressStack.pop() as string;
            contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
                currentTraceSegment,
            );
            currentTraceSegment = [];
            if (structLog.op === OpCode.SelfDestruct) {
                // After contract execution, we look at all sub-calls to external contracts, and for each one, fetch
                // the bytecode and compute the coverage for the call. If the contract is destroyed with a call
                // to `selfdestruct`, we are unable to fetch it's bytecode and compute coverage.
                // TODO: Refactor this logic to fetch the sub-called contract bytecode before the selfdestruct is called
                // in order to handle this edge-case.
                logUtils.warn(
                    "Detected a selfdestruct. We currently do not support that scenario. We'll just skip the trace part for a destructed contract",
                );
            }
        } else if (structLog.op === OpCode.Create) {
            // TODO: Extract the new contract address from the stack and handle that scenario
            logUtils.warn(
                "Detected a contract created from within another contract. We currently do not support that scenario. We'll just skip that trace",
            );
            return contractAddressToTraces;
        } else {
            if (structLog !== _.last(normalizedStructLogs)) {
                const nextStructLog = normalizedStructLogs[i + 1];
                if (nextStructLog.depth === structLog.depth) {
                    continue;
                } else if (nextStructLog.depth === structLog.depth - 1) {
                    const currentAddress = addressStack.pop() as string;
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / trace.ts View on Github external
if (nextStructLog.depth === structLog.depth) {
                    continue;
                } else if (nextStructLog.depth === structLog.depth - 1) {
                    const currentAddress = addressStack.pop() as string;
                    contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
                        currentTraceSegment,
                    );
                    currentTraceSegment = [];
                } else {
                    throw new Error('Malformed trace. Unexpected call depth change');
                }
            }
        }
    }
    if (addressStack.length !== 0) {
        logUtils.warn('Malformed trace. Call stack non empty at the end');
    }
    if (currentTraceSegment.length !== 0) {
        const currentAddress = addressStack.pop() as string;
        contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
            currentTraceSegment,
        );
        currentTraceSegment = [];
        logUtils.warn('Malformed trace. Current trace segment non empty at the end');
    }
    return contractAddressToTraces;
}
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / artifact_adapters / sol_compiler_artifact_adapter.ts View on Github external
public async collectContractsDataAsync(): Promise {
        const artifactsGlob = `${this._artifactsPath}/**/*.json`;
        const artifactFileNames = glob.sync(artifactsGlob, { absolute: true });
        const contractsData: ContractData[] = [];
        for (const artifactFileName of artifactFileNames) {
            const artifact: ContractArtifact = JSON.parse(fs.readFileSync(artifactFileName).toString());
            if (_.isUndefined(artifact.compilerOutput.evm)) {
                logUtils.warn(`${artifactFileName} doesn't contain bytecode. Skipping...`);
                continue;
            }
            const sources: Sources = {};
            const sourceCodes: SourceCodes = {};
            _.map(artifact.sources, (value: { id: number }, relativeFilePath: string) => {
                const source = this._resolver.resolve(relativeFilePath);
                sources[value.id] = source.absolutePath;
                sourceCodes[value.id] = source.source;
            });
            const contractData = {
                sourceCodes,
                sources,
                bytecode: artifact.compilerOutput.evm.bytecode.object,
                sourceMap: artifact.compilerOutput.evm.bytecode.sourceMap,
                runtimeBytecode: artifact.compilerOutput.evm.deployedBytecode.object,
                sourceMapRuntime: artifact.compilerOutput.evm.deployedBytecode.sourceMap,
github 0xProject / 0x-monorepo / packages / pipeline / src / scripts / pull_idex_orderbook_snapshots.ts View on Github external
async function getAndSaveMarketOrderbookAsync(idexSource: IdexSource, marketId: string): Promise {
    logUtils.log(`${marketId}: Retrieving orderbook.`);
    const orderBook = await idexSource.getMarketOrderbookAsync(marketId);
    const observedTimestamp = Date.now();

    if (!R.has('bids', orderBook) || !R.has('asks', orderBook)) {
        logUtils.warn(`${marketId}: Orderbook faulty.`);
        return;
    }

    logUtils.log(`${marketId}: Parsing orders.`);
    const orders = parseIdexOrders(orderBook, observedTimestamp);

    if (orders.length > 0) {
        logUtils.log(`${marketId}: Saving ${orders.length} orders.`);
        const TokenOrderRepository = connection.getRepository(TokenOrder);
        await TokenOrderRepository.save(orders, { chunk: Math.ceil(orders.length / BATCH_SAVE_SIZE) });
    } else {
        logUtils.log(`${marketId}: 0 orders to save.`);
    }
}
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
...currentArtifact,
                ...contractVersion,
            };
        } else {
            newArtifact = {
                schemaVersion: constants.LATEST_ARTIFACT_VERSION,
                contractName,
                ...contractVersion,
                chains: {},
            };
        }

        const artifactString = utils.stringifyWithFormatting(newArtifact);
        const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`;
        await fsWrapper.writeFileAsync(currentArtifactPath, artifactString);
        logUtils.warn(`${contractName} artifact saved!`);
    }
}
github 0xProject / 0x-monorepo / packages / sol-compiler / src / utils / compiler.ts View on Github external
export async function getSolcJSAsync(solcVersion: string, isOfflineMode: boolean): Promise {
    const solcJSReleases = await getSolcJSReleasesAsync(isOfflineMode);
    const fullSolcVersion = solcJSReleases[solcVersion];
    if (fullSolcVersion === undefined) {
        throw new Error(`${solcVersion} is not a known compiler version`);
    }
    const compilerBinFilename = path.join(constants.SOLC_BIN_DIR, fullSolcVersion);
    let solcjs: string;
    if (await fsWrapper.doesFileExistAsync(compilerBinFilename)) {
        solcjs = (await fsWrapper.readFileAsync(compilerBinFilename)).toString();
    } else {
        logUtils.warn(`Downloading ${fullSolcVersion}...`);
        const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`;
        const response = await fetchAsync(url);
        const SUCCESS_STATUS = 200;
        if (response.status !== SUCCESS_STATUS) {
            throw new Error(`Failed to load ${fullSolcVersion}`);
        }
        solcjs = await response.text();
        await fsWrapper.writeFileAsync(compilerBinFilename, solcjs);
    }
    if (solcjs.length === 0) {
        throw new Error('No compiler available');
    }
    const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename));
    return solcInstance;
}
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / revert_trace.ts View on Github external
return [];
        } else {
            if (structLog !== _.last(normalizedStructLogs)) {
                const nextStructLog = normalizedStructLogs[i + 1];
                if (nextStructLog.depth === structLog.depth) {
                    continue;
                } else if (nextStructLog.depth === structLog.depth - 1) {
                    addressStack.pop();
                } else {
                    throw new Error('Malformed trace. Unexpected call depth change');
                }
            }
        }
    }
    if (evmCallStack.length !== 0) {
        logUtils.warn('Malformed trace. Call stack non empty at the end. (probably out of gas)');
    }
    return [];
}