Skip to content

Commit

Permalink
add TestRefreshCost
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Dec 10, 2024
1 parent 453d965 commit e24ae46
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions rhp/v4/rhp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,59 @@ func TestRenewalCost(t *testing.T) {
t.Fatalf("expected %v, got %v", inputSum, outputSum)

Check failure on line 78 in rhp/v4/rhp_test.go

View workflow job for this annotation

GitHub Actions / test / test (1.22, ubuntu-latest)

Test go.sia.tech/core/rhp/v4/TestRenewalCost failed in 0s

rhp_test.go:78: expected 1.381200001280757536391168904 KS, got 1.071200000364210676563968804 KS
}
}

func TestRefreshCost(t *testing.T) {
// contract for renewal
contract := types.V2FileContract{
Capacity: 1000 * SectorSize,
Filesize: 900 * SectorSize,
FileMerkleRoot: types.Hash256{1, 1, 1},
ProofHeight: 500000, // block 500k
ExpirationHeight: 500000 + 1000, // 1000 block window
RenterOutput: types.SiacoinOutput{Value: types.Siacoins(300)},
HostOutput: types.SiacoinOutput{Value: types.Siacoins(400)},
MissedHostValue: types.Siacoins(700),
TotalCollateral: types.Siacoins(1000),
RevisionNumber: 99999999,
}

cs := consensus.State{}
prices := HostPrices{
TipHeight: 40000,
ContractPrice: types.NewCurrency64(100),
Collateral: types.NewCurrency64(200),
StoragePrice: types.NewCurrency64(300),
IngressPrice: types.NewCurrency64(400),
EgressPrice: types.NewCurrency64(500),
FreeSectorPrice: types.NewCurrency64(600),
}

// renew contract
renewal, _ := RefreshContract(contract, prices, RPCRefreshContractParams{
Allowance: contract.RenterOutput.Value.Add(types.Siacoins(20)), // 20 SC more than renter output
Collateral: contract.TotalCollateral.Add(types.Siacoins(10)),
})

minerFee := types.NewCurrency64(700)

// assert expected results
renter, host := RefreshCost(cs, prices, renewal, minerFee)
expectedRenter := types.NewCurrency(10700203959496213284, 21749095)
expectedHost := types.NewCurrency(13106743224624480256, 54752209)
if !renter.Equals(expectedRenter) {
t.Fatalf("expected %v, got %v", expectedRenter, renter)
} else if !host.Equals(expectedHost) {
t.Fatalf("expected %v, got %v", expectedHost, host)
}

// make sure the sums match
fc := renewal.NewContract
inputSum := renter.Add(host)
outputSum := fc.RenterOutput.Value.
Add(fc.HostOutput.Value).
Add(cs.V2FileContractTax(fc)).
Add(minerFee)
if !inputSum.Equals(outputSum) {
t.Fatalf("expected %v, got %v", inputSum, outputSum)

Check failure on line 134 in rhp/v4/rhp_test.go

View workflow job for this annotation

GitHub Actions / test / test (1.22, ubuntu-latest)

Test go.sia.tech/core/rhp/v4/TestRefreshCost failed in 0s

rhp_test.go:134: expected 1.411200000000000000000000804 KS, got 2.111200000000000000000000804 KS
}
}

0 comments on commit e24ae46

Please sign in to comment.