Skip to content

Commit

Permalink
add tests for crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed May 6, 2018
1 parent 371ca5a commit 20d337d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Base58Test extends FlatSpec with Matchers {
Base58.encodeHex("0088C2D2FA846282C870A76CADECBE45C4ACD72BB655DA1216") shouldEqual
"1DU8Hi1sbHTpEP9vViBEkEw6noeUrgKkJH"

Base58.encodeHex("00A6020CF86FECEDEEF8859C172BAA1A15A575BC6F27D7CF19") shouldEqual
"1G8mdKwihfYAxeb2E7XwtE94myognJxibS"

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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


}

}

0 comments on commit 20d337d

Please sign in to comment.