@@ -29,6 +29,70 @@ func TestSha256(t *testing.T) {
29
29
require .Equal (t , "47dc540c94ceb704a23875c11273e16bb0b8a87aed84de911f2133568115f254" , hex .EncodeToString (c .sha256 (ic , []stackitem.Item {stackitem .NewByteArray ([]byte {1 , 0 })}).Value ().([]byte )))
30
30
})
31
31
}
32
+ func TestKeccak256 (t * testing.T ) {
33
+ c := newCrypto ()
34
+ ic := & interop.Context {VM : vm .New ()}
35
+
36
+ t .Run ("bad arg type" , func (t * testing.T ) {
37
+ require .Panics (t , func () {
38
+ c .keccak256 (ic , []stackitem.Item {stackitem .NewInterop (nil )})
39
+ })
40
+ })
41
+ t .Run ("good" , func (t * testing.T ) {
42
+ // 0x0100 hashes to 628bf3596747d233f1e6533345700066bf458fa48daedaf04a7be6c392902476
43
+ require .Equal (t , "628bf3596747d233f1e6533345700066bf458fa48daedaf04a7be6c392902476" , hex .EncodeToString (c .keccak256 (ic , []stackitem.Item {stackitem .NewByteArray ([]byte {1 , 0 })}).Value ().([]byte )))
44
+ })
45
+
46
+ t .Run ("hello world" , func (t * testing.T ) {
47
+ inputData := []byte ("Hello, World!" )
48
+ expectedHashHex := "acaf3289d7b601cbd114fb36c4d29c85bbfd5e133f14cb355c3fd8d99367964f"
49
+
50
+ result := c .keccak256 (ic , []stackitem.Item {stackitem .NewByteArray (inputData )}).Value ().([]byte )
51
+ outputHashHex := hex .EncodeToString (result )
52
+
53
+ require .Equal (t , expectedHashHex , outputHashHex )
54
+ })
55
+
56
+ t .Run ("cryptography" , func (t * testing.T ) {
57
+ inputData := []byte ("Cryptography" )
58
+ expectedHashHex := "53d49d225dd2cfe77d8c5e2112bcc9efe77bea1c7aa5e5ede5798a36e99e2d29"
59
+
60
+ result := c .keccak256 (ic , []stackitem.Item {stackitem .NewByteArray (inputData )}).Value ().([]byte )
61
+ outputHashHex := hex .EncodeToString (result )
62
+
63
+ require .Equal (t , expectedHashHex , outputHashHex )
64
+ })
65
+
66
+ t .Run ("testing123" , func (t * testing.T ) {
67
+ inputData := []byte ("Testing123" )
68
+ expectedHashHex := "3f82db7b16b0818a1c6b2c6152e265f682d5ebcf497c9aad776ad38bc39cb6ca"
69
+
70
+ result := c .keccak256 (ic , []stackitem.Item {stackitem .NewByteArray (inputData )}).Value ().([]byte )
71
+ outputHashHex := hex .EncodeToString (result )
72
+
73
+ require .Equal (t , expectedHashHex , outputHashHex )
74
+ })
75
+
76
+ t .Run ("long string" , func (t * testing.T ) {
77
+ inputData := []byte ("This is a longer string for Keccak256 testing purposes." )
78
+ expectedHashHex := "24115e5c2359f85f6840b42acd2f7ea47bc239583e576d766fa173bf711bdd2f"
79
+
80
+ result := c .keccak256 (ic , []stackitem.Item {stackitem .NewByteArray (inputData )}).Value ().([]byte )
81
+ outputHashHex := hex .EncodeToString (result )
82
+
83
+ require .Equal (t , expectedHashHex , outputHashHex )
84
+ })
85
+
86
+ t .Run ("blanc string" , func (t * testing.T ) {
87
+ inputData := []byte ("" )
88
+ expectedHashHex := "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
89
+
90
+ result := c .keccak256 (ic , []stackitem.Item {stackitem .NewByteArray (inputData )}).Value ().([]byte )
91
+ outputHashHex := hex .EncodeToString (result )
92
+
93
+ require .Equal (t , expectedHashHex , outputHashHex )
94
+ })
95
+ }
32
96
33
97
func TestRIPEMD160 (t * testing.T ) {
34
98
c := newCrypto ()
0 commit comments