gitlab.com/SiaPrime/SiaPrime@v1.4.1/modules/host/storageobligations_test.go (about)

     1  package host
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gitlab.com/SiaPrime/SiaPrime/types"
     7  )
     8  
     9  // TestStorageObligationID checks that the return function of the storage
    10  // obligation returns the correct value for the obligaiton id.
    11  func TestStorageObligationID(t *testing.T) {
    12  	t.Parallel()
    13  	// Try a transaction set with just a file contract.
    14  	so1 := &storageObligation{
    15  		OriginTransactionSet: []types.Transaction{{
    16  			FileContracts: []types.FileContract{{
    17  				ValidProofOutputs: []types.SiacoinOutput{
    18  					{
    19  						UnlockHash: types.UnlockHash{2, 1, 3},
    20  						Value:      types.NewCurrency64(35),
    21  					},
    22  					{
    23  						UnlockHash: types.UnlockHash{0, 1, 3},
    24  						Value:      types.NewCurrency64(25),
    25  					},
    26  				},
    27  				MissedProofOutputs: []types.SiacoinOutput{
    28  					{
    29  						UnlockHash: types.UnlockHash{110, 1, 3},
    30  						Value:      types.NewCurrency64(3325),
    31  					},
    32  					{
    33  						UnlockHash: types.UnlockHash{110, 1, 3},
    34  						Value:      types.NewCurrency64(8325),
    35  					},
    36  				},
    37  			}},
    38  		}},
    39  	}
    40  	if so1.id() != so1.OriginTransactionSet[0].FileContractID(0) {
    41  		t.Error("id function of storage obligation is not correct")
    42  	}
    43  
    44  	// Try a file contract that includes file contract dependencies.
    45  	so2 := &storageObligation{
    46  		OriginTransactionSet: []types.Transaction{
    47  			{
    48  				SiacoinOutputs: []types.SiacoinOutput{{
    49  					UnlockHash: types.UnlockHash{1, 3, 2},
    50  					Value:      types.NewCurrency64(5),
    51  				}},
    52  			},
    53  			{
    54  				FileContracts: []types.FileContract{{
    55  					ValidProofOutputs: []types.SiacoinOutput{
    56  						{
    57  							UnlockHash: types.UnlockHash{8, 11, 4},
    58  							Value:      types.NewCurrency64(85),
    59  						},
    60  						{
    61  							UnlockHash: types.UnlockHash{8, 11, 14},
    62  							Value:      types.NewCurrency64(859),
    63  						},
    64  					},
    65  					MissedProofOutputs: []types.SiacoinOutput{
    66  						{
    67  							UnlockHash: types.UnlockHash{8, 113, 4},
    68  							Value:      types.NewCurrency64(853),
    69  						},
    70  						{
    71  							UnlockHash: types.UnlockHash{8, 119, 14},
    72  							Value:      types.NewCurrency64(9859),
    73  						},
    74  					},
    75  				}},
    76  			},
    77  		},
    78  	}
    79  	if so2.id() != so2.OriginTransactionSet[1].FileContractID(0) {
    80  		t.Error("id function of storage obligation incorrect for file contracts with dependencies")
    81  	}
    82  }