ec6034e2d9
Rather than disallowing the default account to be renamed as was proposed in #245 (and implemented in #246), the default account name is no longer considered a reserved name by the address manager. Instead, it is simply the initial name used for the first initial account. A database upgrade removes any additional aliases for the default account in the database. This prevents a lookup for some name which is not an account name from mapping to the default account unexpectedly (potentially preventing incorrect account usage from the RPC server due to bad iteraction with default parameters). All unset account names in a JSON-RPC request are expected to be set nil by btcjson. This behavior depends on btcsuite/btcd#399. Additionally, the manager no longer considers the wildcard * to be a reserved account name. Due to poor API decisions, the RPC server overloads the meaning of account fields to optionally allow referring to all accounts at a time, or a single account. This is not a address manager responsibility, though, as a future cleaner API should not use multiple differet meanings for the same field across multiple requests. Therefore, don't burden down future APIs with this quirk and prevent incorrect wildcard usage from the RPC server. Closes #245.
96 lines
3.4 KiB
Go
96 lines
3.4 KiB
Go
/*
|
|
* Copyright (c) 2014 Conformal Systems LLC <info@conformal.com>
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
/*
|
|
This test file is part of the waddrmgr package rather than than the
|
|
waddrmgr_test package so it can bridge access to the internals to properly test
|
|
cases which are either not possible or can't reliably be tested via the public
|
|
interface. The functions are only exported while the tests are being run.
|
|
*/
|
|
|
|
package waddrmgr
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/btcsuite/btcwallet/snacl"
|
|
)
|
|
|
|
// TstMaxRecentHashes makes the unexported maxRecentHashes constant available
|
|
// when tests are run.
|
|
var TstMaxRecentHashes = maxRecentHashes
|
|
|
|
// TstLatestMgrVersion makes the unexported latestMgrVersion variable available
|
|
// for change when the tests are run.
|
|
var TstLatestMgrVersion = &latestMgrVersion
|
|
|
|
// Replace the Manager.newSecretKey function with the given one and calls
|
|
// the callback function. Afterwards the original newSecretKey
|
|
// function will be restored.
|
|
func TstRunWithReplacedNewSecretKey(callback func()) {
|
|
orig := newSecretKey
|
|
defer func() {
|
|
newSecretKey = orig
|
|
}()
|
|
newSecretKey = func(passphrase *[]byte, config *Options) (*snacl.SecretKey, error) {
|
|
return nil, snacl.ErrDecryptFailed
|
|
}
|
|
callback()
|
|
}
|
|
|
|
// TstCheckPublicPassphrase returns true if the provided public passphrase is
|
|
// correct for the manager.
|
|
func (m *Manager) TstCheckPublicPassphrase(pubPassphrase []byte) bool {
|
|
secretKey := snacl.SecretKey{Key: &snacl.CryptoKey{}}
|
|
secretKey.Parameters = m.masterKeyPub.Parameters
|
|
err := secretKey.DeriveKey(&pubPassphrase)
|
|
return err == nil
|
|
}
|
|
|
|
// failingCryptoKey is an implementation of the EncryptorDecryptor interface
|
|
// with intentionally fails when attempting to encrypt or decrypt with it.
|
|
type failingCryptoKey struct {
|
|
cryptoKey
|
|
}
|
|
|
|
// Encrypt intenionally returns a failure when invoked to test error paths.
|
|
//
|
|
// This is part of the EncryptorDecryptor interface implementation.
|
|
func (c *failingCryptoKey) Encrypt(in []byte) ([]byte, error) {
|
|
return nil, errors.New("failed to encrypt")
|
|
}
|
|
|
|
// Decrypt intenionally returns a failure when invoked to test error paths.
|
|
//
|
|
// This is part of the EncryptorDecryptor interface implementation.
|
|
func (c *failingCryptoKey) Decrypt(in []byte) ([]byte, error) {
|
|
return nil, errors.New("failed to decrypt")
|
|
}
|
|
|
|
// TstRunWithFailingCryptoKeyPriv runs the provided callback with the
|
|
// private crypto key replaced with a version that fails to help test error
|
|
// paths.
|
|
func TstRunWithFailingCryptoKeyPriv(m *Manager, callback func()) {
|
|
orig := m.cryptoKeyPriv
|
|
defer func() {
|
|
m.cryptoKeyPriv = orig
|
|
}()
|
|
m.cryptoKeyPriv = &failingCryptoKey{}
|
|
callback()
|
|
}
|
|
|
|
// TstDefaultAccountName is the constant defaultAccountName exported for tests.
|
|
const TstDefaultAccountName = defaultAccountName
|