diff --git a/src/main/scala/com/github/fluency03/blockchain/package.scala b/src/main/scala/com/github/fluency03/blockchain/package.scala index 6f86fcd..5f85872 100644 --- a/src/main/scala/com/github/fluency03/blockchain/package.scala +++ b/src/main/scala/com/github/fluency03/blockchain/package.scala @@ -48,7 +48,7 @@ package object blockchain { def toBase64: String = base64Of(bytes) def toSha256: String = SHA256.hash(bytes) def toSha256Digest: Bytes = SHA256.hashToDigest(bytes) - def toRipemd160Of: String = RIPEMD160.hash(bytes) + def toRipemd160: String = RIPEMD160.hash(bytes) def toRipemd160ODigest: Bytes = RIPEMD160.hashToDigest(bytes) def toHash160: String = RIPEMD160.doubleHash(bytes) def toHash160Digest: Bytes = RIPEMD160.doubleHashToDigest(bytes) diff --git a/src/test/scala/com/github/fluency03/blockchain/UtilTest.scala b/src/test/scala/com/github/fluency03/blockchain/BlockchainPackageTest.scala similarity index 66% rename from src/test/scala/com/github/fluency03/blockchain/UtilTest.scala rename to src/test/scala/com/github/fluency03/blockchain/BlockchainPackageTest.scala index fcca1cb..45bbceb 100644 --- a/src/test/scala/com/github/fluency03/blockchain/UtilTest.scala +++ b/src/test/scala/com/github/fluency03/blockchain/BlockchainPackageTest.scala @@ -5,7 +5,7 @@ import java.time.format.DateTimeParseException import org.scalamock.scalatest.MockFactory import org.scalatest.{FlatSpec, Matchers} -class UtilTest extends FlatSpec with Matchers with MockFactory { +class BlockchainPackageTest extends FlatSpec with Matchers with MockFactory { "getCurrentTimestamp" should "be able to get current Unix epoch time." in { val t1 = getCurrentTimestamp @@ -54,13 +54,34 @@ class UtilTest extends FlatSpec with Matchers with MockFactory { "open sesame".toSha256 shouldEqual "41ef4bb0b23661e66301aac36066912dac037827b4ae63a7b1165a5aa93ed4eb" "".toSha256 shouldEqual "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" "a".hex2Binary shouldEqual "1010" + "a".hex2BigInt shouldEqual BigInt(10) "ab".hex2Binary shouldEqual "10101011" + "ab".hex2BigInt shouldEqual BigInt(171) + "bitcoin".toRipemd160 shouldEqual "5891bf40b0b0e8e19f524bdc2e842d012264624b" + "blockchain".toRipemd160 shouldEqual "5c403af45cae136a79eea3c7e9f79c3dd049776b" } "BytesImplicit" should "convert Array of Byte to corresponding type." in { val bytes: Bytes = Array(192.toByte, 168.toByte, 1, 9) bytes.toHex shouldEqual "c0a80109" bytes.toBase64 shouldEqual "wKgBCQ==" + "open sesame".getBytes.toSha256 shouldEqual "41ef4bb0b23661e66301aac36066912dac037827b4ae63a7b1165a5aa93ed4eb" + "open sesame".getBytes.toSha256Digest shouldEqual ("41ef4bb0b23661e66301aac36066912da" + + "c037827b4ae63a7b1165a5aa93ed4eb").hex2Bytes + + "173BDED8F2A2069C193E63EA30DC8FD20E815EC3642B9C24AD7002C03D1BFB9B".hex2Bytes.toRipemd160 shouldEqual + "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".toLowerCase + + "173BDED8F2A2069C193E63EA30DC8FD20E815EC3642B9C24AD7002C03D1BFB9B".hex2Bytes.toRipemd160ODigest shouldEqual + "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".hex2Bytes + + ("04b4d653fcbb4b96000c99343f23b08a44fa306031e0587f9e657ab4a25411" + + "29368d7d9bb05cd8afbdf7705a6540d98028236965553f91bf1c5b4f70073f55b55d").hex2Bytes.toHash160Digest shouldEqual + "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".hex2Bytes + + ("04b4d653fcbb4b96000c99343f23b08a44fa306031e0587f9e657ab4a25411" + + "29368d7d9bb05cd8afbdf7705a6540d98028236965553f91bf1c5b4f70073f55b55d").hex2Bytes.toHash160 shouldEqual + "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".toLowerCase } "genesisTimestamp" should "be the Epoch time of 2018-04-11T18:52:01Z ." in { diff --git a/src/test/scala/com/github/fluency03/blockchain/RIPEMD160Test.scala b/src/test/scala/com/github/fluency03/blockchain/RIPEMD160Test.scala index c23a71e..f99b72e 100644 --- a/src/test/scala/com/github/fluency03/blockchain/RIPEMD160Test.scala +++ b/src/test/scala/com/github/fluency03/blockchain/RIPEMD160Test.scala @@ -13,6 +13,10 @@ class RIPEMD160Test extends FlatSpec with Matchers { "29368d7d9bb05cd8afbdf7705a6540d98028236965553f91bf1c5b4f70073f55b55d").hex2Bytes) shouldEqual "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".hex2Bytes + RIPEMD160.doubleHash(("04b4d653fcbb4b96000c99343f23b08a44fa306031e0587f9e657ab4a25411" + + "29368d7d9bb05cd8afbdf7705a6540d98028236965553f91bf1c5b4f70073f55b55d").hex2Bytes) shouldEqual + "88C2D2FA846282C870A76CADECBE45C4ACD72BB6".toLowerCase + RIPEMD160.hash("61956bf4e271df1cd88a9a7828a59c88eb7ea13c176c4d03355ac27129760673") shouldEqual "352b0b6bd7284755d5c685fb7793c9f4d672c5ff" RIPEMD160.hash("abcd") shouldEqual "2e7e536fd487deaa943fda5522d917bdb9011b7a" @@ -20,8 +24,6 @@ class RIPEMD160Test extends FlatSpec with Matchers { RIPEMD160.hash("bitcoin") shouldEqual "5891bf40b0b0e8e19f524bdc2e842d012264624b" RIPEMD160.hash("blockchain") shouldEqual "5c403af45cae136a79eea3c7e9f79c3dd049776b" - - } }