github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/test/common_test.go (about)

     1  package test_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	addr "github.com/filecoin-project/go-address"
     7  	"github.com/filecoin-project/go-state-types/abi"
     8  	"github.com/filecoin-project/go-state-types/big"
     9  	"github.com/filecoin-project/go-state-types/crypto"
    10  	"github.com/filecoin-project/go-state-types/exitcode"
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"github.com/filecoin-project/specs-actors/v4/actors/builtin"
    14  	"github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
    15  	tutil "github.com/filecoin-project/specs-actors/v4/support/testing"
    16  	vm "github.com/filecoin-project/specs-actors/v4/support/vm"
    17  )
    18  
    19  func publishDeal(t *testing.T, v *vm.VM, provider, dealClient, minerID addr.Address, dealLabel string,
    20  	pieceSize abi.PaddedPieceSize, verifiedDeal bool, dealStart abi.ChainEpoch, dealLifetime abi.ChainEpoch,
    21  ) *market.PublishStorageDealsReturn {
    22  	deal := market.DealProposal{
    23  		PieceCID:             tutil.MakeCID(dealLabel, &market.PieceCIDPrefix),
    24  		PieceSize:            pieceSize,
    25  		VerifiedDeal:         verifiedDeal,
    26  		Client:               dealClient,
    27  		Provider:             minerID,
    28  		Label:                dealLabel,
    29  		StartEpoch:           dealStart,
    30  		EndEpoch:             dealStart + dealLifetime,
    31  		StoragePricePerEpoch: abi.NewTokenAmount(1 << 20),
    32  		ProviderCollateral:   big.Mul(big.NewInt(2), vm.FIL),
    33  		ClientCollateral:     big.Mul(big.NewInt(1), vm.FIL),
    34  	}
    35  
    36  	publishDealParams := market.PublishStorageDealsParams{
    37  		Deals: []market.ClientDealProposal{{
    38  			Proposal:        deal,
    39  			ClientSignature: crypto.Signature{},
    40  		}},
    41  	}
    42  	ret, code := v.ApplyMessage(provider, builtin.StorageMarketActorAddr, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, &publishDealParams)
    43  	require.Equal(t, exitcode.Ok, code)
    44  
    45  	expectedPublishSubinvocations := []vm.ExpectInvocation{
    46  		{To: minerID, Method: builtin.MethodsMiner.ControlAddresses, SubInvocations: []vm.ExpectInvocation{}},
    47  		{To: builtin.RewardActorAddr, Method: builtin.MethodsReward.ThisEpochReward, SubInvocations: []vm.ExpectInvocation{}},
    48  		{To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.CurrentTotalPower, SubInvocations: []vm.ExpectInvocation{}},
    49  	}
    50  
    51  	if verifiedDeal {
    52  		expectedPublishSubinvocations = append(expectedPublishSubinvocations, vm.ExpectInvocation{
    53  			To:             builtin.VerifiedRegistryActorAddr,
    54  			Method:         builtin.MethodsVerifiedRegistry.UseBytes,
    55  			SubInvocations: []vm.ExpectInvocation{},
    56  		})
    57  	}
    58  
    59  	vm.ExpectInvocation{
    60  		To:             builtin.StorageMarketActorAddr,
    61  		Method:         builtin.MethodsMarket.PublishStorageDeals,
    62  		SubInvocations: expectedPublishSubinvocations,
    63  	}.Matches(t, v.LastInvocation())
    64  
    65  	return ret.(*market.PublishStorageDealsReturn)
    66  }