Skip to content

Commit

Permalink
v4: update TestRPCRenew to upload data before renewing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Dec 12, 2024
1 parent 571d72e commit 28baf19
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions rhp/v4/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func TestRPCRefresh(t *testing.T) {
}
fundAndSign := &fundAndSign{w, renterKey}

formContractFundAccount := func(t *testing.T, renterAllowance, hostCollateral, accountBalance types.Currency) rhp4.ContractRevision {
formContractUploadSector := func(t *testing.T, renterAllowance, hostCollateral, accountBalance types.Currency) rhp4.ContractRevision {
t.Helper()

result, err := rhp4.RPCFormContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, hostKey.PublicKey(), settings.WalletAddress, proto4.RPCFormContractParams{
Expand Down Expand Up @@ -390,11 +390,27 @@ func TestRPCRefresh(t *testing.T) {
t.Fatal(err)
}
revision.Revision = fundResult.Revision

// upload data
at := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(5 * time.Minute),
}
at.Signature = renterKey.SignHash(at.SigHash())
wRes, err := rhp4.RPCWriteSector(context.Background(), transport, settings.Prices, at, bytes.NewReader(bytes.Repeat([]byte{1}, proto4.LeafSize)), proto4.LeafSize)
if err != nil {
t.Fatal(err)
}
aRes, err := rhp4.RPCAppendSectors(context.Background(), transport, cs, settings.Prices, renterKey, revision, []types.Hash256{wRes.Root})
if err != nil {
t.Fatal(err)
}
revision.Revision = aRes.Revision
return revision
}

t.Run("no allowance or collateral", func(t *testing.T) {
revision := formContractFundAccount(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
revision := formContractUploadSector(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))

// refresh the contract
_, err = rhp4.RPCRefreshContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, revision.Revision, proto4.RPCRefreshContractParams{
Expand All @@ -410,7 +426,7 @@ func TestRPCRefresh(t *testing.T) {
})

t.Run("valid refresh", func(t *testing.T) {
revision := formContractFundAccount(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
revision := formContractUploadSector(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
// refresh the contract
refreshResult, err := rhp4.RPCRefreshContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, revision.Revision, proto4.RPCRefreshContractParams{
ContractID: revision.ID,
Expand Down Expand Up @@ -473,7 +489,7 @@ func TestRPCRenew(t *testing.T) {
}
fundAndSign := &fundAndSign{w, renterKey}

formContractFundAccount := func(t *testing.T, renterAllowance, hostCollateral, accountBalance types.Currency) rhp4.ContractRevision {
formContractUploadSector := func(t *testing.T, renterAllowance, hostCollateral, accountBalance types.Currency) rhp4.ContractRevision {
t.Helper()

result, err := rhp4.RPCFormContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, hostKey.PublicKey(), settings.WalletAddress, proto4.RPCFormContractParams{
Expand Down Expand Up @@ -514,11 +530,27 @@ func TestRPCRenew(t *testing.T) {
t.Fatal(err)
}
revision.Revision = fundResult.Revision

// upload data
at := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(5 * time.Minute),
}
at.Signature = renterKey.SignHash(at.SigHash())
wRes, err := rhp4.RPCWriteSector(context.Background(), transport, settings.Prices, at, bytes.NewReader(bytes.Repeat([]byte{1}, proto4.LeafSize)), proto4.LeafSize)
if err != nil {
t.Fatal(err)
}
aRes, err := rhp4.RPCAppendSectors(context.Background(), transport, cs, settings.Prices, renterKey, revision, []types.Hash256{wRes.Root})
if err != nil {
t.Fatal(err)
}
revision.Revision = aRes.Revision
return revision
}

t.Run("same duration", func(t *testing.T) {
revision := formContractFundAccount(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
revision := formContractUploadSector(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))

// renew the contract
_, err = rhp4.RPCRenewContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, revision.Revision, proto4.RPCRenewContractParams{
Expand All @@ -535,7 +567,7 @@ func TestRPCRenew(t *testing.T) {
})

t.Run("partial rollover", func(t *testing.T) {
revision := formContractFundAccount(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
revision := formContractUploadSector(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))

// renew the contract
renewResult, err := rhp4.RPCRenewContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, revision.Revision, proto4.RPCRenewContractParams{
Expand Down Expand Up @@ -564,7 +596,7 @@ func TestRPCRenew(t *testing.T) {
})

t.Run("full rollover", func(t *testing.T) {
revision := formContractFundAccount(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
revision := formContractUploadSector(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))

// renew the contract
renewResult, err := rhp4.RPCRenewContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, revision.Revision, proto4.RPCRenewContractParams{
Expand Down Expand Up @@ -593,7 +625,7 @@ func TestRPCRenew(t *testing.T) {
})

t.Run("no rollover", func(t *testing.T) {
revision := formContractFundAccount(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))
revision := formContractUploadSector(t, types.Siacoins(100), types.Siacoins(200), types.Siacoins(25))

// renew the contract
renewResult, err := rhp4.RPCRenewContract(context.Background(), transport, cm, fundAndSign, cm.TipState(), settings.Prices, revision.Revision, proto4.RPCRenewContractParams{
Expand Down

0 comments on commit 28baf19

Please sign in to comment.