Skip to content

Commit

Permalink
add TestRenewalCost
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Dec 10, 2024
1 parent a3d0fb5 commit 6e74872
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions rhp/v4/rhp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rhp
import (
"testing"

"go.sia.tech/core/consensus"
"go.sia.tech/core/types"
)

Expand All @@ -19,3 +20,60 @@ func TestMinRenterAllowance(t *testing.T) {
t.Fatalf("expected %v, got %v", expected, minAllowance)
}
}

func TestRenewalCost(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(100),
RevisionNumber: 99999999,
}

cs := consensus.State{}
prices := HostPrices{
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, _ := RenewContract(contract, prices, RPCRenewContractParams{
Allowance: contract.RenterOutput.Value.Add(types.Siacoins(20)), // 20 SC more than renter output
Collateral: contract.MissedHostValue.Add(types.Siacoins(10)), // 10 SC more than before
ProofHeight: contract.ExpirationHeight + 1000,
})

minerFee := types.NewCurrency64(700)
prevExpirationHeight := uint64(900) // 100 blocks before

// assert expected results
renter, host := RenewalCost(cs, prices, renewal, minerFee, prevExpirationHeight)
expectedRenter := types.NewCurrency(12532760801729053476, 3317658)
expectedHost := types.NewCurrency(7843855920856563812, 71557343)
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 77 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:77: expected 1.381200001342363473543168904 KS, got 1.071200000395617624915968804 KS

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

View workflow job for this annotation

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

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

rhp_test.go:77: expected 1.381200001342363473543168904 KS, got 1.071200000395617624915968804 KS
}
}

0 comments on commit 6e74872

Please sign in to comment.