Skip to content

Commit

Permalink
added testworld tests for proofs (#556)
Browse files Browse the repository at this point in the history
* added testworld tests for proofs

* added proof check for bob
  • Loading branch information
xmxanuel committed Dec 12, 2018
1 parent d1a8004 commit 69894e3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
9 changes: 9 additions & 0 deletions testworld/httputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func mintNFT(e *httpexpect.Expect, httpStatus int, payload map[string]interface{
return httpObj
}

func getProof(e *httpexpect.Expect, httpStatus int, documentID string, payload map[string]interface{}) *httpexpect.Object {
resp := e.POST("/document/"+documentID+"/proof").
WithHeader("accept", "application/json").
WithHeader("Content-Type", "application/json").
WithJSON(payload).
Expect().Status(httpStatus)
return resp.JSON().Object()
}

func createInsecureClient() *http.Client {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Expand Down
3 changes: 3 additions & 0 deletions testworld/nft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
const tokenIdLength = 77

func TestPaymentObligationMint_successful(t *testing.T) {
t.Parallel()

alice := doctorFord.getHostTestSuite(t, "Alice")
bob := doctorFord.getHostTestSuite(t, "Bob")
Expand Down Expand Up @@ -56,6 +57,8 @@ func TestPaymentObligationMint_successful(t *testing.T) {
}

func TestPaymentObligationMint_errors(t *testing.T) {
t.Parallel()

alice := doctorFord.getHostTestSuite(t, "Alice")

tests := []struct {
Expand Down
7 changes: 7 additions & 0 deletions testworld/payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ func updatedInvoicePayload(collaborators []string) map[string]interface{} {
}

}

func defaultProofPayload() map[string]interface{} {
return map[string]interface{}{
"type": "http://github.com/centrifuge/centrifuge-protobufs/invoice/#invoice.InvoiceData",
"fields": []string{"invoice.net_amount", "invoice.currency"},
}
}
44 changes: 44 additions & 0 deletions testworld/proof_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// +build testworld

package testworld

import (
"net/http"
"testing"

"github.com/gavv/httpexpect"
)

func TestProofWithMultipleFields_successful(t *testing.T) {
alice := doctorFord.getHostTestSuite(t, "Alice")
bob := doctorFord.getHostTestSuite(t, "Bob")

// Alice shares invoice document with Bob
res, err := alice.host.createInvoice(alice.httpExpect, http.StatusOK, defaultNFTPayload([]string{bob.id.String()}))
if err != nil {
t.Error(err)
}

docIdentifier := getDocumentIdentifier(t, res)
if docIdentifier == "" {
t.Error("docIdentifier empty")
}

proofPayload := defaultProofPayload()

proofFromAlice := getProof(alice.httpExpect, http.StatusOK, docIdentifier, proofPayload)
proofFromBob := getProof(bob.httpExpect, http.StatusOK, docIdentifier, proofPayload)

checkProof(proofFromAlice, docIdentifier)
checkProof(proofFromBob, docIdentifier)

}

func checkProof(objProof *httpexpect.Object, docIdentifier string) {
objProof.Path("$.header.document_id").String().Equal(docIdentifier)
objProof.Path("$.field_proofs[0].property").String().Equal("invoice.net_amount")
objProof.Path("$.field_proofs[0].sorted_hashes").NotNull()
objProof.Path("$.field_proofs[1].property").String().Equal("invoice.currency")
objProof.Path("$.field_proofs[1].sorted_hashes").NotNull()

}

0 comments on commit 69894e3

Please sign in to comment.