Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AccountToken helper #142

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.2

require (
go.etcd.io/bbolt v1.3.11
go.sia.tech/core v0.8.0
go.sia.tech/core v0.8.1-0.20241217152409-7950a7ca324b
go.sia.tech/mux v1.3.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.31.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.0 h1:J6vZQlVhpj4bTVeuC2GKkfkGEs8jf0j651Kl1wwOxjg=
go.sia.tech/core v0.8.0/go.mod h1:Wj1qzvpMM2rqEQjwWJEbCBbe9VWX/mSJUu2Y2ABl1QA=
go.sia.tech/core v0.8.1-0.20241217152409-7950a7ca324b h1:VRkb6OOX1KawLQwuqOEHLcjha8gxVX0tAyu2Dyoq8Ek=
go.sia.tech/core v0.8.1-0.20241217152409-7950a7ca324b/go.mod h1:Wj1qzvpMM2rqEQjwWJEbCBbe9VWX/mSJUu2Y2ABl1QA=
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=
Expand Down
82 changes: 11 additions & 71 deletions rhp/v4/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,7 @@ func TestRPCRefresh(t *testing.T) {
revision.Revision = fundResult.Revision

// upload data
at := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(5 * time.Minute),
}
at.Signature = renterKey.SignHash(at.SigHash())
at := account.Token(renterKey, hostKey.PublicKey())
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)
Expand Down Expand Up @@ -550,11 +546,7 @@ func TestRPCRenew(t *testing.T) {
revision.Revision = fundResult.Revision

// upload data
at := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(5 * time.Minute),
}
at.Signature = renterKey.SignHash(at.SigHash())
at := account.Token(renterKey, hostKey.PublicKey())
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)
Expand Down Expand Up @@ -753,13 +745,7 @@ func TestAccounts(t *testing.T) {
cs := cm.TipState()

// test operations against unknown account
token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}

tokenSigHash := token.SigHash()
token.Signature = renterKey.SignHash(tokenSigHash)
token := account.Token(renterKey, hostKey.PublicKey())
_, err = rhp4.RPCVerifySector(context.Background(), transport, settings.Prices, token, types.Hash256{1})
if err == nil || !strings.Contains(err.Error(), proto4.ErrNotEnoughFunds.Error()) {
t.Fatal(err)
Expand Down Expand Up @@ -886,14 +872,7 @@ func TestReadWriteSector(t *testing.T) {
t.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
tokenSigHash := token.SigHash()
token.Signature = renterKey.SignHash(tokenSigHash)

token := account.Token(renterKey, hostKey.PublicKey())
data := frand.Bytes(1024)

// store the sector
Expand Down Expand Up @@ -1005,12 +984,7 @@ func TestAppendSectors(t *testing.T) {
revision.Revision = fundResult.Revision
assertLastRevision(t)

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
tokenSigHash := token.SigHash()
token.Signature = renterKey.SignHash(tokenSigHash)
token := account.Token(renterKey, hostKey.PublicKey())

// store random sectors
roots := make([]types.Hash256, 0, 10)
Expand Down Expand Up @@ -1121,14 +1095,7 @@ func TestVerifySector(t *testing.T) {
t.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
tokenSigHash := token.SigHash()
token.Signature = renterKey.SignHash(tokenSigHash)

token := account.Token(renterKey, hostKey.PublicKey())
data := frand.Bytes(1024)

// store the sector
Expand Down Expand Up @@ -1212,13 +1179,7 @@ func TestRPCFreeSectors(t *testing.T) {
t.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
tokenSigHash := token.SigHash()
token.Signature = renterKey.SignHash(tokenSigHash)
token := account.Token(renterKey, hostKey.PublicKey())

roots := make([]types.Hash256, 10)
for i := range roots {
Expand Down Expand Up @@ -1333,13 +1294,7 @@ func TestRPCSectorRoots(t *testing.T) {
t.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
tokenSigHash := token.SigHash()
token.Signature = renterKey.SignHash(tokenSigHash)
token := account.Token(renterKey, hostKey.PublicKey())

roots := make([]types.Hash256, 0, 50)

Expand Down Expand Up @@ -1441,12 +1396,7 @@ func BenchmarkWrite(b *testing.B) {
b.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
token.Signature = renterKey.SignHash(token.SigHash())
token := account.Token(renterKey, hostKey.PublicKey())

var sectors [][proto4.SectorSize]byte
for i := 0; i < b.N; i++ {
Expand Down Expand Up @@ -1529,12 +1479,7 @@ func BenchmarkRead(b *testing.B) {
b.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
token.Signature = renterKey.SignHash(token.SigHash())
token := account.Token(renterKey, hostKey.PublicKey())

var sectors [][proto4.SectorSize]byte
roots := make([]types.Hash256, 0, b.N)
Expand Down Expand Up @@ -1629,12 +1574,7 @@ func BenchmarkContractUpload(b *testing.B) {
b.Fatal(err)
}
revision.Revision = fundResult.Revision

token := proto4.AccountToken{
Account: account,
ValidUntil: time.Now().Add(time.Hour),
}
token.Signature = renterKey.SignHash(token.SigHash())
token := account.Token(renterKey, hostKey.PublicKey())

var sectors [][proto4.SectorSize]byte
roots := make([]types.Hash256, 0, b.N)
Expand Down
Loading