Skip to content

Commit

Permalink
Merge pull request #139 from ShyftNetwork/development
Browse files Browse the repository at this point in the history
Merging Development with Upstream Changes to Geth 1.18.8
  • Loading branch information
GregTheGreek authored Nov 28, 2018
2 parents 597257e + cef0933 commit 3cf6584
Show file tree
Hide file tree
Showing 82 changed files with 1,231 additions and 822 deletions.
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ les/ @zsfelfoldi
light/ @zsfelfoldi
mobile/ @karalabe
p2p/ @fjl @zsfelfoldi
p2p/simulations @lmars
p2p/protocols @zelig
swarm/api/http @justelad
p2p/simulations @lmars
p2p/protocols @zelig
swarm/api/http @justelad
swarm/bmt @zelig
swarm/dev @lmars
swarm/fuse @jmozah @holisticode
Expand Down
6 changes: 6 additions & 0 deletions cmd/swarm/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func accessNewPass(ctx *cli.Context) {
utils.Fatalf("error getting session key: %v", err)
}
m, err := api.GenerateAccessControlManifest(ctx, ref, accessKey, ae)
if err != nil {
utils.Fatalf("had an error generating the manifest: %v", err)
}
if dryRun {
err = printManifests(m, nil)
if err != nil {
Expand Down Expand Up @@ -147,6 +150,9 @@ func accessNewPK(ctx *cli.Context) {
utils.Fatalf("error getting session key: %v", err)
}
m, err := api.GenerateAccessControlManifest(ctx, ref, sessionKey, ae)
if err != nil {
utils.Fatalf("had an error generating the manifest: %v", err)
}
if dryRun {
err = printManifests(m, nil)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/swarm/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/ShyftNetwork/go-empyrean/log"
"github.com/ShyftNetwork/go-empyrean/swarm/api"
swarm "github.com/ShyftNetwork/go-empyrean/swarm/api/client"
swarmhttp "github.com/ShyftNetwork/go-empyrean/swarm/api/http"
"github.com/ShyftNetwork/go-empyrean/swarm/testutil"
)

Expand All @@ -54,7 +55,7 @@ var DefaultCurve = crypto.S256()
// is then fetched through 2nd node. since the tested code is not key-aware - we can just
// fetch from the 2nd node using HTTP BasicAuth
func TestAccessPassword(t *testing.T) {
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil)
defer srv.Close()

dataFilename := testutil.TempFileWithContent(t, data)
Expand Down
36 changes: 6 additions & 30 deletions cmd/swarm/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ package main
import (
"bytes"
"crypto/md5"
"crypto/rand"
"io"
"io/ioutil"
"net/http"
"os"
"runtime"
"strings"
"testing"

"github.com/ShyftNetwork/go-empyrean/swarm"
"github.com/ShyftNetwork/go-empyrean/swarm/testutil"
)

// TestCLISwarmExportImport perform the following test:
Expand All @@ -45,11 +44,12 @@ func TestCLISwarmExportImport(t *testing.T) {
cluster := newTestCluster(t, 1)

// generate random 10mb file
f, cleanup := generateRandomFile(t, 10000000)
defer cleanup()
content := testutil.RandomBytes(1, 10000000)
fileName := testutil.TempFileWithContent(t, string(content))
defer os.Remove(fileName)

// upload the file with 'swarm up' and expect a hash
up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, "up", f.Name())
up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, "up", fileName)
_, matches := up.ExpectRegexp(`[a-f\d]{64}`)
up.ExpectExit()
hash := matches[0]
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestCLISwarmExportImport(t *testing.T) {
}

// compare downloaded file with the generated random file
mustEqualFiles(t, f, res.Body)
mustEqualFiles(t, bytes.NewReader(content), res.Body)
}

func mustEqualFiles(t *testing.T, up io.Reader, down io.Reader) {
Expand All @@ -117,27 +117,3 @@ func mustEqualFiles(t *testing.T, up io.Reader, down io.Reader) {
t.Fatalf("downloaded imported file md5=%x (length %v) is not the same as the generated one mp5=%x (length %v)", downHash, downLen, upHash, upLen)
}
}

