Skip to content

Commit

Permalink
[PSL-282] search & download tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matee81 committed Mar 16, 2022
1 parent 9fb804f commit a11163c
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 90 deletions.
80 changes: 36 additions & 44 deletions integration/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,66 +38,58 @@ var _ = Describe("NFTDownload", func() {

mocker = mock.New(it.PasteldServers, it.DDServers, it.RQServers, it.SNServers, itHelper)
symbol = []byte("test-symbol")
})

Context("when downloading an existing & owned valid nft", func() {
When("storing rq symbols in p2p for the test", func() {
It("should be stored successfully", func() {
Expect(mocker.MockAllRegExpections()).To(Succeed())

id, err := helper.GetP2PID(symbol)
Expect(err).NotTo(HaveOccurred())
storeReq.Value = symbol
id, err := helper.GetP2PID(symbol)
Expect(err).NotTo(HaveOccurred())
storeReq.Value = symbol

// TODO: Why keys are not propagating through p2p network? need to investigate
resp, status, err := itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN1BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())
resp, status, err := itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN1BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())

resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN2BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())

resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN3BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())
storeReq = &helper.StoreRequest{}
storeReply = &helper.StoreReply{}

storeReq = &helper.StoreRequest{}
storeReply = &helper.StoreReply{}
rqfile.SymbolIdentifiers = []string{id}
idFile, err := rqfile.GetIDFile()
Expect(err).NotTo(HaveOccurred())

rqfile.SymbolIdentifiers = []string{id}
idFile, err := rqfile.GetIDFile()
Expect(err).NotTo(HaveOccurred())
storeReq.Value = idFile
resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN1BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())

storeReq.Value = idFile
// Mock Expectations
Expect(mocker.MockAllRegExpections()).To(Succeed())

// TODO: Why keys are not propagating through p2p network? need to investigate
resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN1BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())
})

resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN2BaseURI), nil)
When("user tries to download an existing NFT ", func() {
Context("user owns the NFT", func() {
It("should download NFT successfully", func() {
downResp, status, err := itHelper.Request(helper.HttpGet, nil,
helper.GetDownloadURI(it.WNBaseURI, testconst.ArtistPastelID,
testconst.TestRegTXID), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())

resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(it.SN3BaseURI), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(json.Unmarshal(resp, storeReply)).To(Succeed())
Expect(json.Unmarshal(downResp, &downloadRsp)).To(Succeed())
Expect(len(fmt.Sprintf("%v", downloadRsp["file"]))).NotTo(BeZero())
})
})

Context("user does not own the NFT", func() {
It("should not download nft", func() {
downResp, status, err := itHelper.Request(helper.HttpGet, nil,
helper.GetDownloadURI(it.WNBaseURI, testconst.ArtistPastelID,
// Passing a different PastelID
helper.GetDownloadURI(it.WNBaseURI, "j2Y1wJkRFt4hsPn6LnRqUtoRmBx5QTiGcbCXorKq7JuKVy4Zo89PmE8BoGjyujqj6NwfvfGsxhUH2ute6kW2gY",
testconst.TestRegTXID), nil)
Expect(err).NotTo(HaveOccurred())
Expect(status).To(Equal(http.StatusOK))
Expect(status).To(Equal(http.StatusBadRequest))

Expect(json.Unmarshal(downResp, &downloadRsp)).To(Succeed())
Expect(len(fmt.Sprintf("%v", downloadRsp["file"]))).NotTo(BeZero())
Expect(fmt.Sprintf("%v", downloadRsp["message"])).To(Equal("failed to verify ownership"))
})
})
})
Expand Down
8 changes: 6 additions & 2 deletions integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ var _ = BeforeSuite(func() {
identifier := strings.ToLower(uuid.New().String())
compose = tc.NewLocalDockerCompose([]string{composeFilePath}, identifier)

Expect(compose.WithCommand([]string{"up", "-d", "--build"}).Invoke().Error).To(Succeed())
if os.Getenv("IT_DOCKER_OFF") != "true" {
Expect(compose.WithCommand([]string{"up", "-d", "--build"}).Invoke().Error).To(Succeed())
}

// Backoff wait for api-server container to be available
helper := helper.NewItHelper()
Expand Down Expand Up @@ -68,5 +70,7 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
Expect(compose.Down().Error).NotTo(HaveOccurred(), "should do docker-compose down")
if os.Getenv("IT_DOCKER_OFF") != "true" {
Expect(compose.Down().Error).NotTo(HaveOccurred(), "should do docker-compose down")
}
})
56 changes: 56 additions & 0 deletions integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package main

import (
"fmt"
"net/http"

"github.com/pastelnetwork/gonode/integration/helper"
"github.com/pastelnetwork/gonode/integration/mock"
)
Expand Down Expand Up @@ -79,4 +82,57 @@ func main() {
if err := mocker.MockAllRegExpections(); err != nil {
panic(err)
}

// insert thumbnails for search
storeReq := &helper.StoreRequest{}
storeReq.Value = []byte("thumbnail-one")

resp, status, err := itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(SN1BaseURI), nil)
if err != nil {
panic(fmt.Sprintf("unable to store thumbnail for search tests: %s", err.Error()))
} else if status != http.StatusOK {
panic(fmt.Sprintf("unable to store thumbnail for search tests: %s", string(resp)))
}

storeReq.Value = []byte("thumbnail-two")
resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(SN1BaseURI), nil)
if err != nil {
panic(fmt.Sprintf("unable to store thumbnail for search tests: %s", err.Error()))
} else if status != http.StatusOK {
panic(fmt.Sprintf("unable to store thumbnail for search tests: %s", string(resp)))
}

