github.com/igggame/nebulas-go@v2.1.0+incompatible/crypto/hash/hash_test.go (about) 1 // Copyright (C) 2017 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // the go-nebulas library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with the go-nebulas library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 19 package hash 20 21 import ( 22 "reflect" 23 "testing" 24 ) 25 26 func TestSha3256(t *testing.T) { 27 type args struct { 28 bytes []byte 29 } 30 tests := []struct { 31 name string 32 args args 33 wantDigest []byte 34 }{ 35 { 36 "blank string", 37 args{[]byte("")}, 38 []byte{167, 255, 198, 248, 191, 30, 215, 102, 81, 193, 71, 86, 160, 97, 214, 98, 245, 128, 255, 77, 228, 59, 73, 250, 130, 216, 10, 75, 128, 248, 67, 74}, 39 }, 40 { 41 "Hello, world", 42 args{[]byte("Hello, world")}, 43 []byte{53, 80, 171, 169, 116, 146, 222, 56, 175, 48, 102, 240, 21, 127, 197, 50, 219, 103, 145, 179, 125, 83, 38, 44, 231, 104, 141, 204, 93, 70, 24, 86}, 44 }, 45 { 46 "https://nebulas.io", 47 args{[]byte("https://nebulas.io")}, 48 []byte{94, 159, 238, 157, 152, 227, 18, 248, 53, 8, 13, 247, 231, 21, 17, 14, 172, 34, 192, 157, 24, 175, 119, 254, 126, 208, 174, 17, 14, 77, 1, 55}, 49 }, 50 } 51 52 for _, tt := range tests { 53 t.Run(tt.name, func(t *testing.T) { 54 if gotDigest := Sha3256(tt.args.bytes); !reflect.DeepEqual(gotDigest, tt.wantDigest) { 55 t.Errorf("Sha3256() = %v, want %v", gotDigest, tt.wantDigest) 56 } 57 }) 58 } 59 } 60 61 func TestRipemd160(t *testing.T) { 62 type args struct { 63 bytes []byte 64 } 65 tests := []struct { 66 name string 67 args args 68 wantDigest []byte 69 }{ 70 { 71 "blank string", 72 args{[]byte("")}, 73 []byte{156, 17, 133, 165, 197, 233, 252, 84, 97, 40, 8, 151, 126, 232, 245, 72, 178, 37, 141, 49}, 74 }, 75 { 76 "The quick brown fox jumps over the lazy dog", 77 args{[]byte("The quick brown fox jumps over the lazy dog")}, 78 []byte{55, 243, 50, 246, 141, 183, 123, 217, 215, 237, 212, 150, 149, 113, 173, 103, 28, 249, 221, 59}, 79 }, 80 { 81 "The quick brown fox jumps over the lazy cog", 82 args{[]byte("The quick brown fox jumps over the lazy cog")}, 83 []byte{19, 32, 114, 223, 105, 9, 51, 131, 94, 184, 182, 173, 11, 119, 231, 182, 241, 74, 202, 215}, 84 }, 85 } 86 for _, tt := range tests { 87 t.Run(tt.name, func(t *testing.T) { 88 if gotDigest := Ripemd160(tt.args.bytes); !reflect.DeepEqual(gotDigest, tt.wantDigest) { 89 t.Errorf("Ripemd160() = %v, want %v", gotDigest, tt.wantDigest) 90 } 91 }) 92 } 93 } 94 95 func TestSha256(t *testing.T) { 96 type args struct { 97 bytes []byte 98 } 99 tests := []struct { 100 name string 101 args args 102 wantDigest []byte 103 }{ 104 { 105 "", 106 args{[]byte("")}, 107 []byte{227, 176, 196, 66, 152, 252, 28, 20, 154, 251, 244, 200, 153, 111, 185, 36, 39, 174, 65, 228, 100, 155, 147, 76, 164, 149, 153, 27, 120, 82, 184, 85}, 108 }, 109 { 110 "Hello, world!0", 111 args{[]byte("Hello, world!0")}, 112 []byte{19, 18, 175, 23, 140, 37, 63, 132, 2, 141, 72, 10, 106, 220, 30, 37, 232, 28, 170, 68, 199, 73, 236, 129, 151, 97, 146, 226, 236, 147, 76, 100}, 113 }, 114 { 115 "Hello, world!4250", 116 args{[]byte("Hello, world!4250")}, 117 []byte{0, 0, 195, 175, 66, 252, 49, 16, 63, 31, 220, 1, 81, 250, 116, 127, 248, 115, 73, 164, 113, 77, 247, 204, 82, 234, 70, 78, 18, 220, 212, 233}, 118 }, 119 } 120 for _, tt := range tests { 121 t.Run(tt.name, func(t *testing.T) { 122 if gotDigest := Sha256(tt.args.bytes); !reflect.DeepEqual(gotDigest, tt.wantDigest) { 123 t.Errorf("Sha256() = %v, want %v", gotDigest, tt.wantDigest) 124 } 125 }) 126 } 127 }