diff --git a/lotus-soup/compositions/composition.toml b/lotus-soup/compositions/composition.toml index 812697075..39a72d2d4 100644 --- a/lotus-soup/compositions/composition.toml +++ b/lotus-soup/compositions/composition.toml @@ -22,7 +22,7 @@ clients = "3" miners = "2" genesis_timestamp_offset = "0" - balance = "2000000000" ## be careful, this is in FIL. + balance = "20000000.5" sectors = "10" random_beacon_type = "mock" mining_mode = "natural" diff --git a/lotus-soup/manifest.toml b/lotus-soup/manifest.toml index e76b1d396..c2f1a9db9 100644 --- a/lotus-soup/manifest.toml +++ b/lotus-soup/manifest.toml @@ -35,7 +35,7 @@ instances = { min = 1, max = 100, default = 5 } [testcases.params] clients = { type = "int", default = 1 } miners = { type = "int", default = 1 } - balance = { type = "int", default = 1 } + balance = { type = "float", default = 1 } sectors = { type = "int", default = 1 } role = { type = "string" } @@ -64,7 +64,7 @@ instances = { min = 1, max = 100, default = 5 } [testcases.params] clients = { type = "int", default = 1 } miners = { type = "int", default = 1 } - balance = { type = "int", default = 1 } + balance = { type = "float", default = 1 } sectors = { type = "int", default = 1 } role = { type = "string" } genesis_timestamp_offset = { type = "int", default = 0 } @@ -94,7 +94,7 @@ instances = { min = 1, max = 100, default = 5 } [testcases.params] clients = { type = "int", default = 1 } miners = { type = "int", default = 1 } - balance = { type = "int", default = 1 } + balance = { type = "float", default = 1 } sectors = { type = "int", default = 1 } role = { type = "string" } @@ -127,7 +127,7 @@ instances = { min = 1, max = 100, default = 5 } [testcases.params] clients = { type = "int", default = 1 } miners = { type = "int", default = 1 } - balance = { type = "int", default = 1 } + balance = { type = "float", default = 1 } sectors = { type = "int", default = 1 } role = { type = "string" } genesis_timestamp_offset = { type = "int", default = 0 } diff --git a/lotus-soup/testkit/role_bootstrapper.go b/lotus-soup/testkit/role_bootstrapper.go index 3049a48ca..39d5dba58 100644 --- a/lotus-soup/testkit/role_bootstrapper.go +++ b/lotus-soup/testkit/role_bootstrapper.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + mbig "math/big" "time" "github.com/filecoin-project/lotus/build" @@ -57,11 +58,12 @@ func PrepareBootstrapper(t *TestEnvironment) (*Bootstrapper, error) { totalBalance := big.Zero() for _, b := range balances { - totalBalance = big.Add(big.NewInt(int64(b.Balance)), totalBalance) + totalBalance = big.Add(filToAttoFil(b.Balance), totalBalance) } - t.RecordMessage("TOTAL BALANCE: %s", totalBalance) - if max := types.TotalFilecoinInt; totalBalance.GreaterThanEqual(max) { + totalBalanceFil := attoFilToFil(totalBalance) + 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)) } @@ -76,7 +78,7 @@ func PrepareBootstrapper(t *TestEnvironment) (*Bootstrapper, error) { var genesisMiners []genesis.Miner for _, bm := range balances { - balance := big.Mul(big.NewInt(int64(bm.Balance)), types.NewInt(build.FilecoinPrecision)) + balance := filToAttoFil(bm.Balance) t.RecordMessage("balance assigned to actor %s: %s AttoFIL", bm.Addr, balance) genesisActors = append(genesisActors, genesis.Actor{ @@ -178,3 +180,18 @@ func (b *Bootstrapper) RunDefault() error { b.t.SyncClient.MustSignalAndWait(ctx, StateDone, b.t.TestInstanceCount) return nil } + +// filToAttoFil converts a fractional filecoin value into AttoFIL, rounding if necessary +func filToAttoFil(f float64) big.Int { + a := mbig.NewFloat(f) + a.Mul(a, mbig.NewFloat(float64(build.FilecoinPrecision))) + i, _ := a.Int(nil) + return big.Int{Int: i} +} + +func attoFilToFil(atto big.Int) big.Int { + i := big.NewInt(0) + i.Add(i.Int, atto.Int) + i.Div(i.Int, big.NewIntUnsigned(build.FilecoinPrecision).Int) + return i +} diff --git a/lotus-soup/testkit/role_client.go b/lotus-soup/testkit/role_client.go index 7c62862b3..08bb82fbb 100644 --- a/lotus-soup/testkit/role_client.go +++ b/lotus-soup/testkit/role_client.go @@ -45,7 +45,7 @@ func PrepareClient(t *TestEnvironment) (*LotusClient, error) { } // publish the account ID/balance - balance := t.IntParam("balance") + balance := t.FloatParam("balance") balanceMsg := &InitialBalanceMsg{Addr: walletKey.Address, Balance: balance} t.SyncClient.Publish(ctx, BalanceTopic, balanceMsg) diff --git a/lotus-soup/testkit/role_miner.go b/lotus-soup/testkit/role_miner.go index 86047dece..4850efedf 100644 --- a/lotus-soup/testkit/role_miner.go +++ b/lotus-soup/testkit/role_miner.go @@ -63,7 +63,7 @@ func PrepareMiner(t *TestEnvironment) (*LotusMiner, error) { } // publish the account ID/balance - balance := t.IntParam("balance") + balance := t.FloatParam("balance") balanceMsg := &InitialBalanceMsg{Addr: walletKey.Address, Balance: balance} t.SyncClient.Publish(ctx, BalanceTopic, balanceMsg) diff --git a/lotus-soup/testkit/sync.go b/lotus-soup/testkit/sync.go index f565c501d..51975ce29 100644 --- a/lotus-soup/testkit/sync.go +++ b/lotus-soup/testkit/sync.go @@ -27,7 +27,7 @@ var ( type InitialBalanceMsg struct { Addr address.Address - Balance int + Balance float64 } type PresealMsg struct {