From 20d337d39a83d8ff827a8ce9f7f4a63b0e7099a9 Mon Sep 17 00:00:00 2001 From: fluency03 Date: Sun, 6 May 2018 15:46:54 +0200 Subject: [PATCH] add tests for crypto --- .../com/github/fluency03/blockchain/package.scala | 1 - .../fluency03/blockchain/crypto/Base58Test.scala | 3 +++ .../fluency03/blockchain/crypto/RIPEMD160Test.scala | 3 +++ .../fluency03/blockchain/crypto/SHA256Test.scala | 13 ++++++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/github/fluency03/blockchain/package.scala b/src/main/scala/com/github/fluency03/blockchain/package.scala index 49afe74..e42fd1a 100644 --- a/src/main/scala/com/github/fluency03/blockchain/package.scala +++ b/src/main/scala/com/github/fluency03/blockchain/package.scala @@ -7,7 +7,6 @@ import java.time.Instant import com.github.fluency03.blockchain.crypto.Secp256k1.{privateKeyToHex, publicKeyToHex} import com.github.fluency03.blockchain.core.{Peer, PeerSimple, TxIn, TxOut} import com.github.fluency03.blockchain.crypto.{RIPEMD160, SHA256} -import org.bouncycastle.crypto.digests.RIPEMD160Digest import org.bouncycastle.util.encoders.{Base64, Hex} import org.json4s.native.Serialization import org.json4s.{Formats, NoTypeHints} diff --git a/src/test/scala/com/github/fluency03/blockchain/crypto/Base58Test.scala b/src/test/scala/com/github/fluency03/blockchain/crypto/Base58Test.scala index 284bf33..c66a509 100644 --- a/src/test/scala/com/github/fluency03/blockchain/crypto/Base58Test.scala +++ b/src/test/scala/com/github/fluency03/blockchain/crypto/Base58Test.scala @@ -29,6 +29,9 @@ class Base58Test extends FlatSpec with Matchers { Base58.encodeHex("0088C2D2FA846282C870A76CADECBE45C4ACD72BB655DA1216") shouldEqual "1DU8Hi1sbHTpEP9vViBEkEw6noeUrgKkJH" + Base58.encodeHex("00A6020CF86FECEDEEF8859C172BAA1A15A575BC6F27D7CF19") shouldEqual + "1G8mdKwihfYAxeb2E7XwtE94myognJxibS" + } } diff --git a/src/test/scala/com/github/fluency03/blockchain/crypto/RIPEMD160Test.scala b/src/test/scala/com/github/fluency03/blockchain/crypto/RIPEMD160Test.scala index 0b9a2c4..dc5294f 100644 --- a/src/test/scala/com/github/fluency03/blockchain/crypto/RIPEMD160Test.scala +++ b/src/test/scala/com/github/fluency03/blockchain/crypto/RIPEMD160Test.scala @@ -25,6 +25,9 @@ class RIPEMD160Test extends FlatSpec with Matchers { RIPEMD160.hash("bitcoin") shouldEqual "5891bf40b0b0e8e19f524bdc2e842d012264624b" RIPEMD160.hash("blockchain") shouldEqual "5c403af45cae136a79eea3c7e9f79c3dd049776b" + RIPEMD160.hash("0261107E41495C0DDC3850CD205D32896133EDD2ADDEBE7D8E20E01EFD078710".hex2Bytes) shouldEqual + "A6020CF86FECEDEEF8859C172BAA1A15A575BC6F".toLowerCase + } } diff --git a/src/test/scala/com/github/fluency03/blockchain/crypto/SHA256Test.scala b/src/test/scala/com/github/fluency03/blockchain/crypto/SHA256Test.scala index 7fc946e..a3cc0cd 100644 --- a/src/test/scala/com/github/fluency03/blockchain/crypto/SHA256Test.scala +++ b/src/test/scala/com/github/fluency03/blockchain/crypto/SHA256Test.scala @@ -22,12 +22,23 @@ class SHA256Test extends FlatSpec with Matchers { SHA256.hash("0088C2D2FA846282C870A76CADECBE45C4ACD72BB6".hex2Bytes) shouldEqual "1F87490FC565C795595563D56412A0100CD1F29FFB60A3779789FE0C018C6164".toLowerCase - SHA256.hash("1F87490FC565C795595563D56412A0100CD1F29FFB60A3779789FE0C018C6164".hex2Bytes) shouldEqual "55DA1216A5EF5BAE605B543A5A9CE2AC8A8FA1781AA037F35DE3F2222BAD8127".toLowerCase SHA256.hashToDigest("00".hex2Bytes ++ "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".hex2Bytes) shouldEqual "1F87490FC565C795595563D56412A0100CD1F29FFB60A3779789FE0C018C6164".hex2Bytes + + SHA256.hash(("048FEF639C6FA82AB575532B5B9A4552A6FDEFF141D788CDF3C7AFBA3" + + "B26C6C34383088C705DF262F644BE0C3CA2C2E4319ADF3075397DF5E599F2B754E6AB667C").hex2Bytes) shouldEqual + "0261107E41495C0DDC3850CD205D32896133EDD2ADDEBE7D8E20E01EFD078710".toLowerCase + + SHA256.hash("00A6020CF86FECEDEEF8859C172BAA1A15A575BC6F".hex2Bytes) shouldEqual + "9C3AC7CD5D2673694C492CC508D788CBCACCDD357956EBCF10BD6C5BDF67AA5C".toLowerCase + + SHA256.hash("9C3AC7CD5D2673694C492CC508D788CBCACCDD357956EBCF10BD6C5BDF67AA5C".hex2Bytes) shouldEqual + "27D7CF19837C3D3F713BDB483CB98A00D2917D5039D71348E90ADC68D2399F6D".toLowerCase + + } }