func generateRandomFile(t *testing.T, size int) (f *os.File, teardown func()) {
// create a tmp file
tmp, err := ioutil.TempFile("", "swarm-test")
if err != nil {
t.Fatal(err)
}

// callback for tmp file cleanup
teardown = func() {
tmp.Close()
os.Remove(tmp.Name())
}

// write 10mb random data to file
buf := make([]byte, 10000000)
_, err = rand.Read(buf)
if err != nil {
t.Fatal(err)
}
ioutil.WriteFile(tmp.Name(), buf, 0755)

return tmp, teardown
}
25 changes: 6 additions & 19 deletions cmd/swarm/feeds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
Expand All @@ -40,29 +39,20 @@ import (

func TestCLIFeedUpdate(t *testing.T) {

srv := testutil.NewTestSwarmServer(t, func(api *api.API) testutil.TestServer {
srv := swarmhttp.NewTestSwarmServer(t, func(api *api.API) swarmhttp.TestServer {
return swarmhttp.NewServer(api, "")
}, nil)
log.Info("starting a test swarm server")
defer srv.Close()

// create a private key file for signing
pkfile, err := ioutil.TempFile("", "swarm-test")
if err != nil {
t.Fatal(err)
}
defer pkfile.Close()
defer os.Remove(pkfile.Name())

privkeyHex := "0000000000000000000000000000000000000000000000000000000000001979"
privKey, _ := crypto.HexToECDSA(privkeyHex)
address := crypto.PubkeyToAddress(privKey.PublicKey)

// save the private key to a file
_, err = io.WriteString(pkfile, privkeyHex)
if err != nil {
t.Fatal(err)
}
pkFileName := testutil.TempFileWithContent(t, privkeyHex)
defer os.Remove(pkFileName)

// compose a topic. We'll be doing quotes about Miguel de Cervantes
var topic feed.Topic
Expand All @@ -76,7 +66,7 @@ func TestCLIFeedUpdate(t *testing.T) {

flags := []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkfile.Name(),
"--bzzaccount", pkFileName,
"feed", "update",
"--topic", topic.Hex(),
"--name", name,
Expand All @@ -89,13 +79,10 @@ func TestCLIFeedUpdate(t *testing.T) {

// now try to get the update using the client
client := swarm.NewClient(srv.URL)
if err != nil {
t.Fatal(err)
}

// build the same topic as before, this time
// we use NewTopic to create a topic automatically.
topic, err = feed.NewTopic(name, subject)
topic, err := feed.NewTopic(name, subject)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -153,7 +140,7 @@ func TestCLIFeedUpdate(t *testing.T) {
// test publishing a manifest
flags = []string{
"--bzzapi", srv.URL,
"--bzzaccount", pkfile.Name(),
"--bzzaccount", pkFileName,
"feed", "create",
"--topic", topic.Hex(),
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/swarm/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var (
}
SwarmApiFlag = cli.StringFlag{
Name: "bzzapi",
Usage: "Swarm HTTP endpoint",
Usage: "Specifies the Swarm HTTP endpoint to connect to",
Value: "http://127.0.0.1:8500",
}
SwarmRecursiveFlag = cli.BoolFlag{
Expand Down
3 changes: 3 additions & 0 deletions cmd/swarm/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func TestCLISwarmFs(t *testing.T) {
t.Fatal(err)
}
dirPath2, err := createDirInDir(dirPath, "AnotherTestSubDir")
if err != nil {
t.Fatal(err)
}

dummyContent := "somerandomtestcontentthatshouldbeasserted"
dirs := []string{
Expand Down
6 changes: 3 additions & 3 deletions cmd/swarm/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"github.com/ShyftNetwork/go-empyrean/swarm/api"
swarm "github.com/ShyftNetwork/go-empyrean/swarm/api/client"
"github.com/ShyftNetwork/go-empyrean/swarm/testutil"
swarmhttp "github.com/ShyftNetwork/go-empyrean/swarm/api/http"
)

// TestManifestChange tests manifest add, update and remove
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestManifestChangeEncrypted(t *testing.T) {
// Argument encrypt controls whether to use encryption or not.
func testManifestChange(t *testing.T, encrypt bool) {
t.Parallel()
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil)
defer srv.Close()

tmp, err := ioutil.TempDir("", "swarm-manifest-test")
Expand Down Expand Up @@ -430,7 +430,7 @@ func TestNestedDefaultEntryUpdateEncrypted(t *testing.T) {

func testNestedDefaultEntryUpdate(t *testing.T, encrypt bool) {
t.Parallel()
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil)
defer srv.Close()

tmp, err := ioutil.TempDir("", "swarm-manifest-test")
Expand Down
3 changes: 1 addition & 2 deletions cmd/swarm/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/ShyftNetwork/go-empyrean/swarm"
"github.com/ShyftNetwork/go-empyrean/swarm/api"
swarmhttp "github.com/ShyftNetwork/go-empyrean/swarm/api/http"
"github.com/ShyftNetwork/go-empyrean/swarm/testutil"
"github.com/docker/docker/pkg/reexec"
)

Expand All @@ -58,7 +57,7 @@ func init() {
})
}

func serverFunc(api *api.API) testutil.TestServer {
func serverFunc(api *api.API) swarmhttp.TestServer {
return swarmhttp.NewServer(api, "")
}
func TestMain(m *testing.M) {
Expand Down
26 changes: 7 additions & 19 deletions cmd/swarm/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/ShyftNetwork/go-empyrean/log"
swarm "github.com/ShyftNetwork/go-empyrean/swarm/api/client"
swarmhttp "github.com/ShyftNetwork/go-empyrean/swarm/api/http"
"github.com/ShyftNetwork/go-empyrean/swarm/testutil"
"github.com/mattn/go-colorable"
)
Expand Down Expand Up @@ -77,33 +78,22 @@ func testCLISwarmUp(toEncrypt bool, t *testing.T) {
cluster := newTestCluster(t, 3)
defer cluster.Shutdown()

// create a tmp file
tmp, err := ioutil.TempFile("", "swarm-test")
if err != nil {
t.Fatal(err)
}
defer tmp.Close()
defer os.Remove(tmp.Name())
tmpFileName := testutil.TempFileWithContent(t, data)
defer os.Remove(tmpFileName)

// write data to file
data := "notsorandomdata"
_, err = io.WriteString(tmp, data)
if err != nil {
t.Fatal(err)
}

hashRegexp := `[a-f\d]{64}`
flags := []string{
"--bzzapi", cluster.Nodes[0].URL,
"up",
tmp.Name()}
tmpFileName}
if toEncrypt {
hashRegexp = `[a-f\d]{128}`
flags = []string{
"--bzzapi", cluster.Nodes[0].URL,
"up",
"--encrypt",
tmp.Name()}
tmpFileName}
}
// upload the file with 'swarm up' and expect a hash
log.Info(fmt.Sprintf("uploading file with 'swarm up'"))
Expand Down Expand Up @@ -203,7 +193,6 @@ func testCLISwarmUpRecursive(toEncrypt bool, t *testing.T) {
}
defer os.RemoveAll(tmpUploadDir)
// create tmp files
data := "notsorandomdata"
for _, path := range []string{"tmp1", "tmp2"} {
if err := ioutil.WriteFile(filepath.Join(tmpUploadDir, path), bytes.NewBufferString(data).Bytes(), 0644); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -243,8 +232,7 @@ func testCLISwarmUpRecursive(toEncrypt bool, t *testing.T) {
}
defer os.RemoveAll(tmpDownload)
bzzLocator := "bzz:/" + hash
flagss := []string{}
flagss = []string{
flagss := []string{
"--bzzapi", cluster.Nodes[0].URL,
"down",
"--recursive",
Expand Down Expand Up @@ -299,7 +287,7 @@ func TestCLISwarmUpDefaultPath(t *testing.T) {
}

func testCLISwarmUpDefaultPath(toEncrypt bool, absDefaultPath bool, t *testing.T) {
srv := testutil.NewTestSwarmServer(t, serverFunc, nil)
srv := swarmhttp.NewTestSwarmServer(t, serverFunc, nil)
defer srv.Close()

tmp, err := ioutil.TempDir("", "swarm-defaultpath-test")
Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ func ImportPreimages(db *ethdb.LDBDatabase, shyftdb *ethdb.SPGDatabase, fn strin
// Accumulate the preimages and flush when enough ws gathered
preimages[crypto.Keccak256Hash(blob)] = common.CopyBytes(blob)
if len(preimages) > 1024 {
rawdb.WritePreimages(db, 0, preimages)
rawdb.WritePreimages(db, preimages)
preimages = make(map[common.Hash][]byte)
}
}
// Flush the last batch preimage data
if len(preimages) > 0 {
rawdb.WritePreimages(db, 0, preimages)
rawdb.WritePreimages(db, preimages)
}
return nil
}
Expand Down
Loading

0 comments on commit 3cf6584

Please sign in to comment.