-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Threshold parameter validation (#112)
* Add assertions for t > n/2 for both key sharding and cosigner daemon start * Show container logs for failed tests * Update tests * Fix set state test * Prefer t.Setenv in tests. Fix error message
- Loading branch information
Showing
5 changed files
with
130 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/crypto/ed25519" | ||
"github.com/tendermint/tendermint/privval" | ||
) | ||
|
||
func TestKey2Shares(t *testing.T) { | ||
tmp := t.TempDir() | ||
|
||
privValidatorKeyFile := filepath.Join(tmp, "priv_validator_key.json") | ||
privValidatorStateFile := filepath.Join(tmp, "priv_validator_state.json") | ||
pv := privval.NewFilePV(ed25519.GenPrivKey(), privValidatorKeyFile, privValidatorStateFile) | ||
pv.Save() | ||
|
||
tcs := []struct { | ||
name string | ||
args []string | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "valid threshold and shares", | ||
args: []string{privValidatorKeyFile, "2", "3"}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "valid threshold and shares 2", | ||
args: []string{privValidatorKeyFile, "3", "5"}, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "threshold exactly half of shares", | ||
args: []string{privValidatorKeyFile, "2", "4"}, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "threshold less than half of shares", | ||
args: []string{privValidatorKeyFile, "1", "3"}, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "threshold exceeds shares", | ||
args: []string{privValidatorKeyFile, "4", "3"}, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "non-numeric threshold and shares", | ||
args: []string{privValidatorKeyFile, "two", "three"}, | ||
expectErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
cmd := CreateCosignerSharesCmd() | ||
cmd.SetOutput(io.Discard) | ||
cmd.SetArgs(tc.args) | ||
err := cmd.Execute() | ||
if tc.expectErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.