Migrate math tests to ethers.js v6 (#4769)

Co-authored-by: Ernesto García <ernestognw@gmail.com>
This commit is contained in:
Hadrien Croubois
2023-12-04 20:00:00 +01:00
committed by GitHub
parent ef699fa6a2
commit cffb2f1ddc
9 changed files with 366 additions and 441 deletions

View File

@ -1,12 +1,13 @@
// Array of number or bigint
const max = (...values) => values.slice(1).reduce((x, y) => (x > y ? x : y), values.at(0));
const min = (...values) => values.slice(1).reduce((x, y) => (x < y ? x : y), values.at(0));
const sum = (...values) => values.slice(1).reduce((x, y) => x + y, values.at(0));
module.exports = {
// sum of integer / bignumber
sum: (...args) => args.reduce((acc, n) => acc + n, 0),
bigintSum: (...args) => args.reduce((acc, n) => acc + n, 0n),
BNsum: (...args) => args.reduce((acc, n) => acc.add(n), web3.utils.toBN(0)),
// min of integer / bignumber
min: (...args) => args.slice(1).reduce((x, y) => (x < y ? x : y), args[0]),
BNmin: (...args) => args.slice(1).reduce((x, y) => (x.lt(y) ? x : y), args[0]),
// max of integer / bignumber
max: (...args) => args.slice(1).reduce((x, y) => (x > y ? x : y), args[0]),
BNmax: (...args) => args.slice(1).reduce((x, y) => (x.gt(y) ? x : y), args[0]),
// re-export min, max & sum of integer / bignumber
min,
max,
sum,
// deprecated: BN version of sum
BNsum: (...args) => args.slice(1).reduce((x, y) => x.add(y), args.at(0)),
};