rqfile := &helper.RawSymbolIDFile{
ID: "09f6c459-ec2a-4db1-a8fe-0648fd97b5cb",
PastelID: "jXY1wJkRFt4hsPn6LnRqUtoRmBx5QTiGcbCXorKq7JuKVy4Zo89PmE8BoGjyujqj6NwfvfGsxhUH2ute6kW2gW",
}

symbol := []byte("test-symbol")
storeReq.Value = symbol
resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(SN1BaseURI), nil)
if err != nil {
panic(fmt.Sprintf("store thumbnail for search tests: %s", err.Error()))
} else if status != http.StatusOK {
panic(fmt.Sprintf("store thumbnail for search tests: %s", string(resp)))
}

storeReq = &helper.StoreRequest{}

id, err := helper.GetP2PID(symbol)
if err != nil {
panic(fmt.Sprintf("generate p2p id of symbol for download tests: %s", err.Error()))
}
rqfile.SymbolIdentifiers = []string{id}
idFile, err := rqfile.GetIDFile()
if err != nil {
panic(fmt.Sprintf("store generate id file for download tests: %s", err.Error()))
}

storeReq.Value = idFile
resp, status, err = itHelper.Request(helper.HttpPost, storeReq, helper.GetStoreURI(SN1BaseURI), nil)
if err != nil {
panic(fmt.Sprintf("store rq_id file for download tests: %s", err.Error()))
} else if status != http.StatusOK {
panic(fmt.Sprintf("store rq_id file for download tests: %s", string(resp)))
}
}
2 changes: 1 addition & 1 deletion integration/mock/pasteld_responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func getRegTickets() map[string][]byte {
149, 172, 64, 148, 230, 63, 44, 221, 144, 63, 173, 131, 97, 25, 227, 105, 181, 127},
CreatorName: "Alan Border",
NFTTitle: "nft-c",
NFTSeriesName: "nft-series-c",
NFTSeriesName: "nft-series",
RQIDs: []string{
"24wvWw6zhpaCDwpBAjWXprsnnnB4HApKPkAyArDSi94z",
},
Expand Down
12 changes: 12 additions & 0 deletions integration/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ var _ = Describe("NFTSearch", func() {
})
})

Context("when searching an existing nft with matching string in series", func() {
It("should be found & returned", func() {
searchParams := make(map[string]string)
searchParams["query"] = "nft-series"
searchParams["series"] = "true"

Expect(helper.DoNFTSearchWSReq(strings.TrimPrefix(it.WNBaseURI, "http://"), helper.GetNFTSearchURI(searchParams),
[]string{"nft.series_name", "nft.thumbnail_1", "nft.thumbnail_2"},
[]string{"nft-series", "dGh1bWJuYWlsLW9uZQ==", "dGh1bWJuYWlsLXR3bw=="})).To(Succeed())
})
})

