Created
September 11, 2014 16:32
-
-
Save gsalgado/085fd73dc94807c1e676 to your computer and use it in GitHub Desktop.
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
diff --git a/waddrmgr/internal_test.go b/waddrmgr/internal_test.go | |
index 2868772..8a5bfe1 100644 | |
--- a/waddrmgr/internal_test.go | |
+++ b/waddrmgr/internal_test.go | |
@@ -186,3 +189,10 @@ func TestDecryptExtendedKeyCannotCreateResultKey(t *testing.T) { | |
} | |
} | |
} | |
+ | |
+func RunWithReplacedManagerCryptoKeyScript(vp *VotingPool, cryptoKey EncryptorDecryptor, fn func()) { | |
+ orig := vp.manager.cryptoKeyScript | |
+ vp.manager.cryptoKeyScript = cryptoKey | |
+ fn() | |
+ vp.manager.cryptoKeyScript = orig | |
+} | |
diff --git a/waddrmgr/pool_test.go b/waddrmgr/pool_test.go | |
index 0369af8..46084f7 100644 | |
--- a/waddrmgr/pool_test.go | |
+++ b/waddrmgr/pool_test.go | |
@@ -19,6 +19,7 @@ package waddrmgr_test | |
import ( | |
"bytes" | |
"encoding/hex" | |
+ "errors" | |
"fmt" | |
"io/ioutil" | |
"os" | |
@@ -248,6 +249,37 @@ func TestDepositScriptAddressForHardenedPubKey(t *testing.T) { | |
} | |
} | |
+type FailingToEncryptCryptoKey struct { | |
+ waddrmgr.CryptoKey | |
+} | |
+ | |
+func (c *FailingToEncryptCryptoKey) Encrypt(in []byte) ([]byte, error) { | |
+ return nil, errors.New("failed to encrypt") | |
+} | |
+ | |
+func TestDepositScriptAddressFailureToEncrypt(t *testing.T) { | |
+ tearDown, _, pool := setUp(t) | |
+ defer tearDown() | |
+ if err := pool.CreateSeries(0, []string{pubKey0, pubKey1, pubKey2}, 2); err != nil { | |
+ t.Fatalf("Cannot creates series") | |
+ } | |
+ | |
+ var err error | |
+ waddrmgr.RunWithReplacedManagerCryptoKeyScript( | |
+ pool, &FailingToEncryptCryptoKey{}, func() { | |
+ _, err = pool.DepositScriptAddress(0, 0, uint32(1)) | |
+ }) | |
+ | |
+ if err == nil { | |
+ t.Fatalf("Expected an error, got none") | |
+ } else { | |
+ rerr := err.(waddrmgr.ManagerError) | |
+ if waddrmgr.ErrCrypto != rerr.ErrorCode { | |
+ t.Errorf("Expected ErrCrypto, got %v", rerr.ErrorCode) | |
+ } | |
+ } | |
+} | |
+ | |
func TestCreateVotingPool(t *testing.T) { | |
tearDown, mgr, pool := setUp(t) | |
defer tearDown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment