Skip to content

Commit

Permalink
add tests for implicit String and Bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed May 6, 2018
1 parent 819ea7c commit 3015009
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ 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"
RIPEMD160.hash("205575f4f33a39ff47f569613a694c6321d6cdd7") shouldEqual "bd4e962413308b4a6689aa0e7cff5e419391c3db"
RIPEMD160.hash("bitcoin") shouldEqual "5891bf40b0b0e8e19f524bdc2e842d012264624b"
RIPEMD160.hash("blockchain") shouldEqual "5c403af45cae136a79eea3c7e9f79c3dd049776b"



}

}

0 comments on commit 3015009

Please sign in to comment.