[node.sh] added more end to end test cases

pull/3219/head
Jacky Wang 4 years ago
parent 0a13765a51
commit 80836edcdd
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 2
      cmd/harmony/blsloader/console.go
  2. 12
      cmd/harmony/blsloader/console_test.go
  3. 5
      cmd/harmony/blsloader/helper.go
  4. 66
      cmd/harmony/blsloader/loader_test.go
  5. 4
      cmd/harmony/blsloader/utils.go

@ -24,10 +24,12 @@ type consoleItf interface {
type stdConsole struct{}
func (console *stdConsole) readPassword() (string, error) {
fmt.Println("trapped")
b, err := terminal.ReadPassword(syscall.Stdin)
if err != nil {
return "", err
}
fmt.Println("escaped")
return strings.TrimSpace(string(b)), nil
}

@ -22,18 +22,20 @@ func newTestConsole() *testConsole {
}
func (tc *testConsole) readPassword() (string, error) {
fmt.Println("reading password")
return tc.readln()
}
func (tc *testConsole) readln() (string, error) {
select {
case <-time.After(10 * time.Second):
case <-time.After(2 * time.Second):
fmt.Println("timed out")
return "", errors.New("timed out")
case <-tc.In:
msg, ok := <-tc.In
case msg, ok := <-tc.In:
if !ok {
return "", errors.New("in channel closed")
}
fmt.Println("read in")
return msg, nil
}
}
@ -54,12 +56,16 @@ func (tc *testConsole) printf(format string, a ...interface{}) {
}
func (tc *testConsole) checkClean() (bool, string) {
fmt.Println("check clean")
select {
case msg := <-tc.In:
fmt.Println("not good")
return false, "extra in message: " + msg
case msg := <-tc.Out:
fmt.Println("not good")
return false, "extra out message: " + msg
default:
fmt.Println("good")
return true, ""
}
}

@ -6,6 +6,8 @@ import (
"os"
"path/filepath"
"github.com/harmony-one/harmony/crypto/bls"
bls_core "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/multibls"
)
@ -24,17 +26,20 @@ type basicSingleBlsLoader struct {
// loadKeys load bls keys from a single bls file
func (loader *basicSingleBlsLoader) loadKeys() (multibls.PrivateKeys, error) {
fmt.Println("load keys")
providers, err := loader.getPassProviders()
if err != nil {
fmt.Println("not loaded 1")
return multibls.PrivateKeys{}, err
}
fmt.Println("provider got")
secretKey, err := loadBasicKey(loader.blsKeyFile, providers)
if err != nil {
fmt.Println("not loaded 2")
return multibls.PrivateKeys{}, err
}
fmt.Println("loaded secret key")
console.printf("loaded bls key %x\n", bls.WrapperFromPrivateKey(secretKey).Pub.Bytes)
return multibls.GetPrivateKeys(secretKey), nil
}

@ -89,16 +89,73 @@ func TestLoadKeys_SingleBls_File(t *testing.T) {
expErr error
}{
{
// load the default pass file
// load the default pass file with file
cfg: Config{
BlsKeyFile: &validTestKeys[0].path,
PassSrcType: PassSrcFile,
},
inputs: []string{},
expOutputs: []string{},
expOutputs: []string{
fmt.Sprintf("loaded bls key %s\n", validTestKeys[0].publicKey),
},
expPubKeys: []string{validTestKeys[0].publicKey},
},
{
// load the default pass file with file
cfg: Config{
BlsKeyFile: &validTestKeys[1].path,
PassSrcType: PassSrcFile,
},
inputs: []string{},
expOutputs: []string{
fmt.Sprintf("loaded bls key %s\n", validTestKeys[1].publicKey),
},
expPubKeys: []string{validTestKeys[1].publicKey},
},
{
// load key file with prompt
cfg: Config{
BlsKeyFile: &validTestKeys[1].path,
PassSrcType: PassSrcPrompt,
},
inputs: []string{validTestKeys[1].passphrase},
expOutputs: []string{
fmt.Sprintf("Enter passphrase for the BLS key file %s:", validTestKeys[1].path),
fmt.Sprintf("loaded bls key %s\n", validTestKeys[1].publicKey),
},
expPubKeys: []string{validTestKeys[1].publicKey},
},
{
// Automatically use pass file
cfg: Config{
BlsKeyFile: &validTestKeys[1].path,
PassSrcType: PassSrcAuto,
},
inputs: []string{},
expOutputs: []string{
fmt.Sprintf("loaded bls key %s\n", validTestKeys[1].publicKey),
},
expPubKeys: []string{validTestKeys[1].publicKey},
},
{
// Automatically use prompt
cfg: Config{
BlsKeyFile: &emptyPassTestKeys[1].path,
PassSrcType: PassSrcAuto,
},
inputs: []string{emptyPassTestKeys[1].passphrase},
expOutputs: []string{
"unable to get passphrase from passphrase file testData/blskey_emptypass/152beed46d7a0002ef0f960946008887eedd4775bdf2ed238809aa74e20d31fdca267443615cc6f4ede49d58911ee083.pass: cannot open passphrase file\n",
fmt.Sprintf("Enter passphrase for the BLS key file %s:", emptyPassTestKeys[1].path),
fmt.Sprintf("loaded bls key %s\n", emptyPassTestKeys[1].publicKey),
},
expPubKeys: []string{emptyPassTestKeys[1].publicKey},
},
}
for i, test := range tests {
ts := &testSuite{
@ -174,6 +231,8 @@ func (ts *testSuite) checkResult() error {
return err
default:
}
fmt.Println("got outputs:", ts.gotOutputs)
fmt.Println("expect outputs:", ts.expOutputs)
if isClean, msg := ts.console.checkClean(); !isClean {
return fmt.Errorf("console not clean: %v", msg)
}
@ -183,6 +242,9 @@ func (ts *testSuite) checkResult() error {
if err := ts.checkKeys(); err != nil {
return err
}
if err := ts.checkOutputs(); err != nil {
return err
}
return nil
}

@ -28,7 +28,7 @@ func loadBasicKey(blsKeyFile string, pps []passProvider) (*bls_core.SecretKey, e
secretKey, err := loadBasicKeyWithProvider(blsKeyFile, pp)
if err != nil {
console.println(err)
return nil, err
continue
}
return secretKey, nil
}
@ -108,7 +108,9 @@ func promptGetPassword(prompt string) (string, error) {
if !strings.HasSuffix(prompt, ":") {
prompt += ":"
}
fmt.Println("before print prompt", prompt)
console.print(prompt)
fmt.Println("after print prompt", prompt)
return console.readPassword()
}

Loading…
Cancel
Save