Skip to content

Commit

Permalink
WIP:e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Luis Lucas authored and iknite committed Dec 18, 2018
1 parent 0296fa6 commit e6a343f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 16 deletions.
18 changes: 9 additions & 9 deletions tests/e2e/add_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestAddVerify(t *testing.T) {
before, after := setup(0, "", t)
before, after := setupServer(0, "", t)
scenario, let := scope.Scope(t, before, after)

client := getClient(0)
Expand Down Expand Up @@ -120,18 +120,18 @@ func TestAddVerify(t *testing.T) {

let("Verify both proofs against index i event", func(t *testing.T) {
snap := &protocol.Snapshot{
s[j].HistoryDigest,
s[9].HyperDigest,
s[j].Version,
s[i].EventDigest,
HistoryDigest: s[j].HistoryDigest,
HyperDigest: s[9].HyperDigest,
Version: s[j].Version,
EventDigest: s[i].EventDigest,
}
assert.True(t, client.DigestVerify(p1, snap, hashing.NewSha256Hasher), "p1 should be valid")

snap = &protocol.Snapshot{
s[k].HistoryDigest,
s[9].HyperDigest,
s[k].Version,
s[i].EventDigest,
HistoryDigest: s[k].HistoryDigest,
HyperDigest: s[9].HyperDigest,
Version: s[k].Version,
EventDigest: s[i].EventDigest,
}
assert.True(t, client.DigestVerify(p2, snap, hashing.NewSha256Hasher), "p2 should be valid")

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestCli(t *testing.T) {
before, after := setup(0, "", t)
before, after := setupServer(0, "", t)
scenario, let := scope.Scope(t, before, after)

scenario("Add one event through cli and verify it", func() {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/incremental_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestIncrementalConsistency(t *testing.T) {
before, after := setup(0, "", t)
before, after := setupServer(0, "", t)
scenario, let := scope.Scope(t, before, after)

client := getClient(0)
Expand Down
97 changes: 92 additions & 5 deletions tests/e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,117 @@ import (
"time"

"github.com/bbva/qed/client"
"github.com/bbva/qed/gossip/auditor"
"github.com/bbva/qed/gossip/monitor"
"github.com/bbva/qed/gossip/publisher"
"github.com/bbva/qed/server"
"github.com/bbva/qed/testutils/scope"

"github.com/valyala/fasthttp"
)

var apiKey, storageType, listenAddr, keyFile string
var apiKey, storageType, keyFile string
var cacheSize uint64

const (
QEDUrl = "http://127.0.0.1:9000"
PubUrl = "http://127.0.0.1:9000"
APIKey = "my-key"
)

func init() {
apiKey = "my-key"
apiKey = APIKey
cacheSize = 50000
storageType = "badger"

usr, _ := user.Current()
keyFile = fmt.Sprintf("%s/.ssh/id_ed25519", usr.HomeDir)
}

func setup(id int, joinAddr string, t *testing.T) (scope.TestF, scope.TestF) {
func setupAuditor(t *testing.T) (scope.TestF, scope.TestF) {
var au *auditor.Auditor
var err error

before := func(t *testing.T) {
conf := auditor.DefaultConfig()
conf.QEDUrls = []string{QEDUrl}
conf.PubUrls = []string{PubUrl}
conf.APIKey = APIKey

go (func() {
au, err = auditor.NewAuditor(conf)
if err != nil {
t.Fatalf("Unable to create a new auditor: %v", err)
}
})()
time.Sleep(2 * time.Second)
}

after := func(t *testing.T) {
if au != nil {
au.Shutdown()
} else {
t.Fatalf("Unable to shutdown the auditor!")
}
}
return before, after
}

func setupMonitor(t *testing.T) (scope.TestF, scope.TestF) {
var mn *monitor.Monitor
var err error

before := func(t *testing.T) {
conf := monitor.DefaultConfig()
conf.QEDEndpoints = []string{QEDUrl}
conf.APIKey = APIKey

go (func() {
mn, err = monitor.NewMonitor(conf)
if err != nil {
t.Fatalf("Unable to create a new monitor: %v", err)
}
})()
time.Sleep(2 * time.Second)
}

after := func(t *testing.T) {
if mn != nil {
mn.Shutdown()
} else {
t.Fatalf("Unable to shutdown the monitor!")
}
}
return before, after
}

func setupPublisher(t *testing.T) (scope.TestF, scope.TestF) {
var pu *publisher.Publisher

before := func(t *testing.T) {
conf := publisher.DefaultConfig()
conf.Client = &fasthttp.Client{}
conf.SendTo = []string{PubUrl}

go (func() {
pu = publisher.NewPublisher(conf)
})()
time.Sleep(2 * time.Second)
}

after := func(t *testing.T) {
}
return before, after
}

func setupServer(id int, joinAddr string, t *testing.T) (scope.TestF, scope.TestF) {
var srv *server.Server
var err error
path := fmt.Sprintf("/var/tmp/e2e-qed%d/", id)

before := func(t *testing.T) {
os.RemoveAll(path)
os.MkdirAll(path, os.FileMode(0755))
_ = os.MkdirAll(path, os.FileMode(0755))

hostname, _ := os.Hostname()
conf := server.DefaultConfig()
Expand Down Expand Up @@ -79,7 +166,7 @@ func setup(id int, joinAddr string, t *testing.T) (scope.TestF, scope.TestF) {

after := func(t *testing.T) {
if srv != nil {
srv.Stop()
_ = srv.Stop()
} else {
t.Fatalf("Unable to shutdown the server!")
}
Expand Down

0 comments on commit e6a343f

Please sign in to comment.