Skip to content

Commit

Permalink
rhp4: add cases for capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger authored and ChrisSchinnerl committed Dec 12, 2024
1 parent 23e9cde commit 5dc3661
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions rhp/v4/rhp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func TestRenewalCost(t *testing.T) {
RenterCost: prices.ContractPrice.Add(prices.StoragePrice.Mul64(SectorSize).Mul64(extension)), // storage cost is calculated for just the extension
HostCost: types.ZeroCurrency, // collateral lock up is less than rollover
},
{
Description: "renewed storage - greater capacity",
Modify: func(rev *types.V2FileContract, p *RPCRenewContractParams) {
// add storage
rev.Capacity = SectorSize * 2
rev.Filesize = SectorSize
},
RenterCost: prices.ContractPrice.Add(prices.StoragePrice.Mul64(SectorSize).Mul64(extension)), // storage cost is calculated for just the filesize & extension
HostCost: types.ZeroCurrency, // collateral lock up is less than rollover
},
{
Description: "renewed storage",
Modify: func(rev *types.V2FileContract, p *RPCRenewContractParams) {
Expand Down Expand Up @@ -147,8 +157,13 @@ func TestRenewalCost(t *testing.T) {

contractTotal := renewal.NewContract.HostOutput.Value.Add(renewal.NewContract.RenterOutput.Value)
totalCost := renter.Add(host).Add(renewal.HostRollover).Add(renewal.RenterRollover).Sub(tax).Sub(minerFee)
if !contractTotal.Equals(totalCost) {
switch {
case !contractTotal.Equals(totalCost):
t.Fatalf("expected contract sum %v, got %v", contractTotal, totalCost)
case contract.Filesize != renewal.NewContract.Filesize:
t.Fatalf("expected contract size %d, got %d", contract.Filesize, renewal.NewContract.Filesize)
case contract.Filesize != renewal.NewContract.Capacity: // renewals reset capacity
t.Fatalf("expected contract capacity %d, got %d", contract.Filesize, renewal.NewContract.Capacity)
}
})
}
Expand Down Expand Up @@ -194,6 +209,14 @@ func TestRefreshCost(t *testing.T) {
rev.Filesize = SectorSize
},
},
{
Description: "renewed storage - greater capacity",
Modify: func(rev *types.V2FileContract) {
// add storage
rev.Capacity = SectorSize * 4
rev.Filesize = SectorSize
},
},
{
Description: "renewed storage - no renter rollover",
Modify: func(rev *types.V2FileContract) {
Expand Down Expand Up @@ -239,8 +262,14 @@ func TestRefreshCost(t *testing.T) {

contractTotal := refresh.NewContract.HostOutput.Value.Add(refresh.NewContract.RenterOutput.Value)
totalCost := renter.Add(host).Add(refresh.HostRollover).Add(refresh.RenterRollover).Sub(tax).Sub(minerFee)
if !contractTotal.Equals(totalCost) {

switch {
case !contractTotal.Equals(totalCost):
t.Fatalf("expected contract sum %v, got %v", contractTotal, totalCost)
case contract.Filesize != refresh.NewContract.Filesize:
t.Fatalf("expected contract size %d, got %d", contract.Filesize, refresh.NewContract.Filesize)
case contract.Capacity != refresh.NewContract.Capacity:
t.Fatalf("expected contract capacity %d, got %d", contract.Capacity, refresh.NewContract.Capacity)
}
})
}
Expand Down

0 comments on commit 5dc3661

Please sign in to comment.