diff --git a/.changeset/extended_testrpcrenew_and_testrpcrefresh_with_an_initial_sector_upload.md b/.changeset/extended_testrpcrenew_and_testrpcrefresh_with_an_initial_sector_upload.md new file mode 100644 index 0000000..1211c12 --- /dev/null +++ b/.changeset/extended_testrpcrenew_and_testrpcrefresh_with_an_initial_sector_upload.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +# Extended TestRPCRenew and TestRPCRefresh with an initial sector upload diff --git a/go.mod b/go.mod index dcbed28..0a0dde7 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,10 @@ toolchain go1.23.2 require ( go.etcd.io/bbolt v1.3.11 - go.sia.tech/core v0.7.1 + go.sia.tech/core v0.7.2 go.sia.tech/mux v1.3.0 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.30.0 + golang.org/x/crypto v0.31.0 lukechampine.com/frand v1.5.1 ) diff --git a/go.sum b/go.sum index b822a3c..8dfe940 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0= go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I= -go.sia.tech/core v0.7.1 h1:PrKh19Ql5vJbQbB5YGtTHQ8W3fRF8hhYnR4kPOIOIME= -go.sia.tech/core v0.7.1/go.mod h1:gB8iXFJFSV8XIHRaL00CL6Be+hyykB+SYnvRPHCCc/E= +go.sia.tech/core v0.7.2 h1:GAsZ77LE592VEBGNdKeXLV4old/zjLjH11RblHhYbP4= +go.sia.tech/core v0.7.2/go.mod h1:pRlqaLm8amh3b/OBTSqJMEXmhPT14RxjntlKPySRNpA= go.sia.tech/mux v1.3.0 h1:hgR34IEkqvfBKUJkAzGi31OADeW2y7D6Bmy/Jcbop9c= go.sia.tech/mux v1.3.0/go.mod h1:I46++RD4beqA3cW9Xm9SwXbezwPqLvHhVs9HLpDtt58= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -16,8 +16,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY= -golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= diff --git a/rhp/v4/rpc_test.go b/rhp/v4/rpc_test.go index e264b1b..a54ea37 100644 --- a/rhp/v4/rpc_test.go +++ b/rhp/v4/rpc_test.go @@ -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{ @@ -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{ @@ -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, @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{