gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renew_test.go (about)

     1  package skymodules
     2  
     3  import (
     4  	"testing"
     5  
     6  	"go.sia.tech/siad/modules"
     7  	"go.sia.tech/siad/types"
     8  )
     9  
    10  // TestRenewBaseCost is a unit test for RenewBaseCosts.
    11  func TestRenewBaseCost(t *testing.T) {
    12  	var pt modules.RPCPriceTable
    13  	pt.WriteStoreCost = types.SiacoinPrecision
    14  	pt.CollateralCost = types.SiacoinPrecision.Mul64(2)
    15  	pt.RenewContractCost = types.SiacoinPrecision
    16  	pt.WindowSize = 50
    17  
    18  	// Declare test cases.
    19  	tests := []struct {
    20  		oldWindowEnd types.BlockHeight
    21  		newEndHeight types.BlockHeight
    22  		storage      uint64
    23  
    24  		basePrice      types.Currency
    25  		baseCollateral types.Currency
    26  	}{
    27  		// No storage.
    28  		{
    29  			oldWindowEnd: 0,
    30  			newEndHeight: 10,
    31  			storage:      0,
    32  
    33  			basePrice:      types.SiacoinPrecision,
    34  			baseCollateral: types.ZeroCurrency,
    35  		},
    36  		// 1 block time extension
    37  		{
    38  			oldWindowEnd: 49,
    39  			newEndHeight: 0,
    40  			storage:      1,
    41  
    42  			basePrice:      types.SiacoinPrecision.Mul64(2),
    43  			baseCollateral: types.SiacoinPrecision.Mul64(2),
    44  		},
    45  		// 0 block time extension.
    46  		{
    47  			oldWindowEnd: 50,
    48  			newEndHeight: 0,
    49  			storage:      1,
    50  
    51  			basePrice:      types.SiacoinPrecision,
    52  			baseCollateral: types.ZeroCurrency,
    53  		},
    54  		// -1 block time extension.
    55  		{
    56  			oldWindowEnd: 51,
    57  			newEndHeight: 0,
    58  			storage:      1,
    59  
    60  			basePrice:      types.SiacoinPrecision,
    61  			baseCollateral: types.ZeroCurrency,
    62  		},
    63  		// 60 block time extension
    64  		{
    65  			oldWindowEnd: 0,
    66  			newEndHeight: 10,
    67  			storage:      1,
    68  
    69  			basePrice:      types.SiacoinPrecision.Mul64(61),
    70  			baseCollateral: types.SiacoinPrecision.Mul64(120),
    71  		},
    72  	}
    73  
    74  	// Run tests.
    75  	for i, test := range tests {
    76  		var lastRev types.FileContractRevision
    77  		lastRev.NewWindowEnd = test.oldWindowEnd
    78  		lastRev.NewFileSize = test.storage
    79  		endHeight := test.newEndHeight
    80  		basePrice, baseCollateral := RenewBaseCosts(lastRev, &pt, endHeight)
    81  
    82  		if !basePrice.Equals(test.basePrice) {
    83  			t.Fatalf("%v: expected basePrice %v but was %v", i, test.basePrice, basePrice)
    84  		}
    85  		if !baseCollateral.Equals(test.baseCollateral) {
    86  			t.Fatalf("%v: expected baseCollateral %v but was %v", i, test.baseCollateral, baseCollateral)
    87  		}
    88  	}
    89  }