generateOperationFromMnemonicAndValidator err++

This commit is contained in:
David Theodore
2023-02-09 11:42:55 -06:00
parent 111f5bf627
commit c7025d99dd
2 changed files with 30 additions and 1 deletions

View File

@@ -193,7 +193,7 @@ func (c *command) generateOperationFromMnemonicAndValidator(ctx context.Context)
if c.debug {
fmt.Fprintf(os.Stderr, "Gone %d indices without finding the validator, not scanning any further\n", maxDistance)
}
break
return fmt.Errorf("failed to find validator using the provided mnemonic, index=%s, pubkey=%#x", c.validator, validatorInfo.Pubkey)
}
validatorKeyPath := fmt.Sprintf("m/12381/3600/%d/0/0", i)
validatorPrivkey, err := ethutil.PrivateKeyFromSeedAndPath(seed, validatorKeyPath)
@@ -220,6 +220,24 @@ func (c *command) generateOperationFromMnemonicAndValidator(ctx context.Context)
}
func (c *command) generateOperationsFromMnemonicAndPrivateKey(ctx context.Context) error {
// TODO: determine if this method is only for a single account. If so we
// can add tests to verify that the 0'th account of the seed has the same
// private key as the one provided by the user.
/*
// check that the see from the mnemonic is the same as the one from the private key
seed_from_mnemonic, err := util.SeedFromMnemonic(c.mnemonic)
if err != nil {
return err
}
seed_from_private_key, err := util.SeedFromPrivateKey(c.privateKey)
if err != nil {
return err
}
if !bytes.Equal(seed_from_mnemonic, seed_from_private_key) {
return errors.New("the seed from the mnemonic and the seed from the private key are not the same")
}
*/
// Functionally identical to a simple scan, so use that.
return c.generateOperationsFromMnemonic(ctx)
}

View File

@@ -269,6 +269,17 @@ func TestGenerateOperationFromMnemonicAndValidator(t *testing.T) {
},
err: "invalid withdrawal address: failed to obtain execution address: encoding/hex: invalid byte: U+0072 'r'",
},
{
name: "InvalidWithdrawalAddressBeyondMaxDistance",
command: &command{
mnemonic: "struggle kangaroo horn sniff cradle soft ethics thunder cycle illegal flock unaware dynamic cinnamon play enforce card tennis inform parent surprise bring relax tail",
validator: "1",
chainInfo: chainInfo,
signedOperations: make([]*capella.SignedBLSToExecutionChange, 0),
withdrawalAddressStr: "0x8c1Ff978036F2e9d7CC382Eff7B4c8c53C22ac15",
},
err: "failed to find validator using the provided mnemonic, index=1, pubkey=0xb3d89e2f29c712c6a9f8e5a269b97617c4a94dd6f6662ab3b07ce9e5434573f15b5c988cd14bbd5804f77156a8af1cfa",
},
{
name: "UnknownValidatorPubKey",
command: &command{