From 6a3bb184b7eedf8acee8c090c3bb50b7ac9cd229 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Fri, 8 Oct 2021 12:44:20 +0200 Subject: [PATCH] more tests for deals when provider has no funds in control addr --- itests/deals_retry_deal_no_funds_test.go | 151 ++++++++++++++++++++++- 1 file changed, 147 insertions(+), 4 deletions(-) diff --git a/itests/deals_retry_deal_no_funds_test.go b/itests/deals_retry_deal_no_funds_test.go index 839359c2f..3bb95d148 100644 --- a/itests/deals_retry_deal_no_funds_test.go +++ b/itests/deals_retry_deal_no_funds_test.go @@ -59,10 +59,8 @@ func TestDealsRetryLackOfFunds(t *testing.T) { })), ) - minerFullNode, clientFullNode, miner, ens := kit.EnsembleTwoOne(t, kit.Account(publishStorageDealKey, types.NewInt(1020000000000)), kit.ConstructorOpts(opts), kit.MockProofs(), eightMBSectorsOpt) - - //TODO: this fails slightly differently - handle this case as well - //minerFullNode, clientFullNode, miner, ens := kit.EnsembleTwoOne(t, kit.Account(publishStorageDealKey, types.NewInt(1)), kit.ConstructorOpts(opts), kit.MockProofs(), eightMBSectorsOpt) + publishStorageAccountFunds := types.NewInt(1020000000000) + minerFullNode, clientFullNode, miner, ens := kit.EnsembleTwoOne(t, kit.Account(publishStorageDealKey, publishStorageAccountFunds), kit.ConstructorOpts(opts), kit.MockProofs(), eightMBSectorsOpt) kit.QuietMiningLogs() @@ -105,3 +103,148 @@ func TestDealsRetryLackOfFunds(t *testing.T) { dh.WaitDealSealed(ctx, deal, false, false, nil) } + +func TestDealsRetryLackOfFunds_blockInPublishDeal(t *testing.T) { + ctx := context.Background() + oldDelay := policy.GetPreCommitChallengeDelay() + policy.SetPreCommitChallengeDelay(5) + + t.Cleanup(func() { + policy.SetPreCommitChallengeDelay(oldDelay) + }) + + policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) + kit.QuietMiningLogs() + + // Allow 8MB sectors + eightMBSectorsOpt := kit.SectorSize(8 << 20) + + publishStorageDealKey, err := wallet.GenerateKey(types.KTSecp256k1) + require.NoError(t, err) + + opts := node.Options( + node.Override(new(*storageadapter.DealPublisher), + storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{ + Period: publishPeriod, + MaxDealsPerMsg: maxDealsPerMsg, + }), + ), + node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ + DealPublishControl: []string{ + publishStorageDealKey.Address.String(), + }, + DisableOwnerFallback: true, + DisableWorkerFallback: true, + })), + ) + + publishStorageAccountFunds := types.NewInt(1020000000000) + minerFullNode, clientFullNode, miner, ens := kit.EnsembleTwoOne(t, kit.Account(publishStorageDealKey, publishStorageAccountFunds), kit.ConstructorOpts(opts), kit.MockProofs(), eightMBSectorsOpt) + + kit.QuietMiningLogs() + + ens. + Start(). + InterconnectAll(). + BeginMining(blockTime) + + _, err = minerFullNode.WalletImport(ctx, &publishStorageDealKey.KeyInfo) + require.NoError(t, err) + + miner.SetControlAddresses(publishStorageDealKey.Address) + + dh := kit.NewDealHarness(t, clientFullNode, miner, miner) + + res, _ := clientFullNode.CreateImportFile(ctx, 0, 4<<20) // 4MiB file. + list, err := clientFullNode.ClientListImports(ctx) + require.NoError(t, err) + require.Len(t, list, 1) + require.Equal(t, res.Root, *list[0].Root) + + dp := dh.DefaultStartDealParams() + dp.Data.Root = res.Root + dp.FastRetrieval = true + dp.EpochPrice = abi.NewTokenAmount(62500000) // minimum asking price. + deal := dh.StartDeal(ctx, dp) + + dealSealed := make(chan struct{}) + go func() { + dh.WaitDealSealed(ctx, deal, false, false, nil) + dealSealed <- struct{}{} + }() + + select { + case <-dealSealed: + t.Fatal("deal shouldn't have sealed") + case <-time.After(time.Second * 15): + } +} + +func TestDealsRetryLackOfFunds_belowLimit(t *testing.T) { + ctx := context.Background() + oldDelay := policy.GetPreCommitChallengeDelay() + policy.SetPreCommitChallengeDelay(5) + + t.Cleanup(func() { + policy.SetPreCommitChallengeDelay(oldDelay) + }) + + policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) + kit.QuietMiningLogs() + + // Allow 8MB sectors + eightMBSectorsOpt := kit.SectorSize(8 << 20) + + publishStorageDealKey, err := wallet.GenerateKey(types.KTSecp256k1) + require.NoError(t, err) + + opts := node.Options( + node.Override(new(*storageadapter.DealPublisher), + storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{ + Period: publishPeriod, + MaxDealsPerMsg: maxDealsPerMsg, + }), + ), + node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ + DealPublishControl: []string{ + publishStorageDealKey.Address.String(), + }, + DisableOwnerFallback: true, + DisableWorkerFallback: true, + })), + ) + + publishStorageAccountFunds := types.NewInt(1) + minerFullNode, clientFullNode, miner, ens := kit.EnsembleTwoOne(t, kit.Account(publishStorageDealKey, publishStorageAccountFunds), kit.ConstructorOpts(opts), kit.MockProofs(), eightMBSectorsOpt) + + kit.QuietMiningLogs() + + ens. + Start(). + InterconnectAll(). + BeginMining(blockTime) + + _, err = minerFullNode.WalletImport(ctx, &publishStorageDealKey.KeyInfo) + require.NoError(t, err) + + miner.SetControlAddresses(publishStorageDealKey.Address) + + dh := kit.NewDealHarness(t, clientFullNode, miner, miner) + + res, _ := clientFullNode.CreateImportFile(ctx, 0, 4<<20) // 4MiB file. + list, err := clientFullNode.ClientListImports(ctx) + require.NoError(t, err) + require.Len(t, list, 1) + require.Equal(t, res.Root, *list[0].Root) + + dp := dh.DefaultStartDealParams() + dp.Data.Root = res.Root + dp.FastRetrieval = true + dp.EpochPrice = abi.NewTokenAmount(62500000) // minimum asking price. + deal := dh.StartDeal(ctx, dp) + + err = dh.ExpectDealFailure(ctx, deal, "actor balance less than needed") + if err != nil { + t.Fatal(err) + } +}