fix max fil check

This commit is contained in:
Yusef Napora 2020-07-07 17:15:12 -04:00
parent 735c1ecc2a
commit 4926a788c1

View File

@ -61,8 +61,9 @@ func PrepareBootstrapper(t *TestEnvironment) (*Bootstrapper, error) {
totalBalance = big.Add(attoFil(b.Balance), totalBalance) totalBalance = big.Add(attoFil(b.Balance), totalBalance)
} }
t.RecordMessage("TOTAL BALANCE: %s AttoFIL (%f FIL)", totalBalance, fractionalFil(totalBalance)) totalBalanceFil := attoFilToFil(totalBalance)
if max := types.TotalFilecoinInt; totalBalance.GreaterThanEqual(max) { t.RecordMessage("TOTAL BALANCE: %s AttoFIL (%s FIL)", totalBalance, totalBalanceFil)
if max := types.TotalFilecoinInt; totalBalanceFil.GreaterThanEqual(max) {
panic(fmt.Sprintf("total sum of balances is greater than max Filecoin ever; sum=%s, max=%s", totalBalance, max)) panic(fmt.Sprintf("total sum of balances is greater than max Filecoin ever; sum=%s, max=%s", totalBalance, max))
} }
@ -188,12 +189,9 @@ func attoFil(f float64) big.Int {
return big.Int{Int: i} return big.Int{Int: i}
} }
// fractionalFil converts from AttoFIL to a fractional Fil value func attoFilToFil(atto big.Int) big.Int {
// possibly losing some precision due to floating point gremlins i := big.NewInt(0)
func fractionalFil(atto big.Int) float64 { i.Add(i.Int, atto.Int)
f := mbig.NewFloat(0) i.Div(i.Int, big.NewIntUnsigned(build.FilecoinPrecision).Int)
f.SetInt(atto.Int) return i
f.Quo(f, mbig.NewFloat(float64(build.FilecoinPrecision)))
val, _ := f.Float64()
return val
} }