1+ # Polywrap Python Client - https://polywrap.io
2+ # SHA3 Wrapper Schema - https://wrappers.io/v/ipfs/QmbYw6XfEmNdR3Uoa7u2U1WRqJEXbseiSoBNBt3yPFnKvi
3+
4+ from pathlib import Path
5+ from polywrap_client import PolywrapClient
6+ from polywrap_core import Uri , InvokerOptions
7+ import hashlib
8+ import pytest
9+ from Crypto .Hash import keccak , SHAKE128 , SHAKE256
10+
11+ client = PolywrapClient ()
12+ uri = Uri (f'fs/{ Path (__file__ ).parent .joinpath ("cases" , "sha3" ).absolute ()} ' )
13+
14+ args = {"message" : "hello polywrap!" }
15+
16+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
17+ async def test_invoke_sha3_512 ():
18+ options = InvokerOptions (uri = uri , method = "sha3_512" , args = args , encode_result = False )
19+ result = await client .invoke (options )
20+ s = hashlib .sha512 ()
21+ s .update (b"hello polywrap!" )
22+ print (result )
23+ assert result .result == s .digest ()
24+
25+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
26+ async def test_invoke_sha3_384 ():
27+ options = InvokerOptions (uri = uri , method = "sha3_384" , args = args , encode_result = False )
28+ result = await client .invoke (options )
29+ s = hashlib .sha384 ()
30+ s .update (b"hello polywrap!" )
31+ assert result .result == s .digest ()
32+
33+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
34+ async def test_invoke_sha3_256 ():
35+ options = InvokerOptions (uri = uri , method = "sha3_256" , args = args , encode_result = False )
36+ result = await client .invoke (options )
37+ s = hashlib .sha256 ()
38+ s .update (b"hello polywrap!" )
39+ assert result .result == s .digest ()
40+
41+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
42+ async def test_invoke_sha3_224 ():
43+ options = InvokerOptions (uri = uri , method = "sha3_224" , args = args , encode_result = False )
44+ result = await client .invoke (options )
45+ s = hashlib .sha224 ()
46+ s .update (b"hello polywrap!" )
47+ assert result .result == s .digest ()
48+
49+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
50+ async def test_invoke_keccak_512 ():
51+ options = InvokerOptions (uri = uri , method = "keccak_512" , args = args , encode_result = False )
52+ result = await client .invoke (options )
53+ k = keccak .new (digest_bits = 512 )
54+ k .update (b'hello polywrap!' )
55+ assert result .result == k .digest ()
56+
57+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
58+ async def test_invoke_keccak_384 ():
59+ options = InvokerOptions (uri = uri , method = "keccak_384" , args = args , encode_result = False )
60+ result = await client .invoke (options )
61+ k = keccak .new (digest_bits = 384 )
62+ k .update (b'hello polywrap!' )
63+ assert result .result == k .digest ()
64+
65+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
66+ async def test_invoke_keccak_256 ():
67+ options = InvokerOptions (uri = uri , method = "keccak_256" , args = args , encode_result = False )
68+ result = await client .invoke (options )
69+ k = keccak .new (digest_bits = 256 )
70+ k .update (b'hello polywrap!' )
71+ assert result .result == k .digest ()
72+
73+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
74+ async def test_invoke_keccak_224 ():
75+ options = InvokerOptions (uri = uri , method = "keccak_224" , args = args , encode_result = False )
76+ result = await client .invoke (options )
77+ k = keccak .new (digest_bits = 224 )
78+ k .update (b'hello polywrap!' )
79+ assert result .result == k .digest ()
80+
81+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
82+ async def test_invoke_hex_keccak_256 ():
83+ options = InvokerOptions (uri = uri , method = "hex_keccak_256" , args = args , encode_result = False )
84+ result = await client .invoke (options )
85+ k = keccak .new (digest_bits = 256 )
86+ k .update (b'hello polywrap!' )
87+ assert result .result == k .hexdigest ()
88+
89+ @pytest .mark .skip (reason = "buffer keccak must be implemented in python in order to assert" )
90+ async def test_invoke_buffer_keccak_256 ():
91+ options = InvokerOptions (uri = uri , method = "buffer_keccak_256" , args = args , encode_result = False )
92+ result = await client .invoke (options )
93+ print (result )
94+ # TODO: Not sure exactly what this function `buffer_keccak_256` is doing in order to assert it properly
95+ assert result .result == False
96+
97+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
98+ async def test_invoke_shake_256 ():
99+ args = {"message" : "hello polywrap!" , "outputBits" :8 }
100+ options = InvokerOptions (uri = uri , method = "shake_256" , args = args , encode_result = False )
101+ result = await client .invoke (options )
102+ s = SHAKE256 .new ()
103+ s .update (b"hello polywrap!" )
104+ assert result .result == s .read (8 ).hex ()
105+
106+ @pytest .mark .skip (reason = "can't invoke sha3 wrapper due to an error related to wasmtime" )
107+ async def test_invoke_shake_128 ():
108+ args = {"message" : "hello polywrap!" , "outputBits" :8 }
109+ options = InvokerOptions (uri = uri , method = "shake_128" , args = args , encode_result = False )
110+ result = await client .invoke (options )
111+ s = SHAKE128 .new ()
112+ s .update (b"hello polywrap!" )
113+ assert result .result == s .read (8 ).hex ()
0 commit comments