Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
dahn510 committed Jun 26, 2023
1 parent 1b8c546 commit fc83070
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 4 additions & 0 deletions jprov/server/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func attest(w *http.ResponseWriter, r *http.Request, cmd *cobra.Command, q *queu
}

upload, err := addMsgAttest(address, attest.Cid, q)
if err != nil {
http.Error(*w, err.Error(), http.StatusBadRequest)
return
}

upload.Callback.Wait()

Expand Down
1 change: 1 addition & 0 deletions jprov/server/file_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestWriteResponse(t *testing.T) {
}

err := server.WriteResponse(rec, upload, c.fid, c.cid)
assert.NoError(t, err)

resp := types.UploadResponse{
CID: c.cid,
Expand Down
6 changes: 3 additions & 3 deletions jprov/server/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetMerkleTree(ctx client.Context, filename string) (*merkletree.MerkleTree,
return &merkletree.MerkleTree{}, fmt.Errorf("unable to find merkle tree for: %s", filename)
}

return merkletree.ImportMerkleTree(rawTree, sha3.New512())
return merkletree.ImportMerkleTree(rawTree, sha3.New512())
}

func GenerateMerkleProof(tree merkletree.MerkleTree, index int, item []byte) (valid bool, proof *merkletree.Proof, err error) {
Expand All @@ -57,7 +57,7 @@ func GenerateMerkleProof(tree merkletree.MerkleTree, index int, item []byte) (va
}

valid, err = merkletree.VerifyProofUsing(h.Sum(nil), false, proof, [][]byte{tree.Root()}, sha3.New512())
return
return
}

func CreateMerkleForProof(clientCtx client.Context, filename string, index int, ctx *utils.Context) (string, string, error) {
Expand Down Expand Up @@ -223,7 +223,7 @@ func requestAttestation(clientCtx client.Context, cid string, hashList string, i

pwg.Wait()

if count < 3 {//NOTE: this value can change in chain params
if count < 3 { // NOTE: this value can change in chain params
fmt.Println("failed to get enough attestations...")
return fmt.Errorf("failed to get attestations")
}
Expand Down
24 changes: 12 additions & 12 deletions jprov/server/proofs_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package server_test

import (
"testing"
"io"
"fmt"
"crypto/sha256"
"fmt"
"io"
"testing"

"github.com/JackalLabs/jackal-provider/jprov/server"
// "github.com/JackalLabs/jackal-provider/jprov/types"
// "github.com/JackalLabs/jackal-provider/jprov/testutils"
// "github.com/JackalLabs/jackal-provider/jprov/types"
// "github.com/JackalLabs/jackal-provider/jprov/testutils"
"github.com/stretchr/testify/require"
merkletree "github.com/wealdtech/go-merkletree"
"github.com/wealdtech/go-merkletree/sha3"
)

func TestGenerateMerkleProof(t *testing.T) {
cases := map[string]struct {
index int
item []byte
index int
item []byte
expValid bool
expErr bool
expErr bool
}{
"valid proof": {
index: 0,
item: []byte("hello"),
index: 0,
item: []byte("hello"),
expValid: true,
expErr: false,
expErr: false,
},
}

for name, c := range cases {
t.Run(name, func(t *testing.T){
t.Run(name, func(t *testing.T) {
data := [][]byte{[]byte("hello"), []byte("world")}
for i, item := range data {
h := sha256.New()
Expand Down

0 comments on commit fc83070

Please sign in to comment.