Skip to content

Commit

Permalink
can run the integration test as a user
Browse files Browse the repository at this point in the history
  • Loading branch information
jbsv committed Mar 30, 2024
1 parent 13fb29c commit 6c9f49a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 51 deletions.
6 changes: 3 additions & 3 deletions server/scripts/publish_roster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ set -e

GREEN='\033[0;32m' # green color
NC='\033[0m' # no Color

KEYFILE=/tmp/priv.key # private key file

K=$(grep 'Pubkey:' smckey.pub | sed 's/🔑 Pubkey: //' | xxd -r -p | base64)
V=$(cat roster.txt)


echo -e "${GREEN}[PUBLISH]${NC} the roster V=${V} on the blockchain using K=${K}"
chaincli --config /tmp/chain1 pool add\
--key private.key\
chaincli --config /tmp/blockchain1 pool add\
--key ${KEYFILE}\
--args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Value\
--args value:key --args \"${K:0:8}\"\
--args value:value --args \"${K}:${V}\"\
Expand Down
62 changes: 31 additions & 31 deletions server/scripts/start_smc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,35 @@ do
done


#echo -e "${GREEN}[INITIALIZE DKG]${NC} on each node"
#i=1;
#while [ ${i} -le ${N} ]
#do
# tmux send-keys -t "${MASTERPANE}" "smccli --config /tmp/${W}${i} dkg listen" C-m
# i=$((i + 1));
#done
#
#echo -e "${GREEN}[SETUP DKG]${NC} ${N} nodes"
#i=1;
#a=""
#while [ ${i} -le ${N} ]
#do
# a="${a} --authority \$(cat /tmp/${W}${i}/dkgauthority)"
# i=$((i + 1));
#done
#tmux send-keys -t "${MASTERPANE}" "smccli --config /tmp/${W}1 dkg setup ${a} --threshold ${N} | tee smckey.pub" C-m
#
## Publish the roster
#echo -e "${GREEN}[SAVE]${NC} roster to file"
#i=1;
#p=$((P + i))
#V="127.0.0.1:${p}"
#while [ ${i} -lt ${N} ]
#do
# i=$((i + 1));
# p=$((P + i));
# V="${V},127.0.0.1:${p}";
#done
#tmux send-keys -t "${MASTERPANE}" "echo ${V} > roster.txt" C-m
#
echo -e "${GREEN}[INITIALIZE DKG]${NC} on each node"
i=1;
while [ ${i} -le ${N} ]
do
tmux send-keys -t "${MASTERPANE}" "smccli --config /tmp/${W}${i} dkg listen" C-m
i=$((i + 1));
done

echo -e "${GREEN}[SETUP DKG]${NC} ${N} nodes"
i=1;
a=""
while [ ${i} -le ${N} ]
do
a="${a} --authority \$(cat /tmp/${W}${i}/dkgauthority)"
i=$((i + 1));
done
tmux send-keys -t "${MASTERPANE}" "smccli --config /tmp/${W}1 dkg setup ${a} --threshold ${N} | tee smckey.pub" C-m

# Publish the roster
echo -e "${GREEN}[SAVE]${NC} roster to file"
i=1;
p=$((P + i))
V="127.0.0.1:${p}"
while [ ${i} -lt ${N} ]
do
i=$((i + 1));
p=$((P + i));
V="${V},127.0.0.1:${p}";
done
tmux send-keys -t "${MASTERPANE}" "echo ${V} > roster.txt" C-m

tmux select-pane -t "${MASTERPANE}"
13 changes: 6 additions & 7 deletions server/smc/smccli/web/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,21 @@ func (h *pubKeyHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
pk, err := a.GetPublicKey()
if err != nil {
http.Error(w, fmt.Sprintf("failed retrieving public key: %v", err),
http.StatusInternalServerError)
http.StatusServiceUnavailable)
return
}

b, err := pk.MarshalBinary()
response, err := pk.MarshalBinary()
if err != nil {
http.Error(w, fmt.Sprintf("failed to marshal public key: %v", err),
http.StatusInternalServerError)
http.StatusInsufficientStorage)
return
}

encoder := json.NewEncoder(w)
err = encoder.Encode(b)
// Write the byte array to the response writer
_, err = w.Write(response)
if err != nil {
http.Error(w, fmt.Sprintf("failed to respond: %v", err),
http.StatusInternalServerError)
http.Error(w, "Unable to write response", http.StatusNotExtended)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/test/admin/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.dedis.ch/kyber/v3/suites"
)

const blockchainServer = "localhost:3003"
const blockchainServer = "http://localhost:40001"

// suite is the Kyber suite for Pedersen.
var suite = suites.MustFind("Ed25519")
Expand Down
2 changes: 1 addition & 1 deletion server/test/user/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"golang.org/x/xerrors"
)

const blockchainServer = "localhost:3003"
const blockchainServer = "http://localhost:40001"

// suite is the Kyber suite for Pedersen.
var suite = suites.MustFind("Ed25519")
Expand Down
23 changes: 15 additions & 8 deletions server/test/user/smc.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package user

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

"github.com/rs/zerolog/log"
"go.dedis.ch/kyber/v3"
)

const smcServer = "http://localhost:40001"
// Define a struct to unmarshal the JSON response
type Response struct {
PubKey []byte `json:"pubkey"`
}

const smcServer = "http://localhost:41001"

func SmcGetKey() kyber.Point {
resp, err := http.Get(smcServer + "/smc/pubkey")
Expand All @@ -17,20 +22,22 @@ func SmcGetKey() kyber.Point {
}
defer resp.Body.Close()

decoder := json.NewDecoder(resp.Body)
// Check if the status code is OK
if resp.StatusCode != http.StatusOK {
log.Fatal().Msgf("Error received from server: %v", resp)
}

// Decode the response
var data []byte
err = decoder.Decode(&data)
// Read the response body into a byte array
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal().Msgf("error: %v", err)
}

// Unmarshal the response
pk := suite.Point()
err = pk.UnmarshalBinary(data)
err = pk.UnmarshalBinary(body)
if err != nil {
log.Error().Msgf("error decoding response: %v", err)
log.Error().Msgf("Error unmarshaling the pubkey: %v", err)
}

return pk
Expand Down

0 comments on commit 6c9f49a

Please sign in to comment.