Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 690522b

Browse files
committed
swarm/api: Amend @gbalint comments PR 204 + args dep test loglvl
1 parent edacd4b commit 690522b

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

swarm/api/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,11 @@ func (self *Api) ResourceLookup(name string, period uint32, version uint32) (sto
389389

390390
func (self *Api) ResourceCreate(name string, frequency uint64) (storage.Key, error) {
391391
rsrc, err := self.resource.NewResource(name, frequency)
392+
if err != nil {
393+
return nil, err
394+
}
392395
h := rsrc.NameHash()
393-
return storage.Key(h[:]), err
396+
return storage.Key(h[:]), nil
394397
}
395398

396399
func (self *Api) ResourceUpdate(name string, data []byte) (storage.Key, uint32, uint32, error) {

swarm/api/http/server_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ func TestBzzResource(t *testing.T) {
6464
resp, err := http.Post(url, "application/octet-stream", bytes.NewReader(databytes))
6565
if err != nil {
6666
t.Fatal(err)
67-
} else if resp.StatusCode != http.StatusOK {
67+
}
68+
if resp.StatusCode != http.StatusOK {
6869
t.Fatalf("err %s", resp.Status)
6970
}
7071
b, err := ioutil.ReadAll(resp.Body)
7172
if err != nil {
7273
t.Fatal(err)
73-
} else if !bytes.Equal(b, []byte(keybyteshash)) {
74+
}
75+
if !bytes.Equal(b, []byte(keybyteshash)) {
7476
t.Fatalf("resource update hash mismatch, expected '%s' got '%s'", keybyteshash, b)
7577
}
7678
resp.Body.Close()
@@ -80,13 +82,15 @@ func TestBzzResource(t *testing.T) {
8082
resp, err = http.Get(url)
8183
if err != nil {
8284
t.Fatal(err)
83-
} else if resp.StatusCode != http.StatusOK {
85+
}
86+
if resp.StatusCode != http.StatusOK {
8487
t.Fatalf("err %s", resp.Status)
8588
}
8689
b, err = ioutil.ReadAll(resp.Body)
8790
if err != nil {
8891
t.Fatal(err)
89-
} else if !bytes.Equal(databytes, b) {
92+
}
93+
if !bytes.Equal(databytes, b) {
9094
t.Fatalf("Expected body '%x', got '%x'", databytes, b)
9195
}
9296
resp.Body.Close()
@@ -97,7 +101,8 @@ func TestBzzResource(t *testing.T) {
97101
resp, err = http.Post(url, "application/octet-stream", bytes.NewReader(data))
98102
if err != nil {
99103
t.Fatal(err)
100-
} else if resp.StatusCode != http.StatusOK {
104+
}
105+
if resp.StatusCode != http.StatusOK {
101106
t.Fatalf("Update returned %d", resp.Status)
102107
}
103108

@@ -106,13 +111,15 @@ func TestBzzResource(t *testing.T) {
106111
resp, err = http.Get(url)
107112
if err != nil {
108113
t.Fatal(err)
109-
} else if resp.StatusCode != http.StatusOK {
114+
}
115+
if resp.StatusCode != http.StatusOK {
110116
t.Fatalf("err %s", resp.Status)
111117
}
112118
b, err = ioutil.ReadAll(resp.Body)
113119
if err != nil {
114120
t.Fatal(err)
115-
} else if !bytes.Equal(data, b) {
121+
}
122+
if !bytes.Equal(data, b) {
116123
t.Fatalf("Expected body '%x', got '%x'", data, b)
117124
}
118125
resp.Body.Close()

swarm/storage/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ func newUpdateChunk(key Key, signature *Signature, period uint32, version uint32
703703
datalength := len(data)
704704

705705
chunk := NewChunk(key, nil)
706-
chunk.SData = make([]byte, 4+signaturelength+headerlength+datalength)
706+
chunk.SData = make([]byte, 4+signaturelength+headerlength+datalength) // initial 4 are uint16 length descriptors for headerlength and datalength
707707

708708
// data header length does NOT include the header length prefix bytes themselves
709709
cursor := 0

swarm/storage/resource_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/ecdsa"
77
"crypto/rand"
88
"encoding/binary"
9+
"flag"
910
"fmt"
1011
"io/ioutil"
1112
"math/big"
@@ -37,7 +38,11 @@ var (
3738

3839
func init() {
3940
var err error
40-
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
41+
verbose := flag.Bool("v", false, "verbose")
42+
flag.Parse()
43+
if *verbose {
44+
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
45+
}
4146
safeName, err = ToSafeName(domainName)
4247
if err != nil {
4348
panic(err)

0 commit comments

Comments
 (0)