Skip to content

Commit 17067d6

Browse files
committed
fix: reduce amount of buildconstant hacking in itests
1 parent 606e51a commit 17067d6

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

itests/daily_fees_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
gstStore "github.com/filecoin-project/go-state-types/store"
2222

2323
"github.com/filecoin-project/lotus/blockstore"
24+
"github.com/filecoin-project/lotus/build/buildconstants"
2425
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
2526
"github.com/filecoin-project/lotus/chain/consensus/filcns"
2627
"github.com/filecoin-project/lotus/chain/state"
@@ -44,6 +45,15 @@ func TestDailyFees(t *testing.T) {
4445
nv26epoch abi.ChainEpoch = nv25epoch + builtin.EpochsInDay/2 // Tock
4546
feePostWg sync.WaitGroup
4647
)
48+
// itests start off with a FilReserved of 300M FIL, leading to a circulating supply of 0 initially,
49+
// but we'll also simulate the calibnet bump of the InitialFilReserved to get the circulating
50+
// supply calculation up to ~700M FIL. It has ~300M in it, we need to pretend 700M has been used,
51+
// so 1B - 300M = 700M.
52+
originalUpgradeTeepInitialFilReserved := buildconstants.UpgradeTeepInitialFilReserved
53+
buildconstants.UpgradeTeepInitialFilReserved = types.MustParseFIL("1000000000 FIL").Int
54+
t.Cleanup(func() {
55+
buildconstants.UpgradeTeepInitialFilReserved = originalUpgradeTeepInitialFilReserved
56+
})
4757

4858
type sectorInfo struct {
4959
sn abi.SectorNumber

itests/fevm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func TestFEVMTestSendToContract(t *testing.T) {
427427
_, _, err = client.EVM().InvokeContractByFuncName(ctx, fromAddr, contractAddr, "destroy()", []byte{})
428428
require.NoError(t, err)
429429

430-
finalBalanceMinimum := types.FromFil(uint64(99_999_999)) // 100 million FIL - 1 FIL for gas upper bounds
430+
finalBalanceMinimum := types.FromFil(uint64(9_999_999)) // 10 million FIL - 1 FIL for gas upper bounds
431431
finalBal, err := client.WalletBalance(ctx, client.DefaultKey.Address)
432432
require.NoError(t, err)
433433
require.Equal(t, true, finalBal.GreaterThan(finalBalanceMinimum))

itests/kit/ensemble.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
"github.com/filecoin-project/lotus/cmd/lotus-worker/sealworker"
5555
"github.com/filecoin-project/lotus/gateway"
5656
"github.com/filecoin-project/lotus/genesis"
57+
"github.com/filecoin-project/lotus/lib/must"
5758
lotusminer "github.com/filecoin-project/lotus/miner"
5859
"github.com/filecoin-project/lotus/node"
5960
"github.com/filecoin-project/lotus/node/config"
@@ -158,14 +159,23 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble {
158159
}
159160
}
160161

162+
usedBalance := big.Zero()
161163
// add accounts from ensemble options to genesis.
162164
for _, acc := range options.accounts {
163165
n.genesis.accounts = append(n.genesis.accounts, genesis.Actor{
164166
Type: genesis.TAccount,
165167
Balance: acc.initialBalance,
166168
Meta: (&genesis.AccountMeta{Owner: acc.key.Address}).ActorMeta(),
167169
})
170+
usedBalance = big.Add(usedBalance, acc.initialBalance)
168171
}
172+
// Soak up some balance from FilBase so that we leave FilReserved at 300M to match mainnet.
173+
// See https://github.com/filecoin-project/lotus/pull/12932 for context on this.
174+
n.genesis.accounts = append(n.genesis.accounts, genesis.Actor{
175+
Type: genesis.TAccount,
176+
Balance: big.Sub(big.Int(types.MustParseFIL("400000000 FIL")), usedBalance),
177+
Meta: (&genesis.AccountMeta{Owner: must.One(key.GenerateKey(types.KTSecp256k1)).Address}).ActorMeta(),
178+
})
169179

170180
// Ensure we're using the right actors. This really shouldn't be some global thing, but it's
171181
// the best we can do for now.
@@ -176,15 +186,7 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble {
176186
}
177187

178188
buildconstants.EquivocationDelaySecs = 0
179-
180-
// See FIP-0100; we manually set these to the 2k network settings for itests not run with -tags 2k
181189
buildconstants.UpgradeAssemblyHeight = -1 // so GetVMCirculatingSupplyDetailed() properly calculates FilReserved
182-
// 700M FIL is the correct value for test networks, with UpgradeAssemblyHeight in the past, this
183-
// value is used in supply.go to calculate the mining reserve in circulation which is added to
184-
// circulating supply.
185-
buildconstants.InitialFilReserved = types.MustParseFIL("700000000 FIL").Int
186-
// Bump it at Teep upgrade to simulate FIP-0100 and get CS close to ~700M FIL like in mainnet.
187-
buildconstants.UpgradeTeepInitialFilReserved = types.MustParseFIL("1400000000 FIL").Int
188190

189191
return n
190192
}

