-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestUtils.js
48 lines (40 loc) · 1.04 KB
/
testUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: MIT
/*
* Copyright ©2023 by Poption.
* Author: Hydrogenbear <[email protected]>
*/
const Decimal = require("decimal.js");
const _ = require("lodash");
const { BigNumber } = require("ethers");
const BigFloat = Decimal.clone({
precision: 150,
toExpNeg: -150,
toExpPos: 150,
});
const BF = (x) => new BigFloat(x);
const TWO_F_128 = new BigFloat("340282366920938463463374607431768211456");
const TWO_F_64 = new BigFloat("18446744073709551616");
const TWO_I_128 = BigNumber.from("340282366920938463463374607431768211456");
const TWO_I_64 = BigNumber.from("18446744073709551616");
const toDec = (x) => BF(x.toString()).div(TWO_F_64);
const toInt = (x) => BF(x).mul(TWO_F_64).toFixed(0);
const readGas = async (trx) => {
const receipt = await trx.wait();
console.log(`gas: ${receipt.gasUsed}`);
};
const estGas = async (trx) => {
const gas = await trx;
console.log(`gas: ${gas}`);
};
module.exports = {
BigFloat,
BF,
TWO_I_64,
TWO_I_128,
TWO_F_64,
TWO_F_128,
toDec,
toInt,
readGas,
estGas,
};