Added a few more test cases for the memo decoding
This commit is contained in:
parent
1004873d98
commit
8b7b3deafe
1 changed files with 21 additions and 0 deletions
|
@ -57,6 +57,14 @@ public class MemoTest {
|
||||||
destinationAddress = new Address(publicKey.getKey());
|
destinationAddress = new Address(publicKey.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canObtainSharedSecret(){
|
||||||
|
byte[] secret1 = sourcePrivate.getPubKeyPoint().multiply(destinationPrivate.getPrivKey()).normalize().getXCoord().getEncoded();
|
||||||
|
byte[] secret2 = destinationPrivate.getPubKeyPoint().multiply(sourcePrivate.getPrivKey()).normalize().getXCoord().getEncoded();
|
||||||
|
System.out.println(String.format("Secret 1: %s, Secret 2: %s", Util.bytesToHex(secret1), Util.bytesToHex(secret2)));
|
||||||
|
Assert.assertArrayEquals(secret1, secret2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMatchPredefinedCiphertext(){
|
public void shouldMatchPredefinedCiphertext(){
|
||||||
byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, shortEncryptedMessageNonce, shortMessage);
|
byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, shortEncryptedMessageNonce, shortMessage);
|
||||||
|
@ -118,6 +126,19 @@ public class MemoTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDecryptOwnMessage(){
|
||||||
|
try{
|
||||||
|
BigInteger nonce = new BigInteger("123456789");
|
||||||
|
byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, longerMessage);
|
||||||
|
String decrypted = Memo.decryptMessage(sourcePrivate, destinationAddress, nonce, encrypted);
|
||||||
|
System.out.println("Decrypted: "+decrypted);
|
||||||
|
Assert.assertEquals(longerMessage, decrypted);
|
||||||
|
}catch (ChecksumException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = ChecksumException.class)
|
@Test(expected = ChecksumException.class)
|
||||||
public void shouldThrowException() throws ChecksumException {
|
public void shouldThrowException() throws ChecksumException {
|
||||||
byte[] corrupted = Memo.encryptMessage(sourcePrivate, destinationAddress, longEncryptedMessageNonce, longerMessage);
|
byte[] corrupted = Memo.encryptMessage(sourcePrivate, destinationAddress, longEncryptedMessageNonce, longerMessage);
|
||||||
|
|
Loading…
Reference in a new issue