first commit
This commit is contained in:
29
test/utils/Log.ts
Normal file
29
test/utils/Log.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
import { TransactionReceipt } from "web3-core"
|
||||
|
||||
export const blueText = x => `\x1b[36m${x}\x1b[0m`;
|
||||
export const yellowText = x => `\x1b[33m${x}\x1b[0m`;
|
||||
export const greenText = x => `\x1b[32m${x}\x1b[0m`;
|
||||
export const redText = x => `\x1b[31m${x}\x1b[0m`;
|
||||
export const numberWithCommas = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
|
||||
export function logGas(receipt: TransactionReceipt, desc: string) {
|
||||
const gasUsed = receipt.gasUsed;
|
||||
let colorFn;
|
||||
|
||||
if (gasUsed < 80000) {
|
||||
colorFn = greenText;
|
||||
} else if (gasUsed < 200000) {
|
||||
colorFn = yellowText;
|
||||
} else {
|
||||
colorFn = redText;
|
||||
}
|
||||
|
||||
console.log(("Gas used:").padEnd(60, '.'), blueText(desc) + " ", colorFn(numberWithCommas(gasUsed).padStart(5)));
|
||||
}
|
||||
Reference in New Issue
Block a user