Skip to content

Commit db19dfa

Browse files
committed
[tests] add test case for RIPEMD160 precompile
1 parent de9cc2d commit db19dfa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/t_ethereum_evm_precompiles.nim

+29
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,38 @@ proc testSha256() =
130130

131131
stdout.write "Success\n"
132132

133+
proc testRipemd160() =
134+
# https://github.com/ethereum/go-ethereum/blob/v1.14.0/core/vm/contracts_test.go#L216-L224
135+
let input = "38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e000000000000000000000000000000000000000000000000000000000000001b38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e789d1dd423d25f0772d2748d60f7e4b81bb14d086eba8e8e8efb6dcff8a4ae02"
136+
let expected = "0000000000000000000000009215b8d9882ff46f0dfde6684d78e831467f65e6"
137+
138+
echo "Running RIPEMD160 tests"
139+
stdout.write " Testing RIPEMD160 ... "
140+
141+
var inputbytes = newSeq[byte](input.len div 2)
142+
inputbytes.fromHex(input)
143+
144+
var expectedbytes = newSeq[byte](expected.len div 2)
145+
expectedbytes.fromHex(expected)
146+
147+
var r = newSeq[byte](expected.len div 2)
148+
149+
let status = eth_evm_ripemd160(r, inputbytes)
150+
if status != cttEVM_Success:
151+
reset(r)
152+
153+
doAssert r == expectedbytes, "[Test Failure]\n" &
154+
" eth_evm_ripemd160 status: " & $status & "\n" &
155+
" " & "result: " & r.toHex() & "\n" &
156+
" " & "expected: " & expectedbytes.toHex() & '\n'
157+
158+
stdout.write "Success\n"
159+
160+
133161
# ----------------------------------------------------------------------
134162

135163
testSha256()
164+
testRipemd160()
136165

137166
runPrecompileTests("modexp.json", eth_evm_modexp, 0)
138167
runPrecompileTests("modexp_eip2565.json", eth_evm_modexp, 0)

0 commit comments

Comments
 (0)