Skip to content

Commit

Permalink
fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Oct 14, 2024
1 parent 23b13c4 commit 6f313a6
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 124 deletions.
6 changes: 3 additions & 3 deletions cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,12 +1080,12 @@ func Sync(logger *zap.Logger) error {

func checkIfOperatorHTTPS(ops []wire.OperatorCLI) error {
for _, op := range ops {
url, err := url.Parse(op.Addr)
addr, err := url.Parse(op.Addr)
if err != nil {
return fmt.Errorf("parsing IP address: %s, err: %w", op.Addr, err)
}
if url.Scheme != "https" {
return fmt.Errorf("only HTTPS scheme is allowed at operator address %s, got: %s", op.Addr, url.Scheme)
if addr.Scheme != "https" {
return fmt.Errorf("only HTTPS scheme is allowed at operator address %s, got: %s", op.Addr, addr.Scheme)
}
}
return nil
Expand Down
41 changes: 19 additions & 22 deletions integration_test/reshare_bulk_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package integration_test

import (
"encoding/hex"
"encoding/json"
"os"
"path/filepath"
"strconv"
"strings"
"testing"

"github.com/bloxapp/ssv/logging"
Expand All @@ -16,7 +18,6 @@ import (
"github.com/ssvlabs/dkg-spec/testing/stubs"
cli_initiator "github.com/ssvlabs/ssv-dkg/cli/initiator"
cli_verify "github.com/ssvlabs/ssv-dkg/cli/verify"
"github.com/ssvlabs/ssv-dkg/pkgs/wire"
)

func TestBulkReshareHappyFlows4Ops(t *testing.T) {
Expand Down Expand Up @@ -133,10 +134,9 @@ func TestBulkReshareHappyFlows4Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -146,7 +146,7 @@ func TestBulkReshareHappyFlows4Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -171,7 +171,7 @@ func TestBulkReshareHappyFlows4Ops(t *testing.T) {
require.NoError(t, err)
}
// remove resign message
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
reshareCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -311,10 +311,9 @@ func TestBulkReshareHappyFlows7Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -324,7 +323,7 @@ func TestBulkReshareHappyFlows7Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -349,7 +348,7 @@ func TestBulkReshareHappyFlows7Ops(t *testing.T) {
require.NoError(t, err)
}
// remove resign message
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
reshareCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -489,10 +488,9 @@ func TestBulkReshareHappyFlows10Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -502,7 +500,7 @@ func TestBulkReshareHappyFlows10Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -527,7 +525,7 @@ func TestBulkReshareHappyFlows10Ops(t *testing.T) {
require.NoError(t, err)
}
// remove resign message
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
reshareCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -667,10 +665,9 @@ func TestBulkReshareHappyFlows13Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -680,7 +677,7 @@ func TestBulkReshareHappyFlows13Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -705,7 +702,7 @@ func TestBulkReshareHappyFlows13Ops(t *testing.T) {
require.NoError(t, err)
}
// remove resign message
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
reshareCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -733,7 +730,7 @@ func TestBulkReshareHappyFlows13Ops(t *testing.T) {
// NOTE: Example below how to generate EOA signature

// func TestSignReshare(t *testing.T) {
// msg_path := "../examples/initiator/output/reshare.json"
// msg_path := "../examples/initiator/output/reshare.txt"
// sk_path := "../examples/initiator/UTC--2024-06-14T14-05-12.366668334Z--dcc846fa10c7cfce9e6eb37e06ed93b666cfc5e9"
// password_path := "../examples/initiator/password"

Expand Down
39 changes: 18 additions & 21 deletions integration_test/reshare_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package integration_test

import (
"encoding/hex"
"encoding/json"
"os"
"path/filepath"
"strconv"
"strings"
"testing"

"github.com/bloxapp/ssv/logging"
Expand All @@ -13,7 +15,6 @@ import (
"github.com/spf13/cobra"
cli_initiator "github.com/ssvlabs/ssv-dkg/cli/initiator"
cli_verify "github.com/ssvlabs/ssv-dkg/cli/verify"
"github.com/ssvlabs/ssv-dkg/pkgs/wire"
"github.com/stretchr/testify/require"

"github.com/ssvlabs/dkg-spec/testing/stubs"
Expand Down Expand Up @@ -105,10 +106,9 @@ func TestReshareHappyFlows4Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -118,7 +118,7 @@ func TestReshareHappyFlows4Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

// start resharing
Expand All @@ -144,7 +144,7 @@ func TestReshareHappyFlows4Ops(t *testing.T) {
require.NoError(t, err)
}
// remove reshare file
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
resignCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -254,10 +254,9 @@ func TestReshareHappyFlows7Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -267,7 +266,7 @@ func TestReshareHappyFlows7Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -292,7 +291,7 @@ func TestReshareHappyFlows7Ops(t *testing.T) {
require.NoError(t, err)
}
// remove reshare file
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
resignCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -402,10 +401,9 @@ func TestReshareHappyFlows10Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -415,7 +413,7 @@ func TestReshareHappyFlows10Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -440,7 +438,7 @@ func TestReshareHappyFlows10Ops(t *testing.T) {
require.NoError(t, err)
}
// remove reshare file
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
resignCeremonies, err := os.ReadDir("./output")
Expand Down Expand Up @@ -550,10 +548,9 @@ func TestReshareHappyFlows13Ops(t *testing.T) {
resetFlags(RootCmd)

// load reshare message
reshareMsgBytes, err := os.ReadFile("./output/reshare.json")
reshareMsgBytes, err := os.ReadFile("./output/reshare.txt")
require.NoError(t, err)
reshareMsg := make([]*wire.ReshareMessage, 0)
err = json.Unmarshal(reshareMsgBytes, &reshareMsg)
hash, err := hex.DecodeString(strings.TrimPrefix(string(reshareMsgBytes), "0x"))
require.NoError(t, err)

// sign reshare message
Expand All @@ -563,7 +560,7 @@ func TestReshareHappyFlows13Ops(t *testing.T) {
require.NoError(t, err)
sk, err := keystore.DecryptKey(jsonBytes, string(keyStorePassword))
require.NoError(t, err)
signature, err := SignReshare(reshareMsg, sk.PrivateKey)
signature, err := SignHash(hash, sk.PrivateKey)
require.NoError(t, err)

args := []string{"reshare",
Expand All @@ -588,7 +585,7 @@ func TestReshareHappyFlows13Ops(t *testing.T) {
require.NoError(t, err)
}
// remove reshare file
err = os.Remove("./output/reshare.json")
err = os.Remove("./output/reshare.txt")
require.NoError(t, err)
// validate reshare results
resignCeremonies, err := os.ReadDir("./output")
Expand Down
Loading

0 comments on commit 6f313a6

Please sign in to comment.