Skip to content

Commit

Permalink
Merge branch 'feature/marketplace-api' of https://github.com/mesg-fou…
Browse files Browse the repository at this point in the history
…ndation/core into feature/marketplace-api
  • Loading branch information
antho1404 committed Mar 28, 2019
2 parents 833052f + 66f6b76 commit 61fe9fe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions database/service_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ func (d *LevelDBServiceDB) Save(s *service.Service) error {
return err
}

// delete existent service that has the same sid.
if err := d.delete(tx, s.Sid); err != nil && !IsErrNotFound(err) {
tx.Discard()
return err
}

// encode service
b, err := d.marshal(s)
if err != nil {
Expand Down
24 changes: 22 additions & 2 deletions database/service_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func TestServiceDBSave(t *testing.T) {
s2 := &service.Service{Hash: "01", Sid: "1", Name: "test-service"}
require.NoError(t, db.Save(s2))
_, err := db.Get(s1.Hash)
require.NoError(t, err)
require.IsType(t, &ErrNotFound{}, err)

// different hash, different sid. should not replace anything.
s3 := &service.Service{Hash: "02", Sid: "2", Name: "test-service"}
require.NoError(t, db.Save(s3))
ss, _ = db.All()
require.Len(t, ss, 3)
require.Len(t, ss, 2)

// test service without hash.
s := &service.Service{Name: "test-service", Sid: "Sid"}
Expand Down Expand Up @@ -192,3 +192,23 @@ func TestIsErrNotFound(t *testing.T) {
require.True(t, IsErrNotFound(&ErrNotFound{}))
require.False(t, IsErrNotFound(nil))
}

// Test to check behavior of one sid "has one" hash and ony hash "belongs to" one sid
// This test can be replaced/deleted when we implement sid "has many" hashes
func TestPairHashSid(t *testing.T) {
db, closer := openServiceDB(t)
defer closer()

s1 := &service.Service{Hash: "00", Sid: "Sid1"}
s2 := &service.Service{Hash: "01", Sid: "Sid1"}

require.NoError(t, db.Save(s1))
require.NoError(t, db.Save(s2))
defer db.Delete(s1.Hash)
defer db.Delete(s2.Hash)
_, err := db.Get(s1.Hash)
require.Error(t, err)
s, err := db.Get(s2.Hash)
require.NoError(t, err)
require.Equal(t, s.Hash, s2.Hash)
}
2 changes: 1 addition & 1 deletion dev-core
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for i in systemservices/* ; do
echo "Creating archive for $i..."
cd $i
file=$(basename "$i")
tar -czf ../../tmp-systemservices/$file.tar.gz *
tar -czf ../../tmp-systemservices/$file.tar.gz --exclude-from=.dockerignore .
varname="$(tr '[:lower:]' '[:upper:]' <<< ${file:0:1})${file:1}"
LDFLAGS+=" -X 'github.com/mesg-foundation/core/config.${varname}URL=http://$MESG_SERVICE_SERVER/$file.tar.gz'"
cd ../..
Expand Down
2 changes: 1 addition & 1 deletion systemservices/marketplace/mesg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sid: marketplace
description: ""
configuration:
env:
- PROVIDER_ENDPOINT=https://ropsten.infura.io
- PROVIDER_ENDPOINT=https://ropsten.infura.io/v3/6115ae2531f64c04a9a392cf500e5fbe
- BLOCK_CONFIRMATIONS=0
- DEFAULT_GAS=1000000
- POLLING_TIME=1000
Expand Down

0 comments on commit 61fe9fe

Please sign in to comment.