AfterEach(func() {
Expect(mocker.CleanupAll()).To(Succeed())
})
Expand Down
9 changes: 4 additions & 5 deletions integration/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var _ = Describe("StoreRetrieve", func() {
storeReq *helper.StoreRequest
storeReply *helper.StoreReply
getReply *helper.RetrieveResponse
//err error
)

BeforeEach(func() {
Expand Down Expand Up @@ -58,7 +57,7 @@ var _ = Describe("StoreRetrieve", func() {
Expect(json.Unmarshal(getResp, getReply)).To(Succeed())

Expect(getReply.Key).To(Equal(storeReply.Key))
Expect(getReply.Value).To(Equal(getReply.Value))
Expect(storeReq.Value).To(Equal(getReply.Value))
})
})

Expand All @@ -76,7 +75,7 @@ var _ = Describe("StoreRetrieve", func() {
Expect(json.Unmarshal(getResp, getReply)).To(Succeed())

Expect(getReply.Key).To(Equal(storeReply.Key))
Expect(getReply.Value).To(Equal(getReply.Value))
Expect(storeReq.Value).To(Equal(getReply.Value))
})
})

Expand All @@ -94,7 +93,7 @@ var _ = Describe("StoreRetrieve", func() {
Expect(json.Unmarshal(getResp, getReply)).To(Succeed())

Expect(getReply.Key).To(Equal(storeReply.Key))
Expect(getReply.Value).To(Equal(getReply.Value))
Expect(storeReq.Value).To(Equal(getReply.Value))
})
})

Expand All @@ -112,7 +111,7 @@ var _ = Describe("StoreRetrieve", func() {
Expect(json.Unmarshal(getResp, getReply)).To(Succeed())

Expect(getReply.Key).To(Equal(storeReply.Key))
Expect(getReply.Value).To(Equal(getReply.Value))
Expect(storeReq.Value).To(Equal(getReply.Value))
})
})

Expand Down
1 change: 0 additions & 1 deletion metadb/rqlite/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,6 @@ func Test_JSON1(t *testing.T) {
t.Fatalf("failed to perform simple SELECT: %s", err.Error())
}

fmt.Println("q: ", q)
if exp, got := `[{"columns":["phone"],"types":[""],"values":[["{\"mobile\":\"789111\",\"home\":\"123456\"}"]]}]`, asJSON(q); exp != got {
t.Fatalf("unexpected results for simple query, expected %s, got %s", exp, got)
}
Expand Down
2 changes: 2 additions & 0 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ func (s *p2p) configure(ctx context.Context) error {
PeerAuth: true, // Enable peer authentication
}

// We Set ExternalIP only for integration tests
if s.config.BootstrapIPs != "" && s.config.ExternalIP != "" {
kadOpts.ExternalIP = s.config.ExternalIP
kadOpts.PeerAuth = false
}

// new a kademlia distributed hash table
Expand Down
2 changes: 0 additions & 2 deletions pastel/action_ticket_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pastel

import (
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -32,7 +31,6 @@ func TestEncodeActionTicket(t *testing.T) {
outputTicket, err := DecodeActionTicket(encoded)

assert.Nil(t, err)
fmt.Println(string(encoded))
assert.Equal(t, inputTicket.Version, outputTicket.Version)
assert.Equal(t, inputTicket.Caller, outputTicket.Caller)
assert.Equal(t, inputTicket.BlockNum, outputTicket.BlockNum)
Expand Down
27 changes: 12 additions & 15 deletions pastel/dupe_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pastel
import (
"encoding/base64"
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -100,20 +99,18 @@ func TestToCompressSignedDDAndFingerprints(t *testing.T) {

gotDD, _, gotSig, err := ExtractCompressSignedDDAndFingerprints(reply)
assert.Nil(t, err)
if err == nil {
assert.Equal(t, tc.sig, gotSig)
assert.Equal(t, tc.dd.Block, gotDD.Block)
assert.Equal(t, tc.dd.Principal, gotDD.Principal)
assert.Equal(t, tc.dd.IsLikelyDupe, gotDD.IsLikelyDupe)
assert.Equal(t, tc.dd.IsRareOnInternet, gotDD.IsRareOnInternet)
assert.Equal(t, tc.dd.DupeDetectionSystemVersion, gotDD.DupeDetectionSystemVersion)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Porn, gotDD.AlternativeNSFWScores.Porn)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Hentai, gotDD.AlternativeNSFWScores.Hentai)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Sexy, gotDD.AlternativeNSFWScores.Sexy)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Drawings, gotDD.AlternativeNSFWScores.Drawings)
} else {
fmt.Println("err: ", err.Error())
}

assert.Equal(t, tc.sig, gotSig)
assert.Equal(t, tc.dd.Block, gotDD.Block)
assert.Equal(t, tc.dd.Principal, gotDD.Principal)
assert.Equal(t, tc.dd.IsLikelyDupe, gotDD.IsLikelyDupe)
assert.Equal(t, tc.dd.IsRareOnInternet, gotDD.IsRareOnInternet)
assert.Equal(t, tc.dd.DupeDetectionSystemVersion, gotDD.DupeDetectionSystemVersion)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Porn, gotDD.AlternativeNSFWScores.Porn)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Hentai, gotDD.AlternativeNSFWScores.Hentai)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Sexy, gotDD.AlternativeNSFWScores.Sexy)
assert.Equal(t, tc.dd.AlternativeNSFWScores.Drawings, gotDD.AlternativeNSFWScores.Drawings)

})
}
}
Expand Down
11 changes: 2 additions & 9 deletions supernode/services/common/reg_task_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package common
import (
"bytes"
"context"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -203,24 +202,18 @@ func (h *RegTaskHelper) WaitConfirmation(ctx context.Context, txid string, minCo
// ValidateBurnTxID - validates the pre-burnt fee transaction created by the caller
func (h *RegTaskHelper) ValidateBurnTxID(_ context.Context) error {
var err error
fmt.Println("here nill")
<-h.NewAction(func(ctx context.Context) error {
fmt.Println("here nill 2")
if h.ActionTicketRegMetadata == nil {
fmt.Println("here action nil")
}
confirmationChn := h.WaitConfirmation(ctx, h.ActionTicketRegMetadata.BurnTxID, int64(h.preburntTxMinConfirmations), 15*time.Second)
fmt.Println("here nill 3")
log.WithContext(ctx).Debug("waiting for confimation")
if err = <-confirmationChn; err != nil {
fmt.Println("here nill 4")
h.UpdateStatus(StatusErrorInvalidBurnTxID)
log.WithContext(ctx).WithError(err).Errorf("validate preburn transaction validation")
err = errors.Errorf("validate preburn transaction validation :%w", err)
fmt.Println("here nill 7")
return err
}

log.WithContext(ctx).Debug("confirmation done")

return nil
})

Expand Down
5 changes: 4 additions & 1 deletion supernode/services/common/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
StatusFileMismatched
StatusFileEmpty
StatusKeyNotFound
StatusFileRestoreFailed

// Final
StatusTaskCanceled
Expand Down Expand Up @@ -76,6 +77,7 @@ var statusNames = map[Status]string{
StatusFileEmpty: "File empty",
StatusFileMismatched: "File mismatched",
StatusKeyNotFound: "Key not found",
StatusFileRestoreFailed: "File restore failed",
StatusTaskCanceled: "Task Canceled",
StatusTaskCompleted: "Task Completed",
}
Expand Down Expand Up @@ -106,7 +108,8 @@ func (status Status) IsFailure() bool {
status == StatusSymbolFileInvalid || status == StatusSymbolNotFound ||
status == StatusSymbolMismatched || status == StatusSymbolsNotEnough ||
status == StatusFileDecodingFailed || status == StatusFileReadingFailed ||
status == StatusFileEmpty || status == StatusFileMismatched
status == StatusFileEmpty || status == StatusFileMismatched ||
status == StatusKeyNotFound || status == StatusFileRestoreFailed
}

// StatusNames returns a sorted list of status names.
Expand Down
Loading

0 comments on commit a11163c

Please sign in to comment.