itests/kit/evm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ func SetupFEVMTest(t *testing.T, opts ...interface{}) (context.Context, context.
425425
ens.InterconnectAll().BeginMining(blockTime)
426426
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
427427

428-
// require that the initial balance is 100 million FIL in setup
428+
// require that the initial balance is 10 million FIL in setup
429429
// this way other tests can count on this initial wallet balance
430430
fromAddr := client.DefaultKey.Address
431431
bal, err := client.WalletBalance(ctx, fromAddr)
432432
require.NoError(t, err)
433-
originalBalance := types.FromFil(uint64(100_000_000)) // 100 million FIL
433+
originalBalance := types.FromFil(uint64(10_000_000)) // 10 million FIL
434434
require.Equal(t, originalBalance, bal)
435435

436436
return ctx, cancel, client

itests/kit/node_opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var _ connmgr.ConnectionGater = (*loopbackConnGater)(nil)
8181

8282
// DefaultNodeOpts are the default options that will be applied to test nodes.
8383
var DefaultNodeOpts = nodeOpts{
84-
balance: big.Mul(big.NewInt(100000000), types.NewInt(buildconstants.FilecoinPrecision)),
84+
balance: big.Mul(big.NewInt(10_000_000), types.NewInt(buildconstants.FilecoinPrecision)),
8585
sectors: DefaultPresealsPerBootstrapMiner,
8686
sectorSize: abi.SectorSize(2 << 10), // 2KiB.
8787

itests/migration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,10 @@ func TestMigrationNV24(t *testing.T) {
909909
)
910910
buildconstants.UpgradeTuktukPowerRampDurationEpochs = powerRampDurationEpochs
911911
buildconstants.UpgradeTuktukHeight = nv24epoch
912+
// Pretend that the reserve account started with 1B FIL, so that when calculating the
913+
// circulating supply we find that the reserve account only has ~300M FIL so there must be ~700M
914+
// FIL in circulation, which is close to current mainnet supply.
915+
buildconstants.InitialFilReserved = types.MustParseFIL("1000000000 FIL").Int
912916

913917
// InitialPledgeMaxPerByte is a little too low for an itest environment so gets in the way of
914918
// testing the underlying calculation, so we bump it up here so it doesn't interfere.

itests/supply_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestCirciulationSupplyUpgrade(t *testing.T) {
2828
ctx := context.Background()
2929

3030
// Choosing something divisible by epochs per day to remove error with simple deal duration
31-
lockedClientBalance := big.Mul(abi.NewTokenAmount(11_520_000), abi.NewTokenAmount(1e18))
31+
lockedClientBalance := big.Mul(abi.NewTokenAmount(8_640_000), abi.NewTokenAmount(1e18))
3232
lockedProviderBalance := big.Mul(abi.NewTokenAmount(1_000_000), abi.NewTokenAmount(1e18))
3333
var height0 abi.ChainEpoch
3434
var height1 abi.ChainEpoch

0 commit comments

Comments
 (0)