Skip to content

Commit dd9e455

Browse files
add test
1 parent 0323065 commit dd9e455

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

internal/test/e2e/cluster_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,3 +3256,50 @@ func TestDefaultSettingsUploadDownload(t *testing.T) {
32563256
t.Fatal("expected access denied error")
32573257
}
32583258
}
3259+
3260+
func TestContractFormationAndRenewalV2EndHeightCap(t *testing.T) {
3261+
// custom network that starts before the v2 allow height with only 10 blocks
3262+
// between the allow and require height
3263+
network, genesis := testNetwork()
3264+
network.HardforkV2.AllowHeight = 50
3265+
network.HardforkV2.RequireHeight = 60 // 100 blocks after the allow height
3266+
store, state, err := chain.NewDBStore(chain.NewMemDB(), network, genesis, nil)
3267+
if err != nil {
3268+
t.Fatal(err)
3269+
}
3270+
cm := chain.NewManager(store, state)
3271+
3272+
cfg := clusterOptsDefault
3273+
cfg.autopilotConfig = &api.DefaultAutopilotConfig
3274+
cfg.cm = cm
3275+
cfg.hosts = 1
3276+
3277+
// make sure the period is greater then the require height to trigger the
3278+
// cap
3279+
if cfg.autopilotConfig.Contracts.Period < network.HardforkV2.RequireHeight {
3280+
t.Fatal("autopilot config period should be greater than the require height for this test")
3281+
}
3282+
3283+
cluster := newTestCluster(t, cfg)
3284+
defer cluster.Shutdown()
3285+
3286+
// add a host & wait for contracts to form
3287+
contracts := cluster.WaitForContracts()
3288+
if len(contracts) != 1 {
3289+
t.Fatal("expected 1 contract, got", len(contracts))
3290+
}
3291+
contract := contracts[0]
3292+
3293+
// verify startHeight and endHeight of the contract.
3294+
if contract.EndHeight() != network.HardforkV2.RequireHeight-1 {
3295+
t.Fatalf("expected contract end height to be %v, got %v", network.HardforkV2.RequireHeight-1, contract.EndHeight())
3296+
}
3297+
3298+
// manually trigger a renewal
3299+
renewed, err := cluster.Bus.RenewContract(context.Background(), contract.ID, 200, contract.InitialRenterFunds, types.ZeroCurrency, 1000)
3300+
if err != nil {
3301+
t.Fatal(err)
3302+
} else if renewed.EndHeight() != network.HardforkV2.RequireHeight-1 {
3303+
t.Fatalf("expected renewed contract to have end height %v, got %v", network.HardforkV2.RequireHeight-1, renewed.EndHeight())
3304+
}
3305+
}

0 commit comments

Comments
 (0)