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 base58 to store hash #849

Merged
merged 5 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 3 additions & 6 deletions api/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ func TestDeployService(t *testing.T) {
archive, err := xarchive.GzippedTar(path, nil)
require.NoError(t, err)

service, validationError, err := a.DeployService(archive, nil, DeployServiceStatusOption(statuses))
_, validationError, err := a.DeployService(archive, nil, DeployServiceStatusOption(statuses))
antho1404 marked this conversation as resolved.
Show resolved Hide resolved
require.Nil(t, validationError)
require.NoError(t, err)
require.Len(t, service.Hash, 64)
}()

require.Equal(t, DeployStatus{
Expand Down Expand Up @@ -71,8 +70,7 @@ func TestDeployInvalidService(t *testing.T) {
archive, err := xarchive.GzippedTar(path, nil)
require.NoError(t, err)

service, validationError, err := a.DeployService(archive, nil, DeployServiceStatusOption(statuses))
require.Nil(t, service)
_, validationError, err := a.DeployService(archive, nil, DeployServiceStatusOption(statuses))
require.NoError(t, err)
require.Equal(t, (&importer.ValidationError{}).Error(), validationError.Error())
}()
Expand All @@ -98,10 +96,9 @@ func TestDeployServiceFromURL(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
service, validationError, err := a.DeployServiceFromURL(url, nil, DeployServiceStatusOption(statuses))
_, validationError, err := a.DeployServiceFromURL(url, nil, DeployServiceStatusOption(statuses))
require.Nil(t, validationError)
require.NoError(t, err)
require.Len(t, service.Hash, 64)
}()

require.Equal(t, DeployStatus{
Expand Down
2 changes: 2 additions & 0 deletions api/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestExecuteFunc(t *testing.T) {
defer closer()
executor := newTaskExecutor(a)
s, _ := service.FromService(&service.Service{
Hash: "1",
Name: "TestExecuteFunc",
Tasks: []*service.Task{
{
Expand Down Expand Up @@ -53,6 +54,7 @@ func TestCheckService(t *testing.T) {
defer closer()
executor := newTaskExecutor(a)
s, _ := service.FromService(&service.Service{
Hash: "1",
Name: "TestCheckService",
Dependencies: []*service.Dependency{
{
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
github.com/mesg-foundation/prefixer v0.0.0-20180907095533-d7dbe41616bd
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747
github.com/mr-tron/base58 v1.1.1
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1f
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 h1:eQox4Rh4ewJF+mqYPxCkmBAirRnPaHEB26UkNuPyjlk=
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mr-tron/base58 v1.1.1 h1:OJIdWOWYe2l5PQNgimGtuwHY8nDskvJ5vvs//YnzRLs=
github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
1 change: 1 addition & 0 deletions service/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func testDependencyLogs(t *testing.T, do func(s *Service, dependencyKey string)
go werr.Write(errData)

s, mc := newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Dependencies: []*Dependency{
{Key: dependencyKey},
},
Expand Down
4 changes: 2 additions & 2 deletions service/logs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestIntegrationLogs(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestLogs",
Dependencies: []*Dependency{
{
Expand All @@ -32,7 +32,7 @@ func TestIntegrationLogs(t *testing.T) {

func TestIntegrationLogsOnlyOneDependency(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestLogsOnlyOneDependency",
Dependencies: []*Dependency{
{
Expand Down
6 changes: 1 addition & 5 deletions service/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ const resultChannel string = "Result"

// namespace returns the namespace of the service.
func (service *Service) namespace() []string {
h, err := hex.DecodeString(service.Hash)
if err != nil {
panic(err)
}
sum := sha1.Sum(h)
sum := sha1.Sum([]byte(service.Hash))
return []string{hex.EncodeToString(sum[:])}
}

Expand Down
29 changes: 19 additions & 10 deletions service/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import (
)

func TestServiceNamespace(t *testing.T) {
service, _ := FromService(&Service{Name: "TestServiceNamespace"})
service, _ := FromService(&Service{
Hash: "1",
Name: "TestServiceNamespace",
})
namespace := service.namespace()
h, err := hex.DecodeString(service.Hash)
require.NoError(t, err)
sum := sha1.Sum(h)
sum := sha1.Sum([]byte(service.Hash))
require.Equal(t, namespace, []string{hex.EncodeToString(sum[:])})
}

func TestDependencyNamespace(t *testing.T) {
service, _ := FromService(&Service{
Hash: "1",
Name: "TestDependencyNamespace",
Dependencies: []*Dependency{
{
Expand All @@ -29,30 +31,37 @@ func TestDependencyNamespace(t *testing.T) {
},
})
dep := service.Dependencies[0]
h, err := hex.DecodeString(service.Hash)
require.NoError(t, err)
sum := sha1.Sum(h)
sum := sha1.Sum([]byte(service.Hash))
require.Equal(t, dep.namespace(), []string{hex.EncodeToString(sum[:]), "test"})
}

func TestEventSubscriptionChannel(t *testing.T) {
service, _ := FromService(&Service{Name: "TestEventSubscriptionChannel"})
service, _ := FromService(&Service{
Hash: "1",
Name: "TestEventSubscriptionChannel",
})
require.Equal(t, service.EventSubscriptionChannel(), hash.Calculate(append(
service.namespace(),
eventChannel,
)))
}

func TestTaskSubscriptionChannel(t *testing.T) {
service, _ := FromService(&Service{Name: "TaskSubscriptionChannel"})
service, _ := FromService(&Service{
Hash: "1",
Name: "TaskSubscriptionChannel",
})
require.Equal(t, service.TaskSubscriptionChannel(), hash.Calculate(append(
service.namespace(),
taskChannel,
)))
}

func TestResultSubscriptionChannel(t *testing.T) {
service, _ := FromService(&Service{Name: "ResultSubscriptionChannel"})
service, _ := FromService(&Service{
Hash: "1",
Name: "ResultSubscriptionChannel",
})
require.Equal(t, service.ResultSubscriptionChannel(), hash.Calculate(append(
service.namespace(),
resultChannel,
Expand Down
4 changes: 2 additions & 2 deletions service/service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package service

import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/utils/dirhash"
"github.com/mesg-foundation/core/x/xos"
"github.com/mr-tron/base58"
)

// WARNING about hash tags on Service type and its inner types:
Expand Down Expand Up @@ -120,7 +120,7 @@ func New(tarball io.Reader, env map[string]string, options ...Option) (*Service,
if err != nil {
return nil, err
}
s.Hash = hex.EncodeToString(hash)
s.Hash = base58.Encode(hash)
antho1404 marked this conversation as resolved.
Show resolved Hide resolved

s.injectDefinition(def)

Expand Down
18 changes: 9 additions & 9 deletions service/start_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestIntegrationStartServiceIntegration(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStartService",
Dependencies: []*Dependency{
{
Expand All @@ -31,7 +31,7 @@ func TestIntegrationStartServiceIntegration(t *testing.T) {
func TestIntegrationStartWith2DependenciesIntegration(t *testing.T) {
c := newIntegrationContainer(t)
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStartWith2Dependencies",
Dependencies: []*Dependency{
{
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestIntegrationStartWith2DependenciesIntegration(t *testing.T) {

func TestIntegrationStartAgainService(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStartAgainService",
Dependencies: []*Dependency{
{
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestIntegrationStartAgainService(t *testing.T) {
func TestIntegrationStartDependency(t *testing.T) {
c := newIntegrationContainer(t)
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStartDependency",
Dependencies: []*Dependency{
{
Expand All @@ -131,7 +131,7 @@ func TestIntegrationStartDependency(t *testing.T) {
func TestIntegrationNetworkCreated(t *testing.T) {
c := newIntegrationContainer(t)
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestNetworkCreated",
Dependencies: []*Dependency{
{
Expand All @@ -150,7 +150,7 @@ func TestIntegrationNetworkCreated(t *testing.T) {
// Test for https://github.com/mesg-foundation/core/issues/88
func TestIntegrationStartStopStart(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStartStopStart",
Dependencies: []*Dependency{
{
Expand All @@ -173,7 +173,7 @@ func TestIntegrationServiceDependenciesListensFromSamePort(t *testing.T) {
c := newIntegrationContainer(t)
var (
service, _ = FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestServiceDependenciesListensFromSamePort",
Dependencies: []*Dependency{
{
Expand All @@ -185,7 +185,7 @@ func TestIntegrationServiceDependenciesListensFromSamePort(t *testing.T) {
}, ContainerOption(c))

service1, _ = FromService(&Service{
Hash: "01",
Hash: "2",
Name: "TestServiceDependenciesListensFromSamePort1",
Dependencies: []*Dependency{
{
Expand All @@ -208,7 +208,7 @@ func TestIntegrationServiceDependenciesListensFromSamePort(t *testing.T) {
func TestStartWithSamePorts(t *testing.T) {
c := newIntegrationContainer(t)
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStartWithSamePorts",
Dependencies: []*Dependency{
{
Expand Down
6 changes: 6 additions & 0 deletions service/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestStartService(t *testing.T) {
networkID = "3"
sharedNetworkID = "4"
s, mc = newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Name: serviceName,
Sid: Sid,
Dependencies: []*Dependency{
Expand Down Expand Up @@ -124,6 +125,7 @@ func TestStartWith2Dependencies(t *testing.T) {
sharedNetworkID = "8"
serviceName = "TestStartWith2Dependencies"
s, mc = newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Name: serviceName,
Dependencies: []*Dependency{
{
Expand Down Expand Up @@ -168,6 +170,7 @@ func TestStartServiceRunning(t *testing.T) {
var (
dependencyKey = "1"
s, mc = newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Dependencies: []*Dependency{
{
Key: dependencyKey,
Expand Down Expand Up @@ -195,6 +198,7 @@ func TestPartiallyRunningService(t *testing.T) {
sharedNetworkID = "4"
containerServiceIDs = []string{"5", "6"}
s, mc = newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Name: "TestPartiallyRunningService",
Dependencies: []*Dependency{
{
Expand Down Expand Up @@ -244,6 +248,7 @@ func TestStartDependency(t *testing.T) {
sharedNetworkID = "4"
containerServiceID = "5"
s, mc = newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Name: "TestStartDependency",
Dependencies: []*Dependency{
{
Expand Down Expand Up @@ -273,6 +278,7 @@ func TestServiceStartError(t *testing.T) {
sharedNetworkID = "4"
startErr = errors.New("ops")
s, mc = newFromServiceAndContainerMocks(t, &Service{
Hash: "1",
Name: "TestNetworkCreated",
Dependencies: []*Dependency{
{
Expand Down
8 changes: 4 additions & 4 deletions service/status_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestIntegrationStatusService(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStatusService",
Dependencies: []*Dependency{
{
Expand All @@ -34,7 +34,7 @@ func TestIntegrationStatusService(t *testing.T) {

func TestIntegrationStatusDependency(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestStatusDependency",
Dependencies: []*Dependency{
{
Expand All @@ -58,7 +58,7 @@ func TestIntegrationStatusDependency(t *testing.T) {

func TestIntegrationListRunning(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestList",
Dependencies: []*Dependency{
{
Expand All @@ -77,7 +77,7 @@ func TestIntegrationListRunning(t *testing.T) {

func TestIntegrationListRunningMultipleDependencies(t *testing.T) {
service, _ := FromService(&Service{
Hash: "00",
Hash: "1",
Name: "TestListMultipleDependencies",
Dependencies: []*Dependency{
{
Expand Down
Loading