mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
swarm/api: Amend @gbalint comments PR 204 + args dep test loglvl
This commit is contained in:
parent
edacd4b7c3
commit
690522b09d
4 changed files with 25 additions and 10 deletions
|
|
@ -389,8 +389,11 @@ func (self *Api) ResourceLookup(name string, period uint32, version uint32) (sto
|
||||||
|
|
||||||
func (self *Api) ResourceCreate(name string, frequency uint64) (storage.Key, error) {
|
func (self *Api) ResourceCreate(name string, frequency uint64) (storage.Key, error) {
|
||||||
rsrc, err := self.resource.NewResource(name, frequency)
|
rsrc, err := self.resource.NewResource(name, frequency)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
h := rsrc.NameHash()
|
h := rsrc.NameHash()
|
||||||
return storage.Key(h[:]), err
|
return storage.Key(h[:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Api) ResourceUpdate(name string, data []byte) (storage.Key, uint32, uint32, error) {
|
func (self *Api) ResourceUpdate(name string, data []byte) (storage.Key, uint32, uint32, error) {
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,15 @@ func TestBzzResource(t *testing.T) {
|
||||||
resp, err := http.Post(url, "application/octet-stream", bytes.NewReader(databytes))
|
resp, err := http.Post(url, "application/octet-stream", bytes.NewReader(databytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if resp.StatusCode != http.StatusOK {
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Fatalf("err %s", resp.Status)
|
t.Fatalf("err %s", resp.Status)
|
||||||
}
|
}
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if !bytes.Equal(b, []byte(keybyteshash)) {
|
}
|
||||||
|
if !bytes.Equal(b, []byte(keybyteshash)) {
|
||||||
t.Fatalf("resource update hash mismatch, expected '%s' got '%s'", keybyteshash, b)
|
t.Fatalf("resource update hash mismatch, expected '%s' got '%s'", keybyteshash, b)
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
@ -80,13 +82,15 @@ func TestBzzResource(t *testing.T) {
|
||||||
resp, err = http.Get(url)
|
resp, err = http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if resp.StatusCode != http.StatusOK {
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Fatalf("err %s", resp.Status)
|
t.Fatalf("err %s", resp.Status)
|
||||||
}
|
}
|
||||||
b, err = ioutil.ReadAll(resp.Body)
|
b, err = ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if !bytes.Equal(databytes, b) {
|
}
|
||||||
|
if !bytes.Equal(databytes, b) {
|
||||||
t.Fatalf("Expected body '%x', got '%x'", databytes, b)
|
t.Fatalf("Expected body '%x', got '%x'", databytes, b)
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
@ -97,7 +101,8 @@ func TestBzzResource(t *testing.T) {
|
||||||
resp, err = http.Post(url, "application/octet-stream", bytes.NewReader(data))
|
resp, err = http.Post(url, "application/octet-stream", bytes.NewReader(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if resp.StatusCode != http.StatusOK {
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Fatalf("Update returned %d", resp.Status)
|
t.Fatalf("Update returned %d", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,13 +111,15 @@ func TestBzzResource(t *testing.T) {
|
||||||
resp, err = http.Get(url)
|
resp, err = http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if resp.StatusCode != http.StatusOK {
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Fatalf("err %s", resp.Status)
|
t.Fatalf("err %s", resp.Status)
|
||||||
}
|
}
|
||||||
b, err = ioutil.ReadAll(resp.Body)
|
b, err = ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if !bytes.Equal(data, b) {
|
}
|
||||||
|
if !bytes.Equal(data, b) {
|
||||||
t.Fatalf("Expected body '%x', got '%x'", data, b)
|
t.Fatalf("Expected body '%x', got '%x'", data, b)
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
|
||||||
|
|
@ -703,7 +703,7 @@ func newUpdateChunk(key Key, signature *Signature, period uint32, version uint32
|
||||||
datalength := len(data)
|
datalength := len(data)
|
||||||
|
|
||||||
chunk := NewChunk(key, nil)
|
chunk := NewChunk(key, nil)
|
||||||
chunk.SData = make([]byte, 4+signaturelength+headerlength+datalength)
|
chunk.SData = make([]byte, 4+signaturelength+headerlength+datalength) // initial 4 are uint16 length descriptors for headerlength and datalength
|
||||||
|
|
||||||
// data header length does NOT include the header length prefix bytes themselves
|
// data header length does NOT include the header length prefix bytes themselves
|
||||||
cursor := 0
|
cursor := 0
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -37,7 +38,11 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
|
verbose := flag.Bool("v", false, "verbose")
|
||||||
|
flag.Parse()
|
||||||
|
if *verbose {
|
||||||
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
|
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
|
||||||
|
}
|
||||||
safeName, err = ToSafeName(domainName)
|
safeName, err = ToSafeName(domainName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue