Skip to content

Commit

Permalink
resolve master merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjbrostoff committed Mar 10, 2022
2 parents a00ef89 + decb94f commit 2fc7db1
Show file tree
Hide file tree
Showing 27 changed files with 1,305 additions and 85 deletions.
2 changes: 1 addition & 1 deletion integration/configs/sn2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ log-config:
log-max-backups: 10 # set the maximum number of old log files to retain
log-levels: # log level of individual files
common: debug
p2p: info
p2p: debug
metadb: info
dd: info
temp-dir:
Expand Down
2 changes: 1 addition & 1 deletion integration/configs/sn3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ log-config:
log-max-backups: 10 # set the maximum number of old log files to retain
log-levels: # log level of individual files
common: debug
p2p: info
p2p: debug
metadb: info
dd: info
temp-dir:
Expand Down
2 changes: 1 addition & 1 deletion integration/configs/sn4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ log-config:
log-max-backups: 10 # set the maximum number of old log files to retain
log-levels: # log level of individual files
common: debug
p2p: info
p2p: debug
metadb: info
dd: info
temp-dir:
Expand Down
108 changes: 108 additions & 0 deletions integration/download_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main_test

import (
"encoding/json"
"fmt"
"net/http"

"github.com/pastelnetwork/gonode/integration/fakes/common/testconst"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
it "github.com/pastelnetwork/gonode/integration"
helper "github.com/pastelnetwork/gonode/integration/helper"
"github.com/pastelnetwork/gonode/integration/mock"
)

var _ = Describe("NFTDownload", func() {
var (
itHelper = helper.NewItHelper()
mocker *mock.Mocker
downloadRsp map[string]interface{}

storeReq *helper.StoreRequest
storeReply *helper.StoreReply
rqfile *helper.RawSymbolIDFile
symbol []byte
)

BeforeEach(func() {
storeReq = &helper.StoreRequest{}
storeReply = &helper.StoreReply{}

downloadRsp = make(map[string]interface{})
rqfile = &helper.RawSymbolIDFile{
ID: "09f6c459-ec2a-4db1-a8fe-0648fd97b5cb",
PastelID: "jXY1wJkRFt4hsPn6LnRqUtoRmBx5QTiGcbCXorKq7JuKVy4Zo89PmE8BoGjyujqj6NwfvfGsxhUH2ute6kW2gW",
}

mocker = mock.New(it.PasteldServers, it.DDServers, it.RQServers, 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

// 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)
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{}

rqfile.SymbolIdentifiers = []string{id}
idFile, err := rqfile.GetIDFile()
Expect(err).NotTo(HaveOccurred())

storeReq.Value = idFile

// 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)
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())

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(downResp, &downloadRsp)).To(Succeed())
Expect(len(fmt.Sprintf("%v", downloadRsp["file"]))).NotTo(BeZero())
})
})
})

AfterEach(func() {
Expect(mocker.CleanupAll()).To(Succeed())
})
})
1 change: 1 addition & 0 deletions integration/fakes/common/testconst/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ var SNsPastelIDs = []string{
}

var ArtistPastelID = "jXY1wJkRFt4hsPn6LnRqUtoRmBx5QTiGcbCXorKq7JuKVy4Zo89PmE8BoGjyujqj6NwfvfGsxhUH2ute6kW2gW"
var TestRegTXID = "b4b1fc370983c7409ec58fcd079136f04efe1e1c363f4cd8f4aff8986a91ef09"
144 changes: 144 additions & 0 deletions integration/fakes/pasteld/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,73 @@ func (h *rpcHandler) HandleTickets(params json.RawMessage) (interface{}, *jrpc2.
(p.Params[0] == "register") || (p.Params[0] == "activate") ||
(p.Params[0] == "find" && p.Params[1] == "action-act") {
p.Params = p.Params[:2]
} else if len(p.Params) > 4 && p.Params[0] == "tools" && p.Params[1] == "validateownership" {
p.Params = p.Params[:5]
} else if len(p.Params) > 2 && p.Params[0] == "list" &&
((p.Params[1] == "trade" && p.Params[2] == "available") || p.Params[1] == "act") {
if p.Params[1] == "act" {
p.Params = p.Params[:2]

key := "tickets" + "*" + strings.Join(p.Params, "*")
data, err := h.store.Get(key)
if err != nil {
return nil, &jrpc2.ErrorObject{
Code: jrpc2.InternalErrorCode,
Message: jrpc2.ErrorMsg("unable to fetch " + err.Error()),
Data: "fetch failure",
}
}
toRet := ActTickets{}
if err := json.Unmarshal(data, &toRet); err != nil {
return nil, &jrpc2.ErrorObject{
Code: jrpc2.InternalErrorCode,
Message: jrpc2.ErrorMsg("unable to unmarsal " + err.Error()),
Data: "unmarshal failure",
}
}

return toRet, nil
}

key := "tickets" + "*" + strings.Join(p.Params, "*")
data, err := h.store.Get(key)
if err != nil {
return nil, &jrpc2.ErrorObject{
Code: jrpc2.InternalErrorCode,
Message: jrpc2.ErrorMsg("unable to fetch " + err.Error()),
Data: "fetch failure",
}
}
toRet := []TradeTicket{}
if err := json.Unmarshal(data, &toRet); err != nil {
return nil, &jrpc2.ErrorObject{
Code: jrpc2.InternalErrorCode,
Message: jrpc2.ErrorMsg("unable to unmarsal " + err.Error()),
Data: "unmarshal failure",
}
}

return toRet, nil
} else if p.Params[0] == "get" {
key := "tickets" + "*" + strings.Join(p.Params, "*")
data, err := h.store.Get(key)
if err != nil {
return nil, &jrpc2.ErrorObject{
Code: jrpc2.InternalErrorCode,
Message: jrpc2.ErrorMsg("unable to fetch " + err.Error()),
Data: "fetch failure",
}
}
toRet := RegTicket{}
if err := json.Unmarshal(data, &toRet); err != nil {
return nil, &jrpc2.ErrorObject{
Code: jrpc2.InternalErrorCode,
Message: jrpc2.ErrorMsg("unable to unmarsal " + err.Error()),
Data: "unmarshal failure",
}
}

return toRet, nil
}

data, err := h.handle("tickets", p.Params)
Expand Down Expand Up @@ -350,3 +417,80 @@ func (h *rpcHandler) HandleSendMany(params json.RawMessage) (interface{}, *jrpc2

return string(data), nil
}

type TradeTicket struct {
Height int `json:"height"`
TXID string `json:"txid"`
Ticket TradeTicketData `json:"ticket"`
}

// TradeTicketData represents pastel Trade ticket data
type TradeTicketData struct {
Type string `json:"type"` // "nft-trade"
Version int `json:"version"` // version
PastelID string `json:"pastelID"` // PastelID of the buyer
SellTXID string `json:"sell_txid"` // txid with sale ticket
BuyTXID string `json:"buy_txid"` // txid with buy ticket
NFTTXID string `json:"nft_txid"` // txid with either 1) NFT activation ticket or 2) trade ticket in it
RegistrationTXID string `json:"registration_txid"` // txid with registration ticket
Price string `json:"price"`
CopySerialNR string `json:"copy_serial_nr"`
Signature string `json:"signature"`
}

// RegTickets is a collection of RegTicket
type RegTickets []RegTicket

// RegTicket represents pastel registration ticket.
type RegTicket struct {
Height int `json:"height"`
TXID string `json:"txid"`
RegTicketData RegTicketData `json:"ticket"`
}

// RegTicketSignatures represents signatures from parties
type RegTicketSignatures struct {
Creator map[string]string `json:"creator,omitempty"`
Mn1 map[string]string `json:"mn1,omitempty"`
Mn2 map[string]string `json:"mn2,omitempty"`
Mn3 map[string]string `json:"mn3,omitempty"`
}

// RegTicketData is Pastel Registration ticket structure
type RegTicketData struct {
Type string `json:"type"`
Version int `json:"version"`
Signatures RegTicketSignatures `json:"signatures"`
Key1 string `json:"key1"`
Key2 string `json:"key2"`
CreatorHeight int `json:"creator_height"`
TotalCopies int `json:"total_copies"`
Royalty float64 `json:"royalty"`
RoyaltyAddress string `json:"royalty_address"`
Green bool `json:"green"`
GreenAddress string `json:"green_address"`
StorageFee int `json:"storage_fee"`
NFTTicket []byte `json:"nft_ticket"`
//NFTTicketData NFTTicket `json:"-"`
}

// ActTickets is a collection of ActTicket
type ActTickets []ActTicket

// ActTicket represents pastel activation ticket.
type ActTicket struct {
Height int `json:"height"`
TXID string `json:"txid"`
ActTicketData ActTicketData `json:"ticket"`
}

// ActTicketData represents activation ticket properties
type ActTicketData struct {
PastelID string `json:"pastelID"`
Signature string `json:"signature"`
Type string `json:"type"`
CreatorHeight int `json:"creator_height"`
RegTXID string `json:"reg_txid"`
StorageFee int `json:"storage_fee"`
Version int `json:"version"`
}
2 changes: 1 addition & 1 deletion integration/fakes/rq-service/handler/rqservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (service *RQService) EncodeMetaData(ctx context.Context, req *pb.EncodeMeta

// Decode ...
func (service *RQService) Decode(ctx context.Context, req *pb.DecodeRequest) (*pb.DecodeReply, error) {
key := "decode" + "*" + string(req.EncoderParameters) + "*" + req.Path
key := "decode" + "*"
data, err := service.store.Get(key)
if err != nil {
return nil, fmt.Errorf("unable to fetch data: %w", err)
Expand Down
16 changes: 12 additions & 4 deletions integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ module github.com/pastelnetwork/gonode/integration
go 1.15

require (
github.com/DataDog/zstd v1.5.0 // indirect
github.com/btcsuite/btcutil v1.0.2
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.4.2
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.15.0
github.com/pastelnetwork/gonode/integration/fakes/common v0.0.0-00010101000000-000000000000 // indirect
github.com/onsi/gomega v1.18.1
github.com/pastelnetwork/gonode/common v0.0.0-00010101000000-000000000000
github.com/pastelnetwork/gonode/integration/fakes/common v0.0.0-00010101000000-000000000000
github.com/pastelnetwork/gonode/pastel v0.0.0-20220301004244-b3d3f466e5d2
github.com/testcontainers/testcontainers-go v0.12.0
)

replace github.com/pastelnetwork/gonode/integration/fakes/common => ./fakes/common
replace (
github.com/pastelnetwork/gonode/common => ../common
github.com/pastelnetwork/gonode/integration/fakes/common => ./fakes/common
github.com/pastelnetwork/gonode/pastel => ../pastel
)
Loading

0 comments on commit 2fc7db1

Please sign in to comment.