Files
dodo-contractV2/test/utils/Log.ts

32 lines
929 B
TypeScript
Raw Normal View History

2020-06-26 00:31:25 +08:00
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
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, ',');
2020-09-08 20:09:31 +08:00
export async function logGas(funcCall: any, params: any, desc: string) {
const estimatedGas = await funcCall.estimateGas(params)
2021-01-08 17:41:36 +08:00
2020-09-08 20:09:31 +08:00
const receipt = await funcCall.send(params)
2020-06-26 00:31:25 +08:00
const gasUsed = receipt.gasUsed;
let colorFn;
if (gasUsed < 80000) {
colorFn = greenText;
} else if (gasUsed < 200000) {
colorFn = yellowText;
} else {
colorFn = redText;
}
2020-09-08 20:09:31 +08:00
console.log(("Gas estimated:" + numberWithCommas(estimatedGas)).padEnd(60, '.'), blueText(desc) + " ", colorFn(numberWithCommas(gasUsed).padStart(5)));
return receipt
2021-01-08 17:41:36 +08:00
}