forked from TrueCloudLab/neoneo-go
keys: improve NEP2 testing
This commit is contained in:
parent
b5b05a969c
commit
951ee383e9
1 changed files with 36 additions and 0 deletions
|
@ -43,3 +43,39 @@ func TestNEP2Decrypt(t *testing.T) {
|
||||||
assert.Equal(t, testCase.Address, address)
|
assert.Equal(t, testCase.Address, address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNEP2DecryptErrors(t *testing.T) {
|
||||||
|
p := "qwerty"
|
||||||
|
|
||||||
|
// Not a base58-encoded value
|
||||||
|
s := "qazwsx"
|
||||||
|
_, err := NEP2Decrypt(s, p)
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
// Valid base58, but not a NEP-2 format.
|
||||||
|
s = "KxhEDBQyyEFymvfJD96q8stMbJMbZUb6D1PmXqBWZDU2WvbvVs9o"
|
||||||
|
_, err = NEP2Decrypt(s, p)
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateNEP2Format(t *testing.T) {
|
||||||
|
// Wrong length.
|
||||||
|
s := []byte("gobbledygook")
|
||||||
|
assert.Error(t, validateNEP2Format(s))
|
||||||
|
|
||||||
|
// Wrong header 1.
|
||||||
|
s = []byte("gobbledygookgobbledygookgobbledygookgob")
|
||||||
|
assert.Error(t, validateNEP2Format(s))
|
||||||
|
|
||||||
|
// Wrong header 2.
|
||||||
|
s[0] = 0x01
|
||||||
|
assert.Error(t, validateNEP2Format(s))
|
||||||
|
|
||||||
|
// Wrong header 3.
|
||||||
|
s[1] = 0x42
|
||||||
|
assert.Error(t, validateNEP2Format(s))
|
||||||
|
|
||||||
|
// OK
|
||||||
|
s[2] = 0xe0
|
||||||
|
assert.NoError(t, validateNEP2Format(s))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue