-
Notifications
You must be signed in to change notification settings - Fork 41
/
multiwallet_utils_test.go
49 lines (40 loc) · 1.2 KB
/
multiwallet_utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package dcrlibwallet
import (
"bytes"
"math/rand"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
// genPass generates a random []byte
func genPass() []byte {
pass := make([]byte, rand.Intn(32))
_, err := rand.Read(pass)
Expect(err).To(BeNil())
return pass
}
var _ = Describe("MultiwalletUtils", func() {
Describe("Wallet Seed Encryption", func() {
Context("encryptWalletSeed and decryptWalletSeed", func() {
It("encrypts and decrypts the wallet seed properly", func() {
pass := genPass()
fakePass := genPass()
for bytes.Equal(pass, fakePass) {
fakePass = genPass()
}
seed, err := GenerateSeed()
Expect(err).To(BeNil())
By("Encrypting the seed with the password")
encrypted, err := encryptWalletSeed(pass, seed)
Expect(err).To(BeNil())
By("Failing decryption of the encrypted seed using the wrong password")
_, err = decryptWalletSeed(fakePass, encrypted)
Expect(err).ToNot(BeNil())
By("Decrypting the encrypted seed using the correct password")
decrypted, err := decryptWalletSeed(pass, encrypted)
Expect(err).To(BeNil())
By("Comparing the decrypted and original seeds")
Expect(seed).To(Equal(decrypted))
})
})
})
})