Skip to content

Commit 281d132

Browse files
authored
Merge pull request #33 from polywrap/rihp/test-bignumber-and-sha3
Wrapper tests: BigNumber & SHA3
2 parents e5e688f + edfb5b7 commit 281d132

File tree

9 files changed

+322
-32
lines changed

9 files changed

+322
-32
lines changed

packages/polywrap-client/poetry.lock

Lines changed: 123 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/polywrap-client/polywrap_client/client.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, config: Optional[PolywrapClientConfig] = None):
4343
resolver=FsUriResolver(file_reader=SimpleFileReader())
4444
)
4545

46-
def getConfig(self):
46+
def get_config(self):
4747
return self._config
4848

4949
def get_uri_resolver(
@@ -130,16 +130,15 @@ async def invoke(self, options: InvokerOptions) -> InvokeResult:
130130
if options.encode_result and not result.encoded:
131131
encoded = msgpack_encode(result.result)
132132
return InvokeResult(result=encoded, error=None)
133-
elif (
133+
if (
134134
not options.encode_result
135135
and result.encoded
136136
and isinstance(result.result, (bytes, bytearray))
137137
):
138138
decoded: Any = msgpack_decode(result.result)
139139
return InvokeResult(result=decoded, error=None)
140-
else:
141-
return result
140+
return result
142141

143-
except Exception as e:
144-
raise e
145-
# return InvokeResult(result=None, error=e)
142+
except Exception as error:
143+
raise error
144+
# return InvokeResult(result=None, error=error)

packages/polywrap-client/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ polywrap-msgpack = { path = "../polywrap-msgpack", develop = true }
1818
polywrap-manifest = { path = "../polywrap-manifest", develop = true }
1919
polywrap-uri-resolvers = { path = "../polywrap-uri-resolvers", develop = true }
2020
result = "^0.8.0"
21+
pysha3 = "^1.0.2"
22+
pycryptodome = "^3.14.1"
2123

2224
[tool.poetry.dev-dependencies]
2325
pytest = "^7.1.2"
724 Bytes
Binary file not shown.
54.5 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
��version�0.1�name�sha3-wasm-rs�type�wasm�abi��version�0.1�moduleType��type�Module�kind̀�methods���name�sha3_512�return��type�String�name�sha3_512�requiredäkind"�scalar��name�sha3_512�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�sha3_384�return��type�String�name�sha3_384�requiredäkind"�scalar��name�sha3_384�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�sha3_256�return��type�String�name�sha3_256�requiredäkind"�scalar��name�sha3_256�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�sha3_224�return��type�String�name�sha3_224�requiredäkind"�scalar��name�sha3_224�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�keccak_512�return��type�String�name�keccak_512�requiredäkind"�scalar��name�keccak_512�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�keccak_384�return��type�String�name�keccak_384�requiredäkind"�scalar��name�keccak_384�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�keccak_256�return��type�String�name�keccak_256�requiredäkind"�scalar��name�keccak_256�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�keccak_224�return��type�String�name�keccak_224�requiredäkind"�scalar��name�keccak_224�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�hex_keccak_256�return��type�String�name�hex_keccak_256�requiredäkind"�scalar��name�hex_keccak_256�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��name�buffer_keccak_256�return��type�String�name�buffer_keccak_256�requiredäkind"�scalar��name�buffer_keccak_256�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�Bytes�name�message�requiredäkind"�scalar��name�message�type�Bytes�requiredäkind��name�shake_256�return��type�String�name�shake_256�requiredäkind"�scalar��name�shake_256�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��type�Int�name�outputBits�requiredäkind"�scalar��name�outputBits�type�Int�requiredäkind��name�shake_128�return��type�String�name�shake_128�requiredäkind"�scalar��name�shake_128�type�String�requiredäkind�type�Method�kind@�requiredéarguments���type�String�name�message�requiredäkind"�scalar��name�message�type�String�requiredäkind��type�Int�name�outputBits�requiredäkind"�scalar��name�outputBits�type�Int�requiredäkind
137 KB
Binary file not shown.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Polywrap Python Client - https://polywrap.io
2+
# BigNumber wrapper schema - https://wrappers.io/v/ipfs/Qme2YXThmsqtfpiUPHJUEzZSBiqX3woQxxdXbDJZvXrvAD
3+
4+
from pathlib import Path
5+
from polywrap_client import PolywrapClient
6+
from polywrap_core import Uri, InvokerOptions
7+
8+
async def test_invoke_bignumber_1arg_and_1prop():
9+
client = PolywrapClient()
10+
uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}')
11+
args = { "arg1": "123", # The base number
12+
"obj": {
13+
"prop1": "1000", # multiply the base number by this factor
14+
}
15+
}
16+
options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False)
17+
result = await client.invoke(options)
18+
assert result.result == "123000"
19+
20+
async def test_invoke_bignumber_with_1arg_and_2props():
21+
client = PolywrapClient()
22+
uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}')
23+
args = {
24+
"arg1": "123123",
25+
"obj": {
26+
"prop1": "1000",
27+
"prop2": "4"
28+
}
29+
}
30+
options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False)
31+
result = await client.invoke(options)
32+
assert result.result == str(123123*1000*4)
33+
34+
async def test_invoke_bignumber_with_2args_and_1prop():
35+
client = PolywrapClient()
36+
uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}')
37+
args = {
38+
"arg1": "123123",
39+
"obj": {
40+
"prop1": "1000",
41+
"prop2": "444"
42+
}
43+
}
44+
options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False)
45+
result = await client.invoke(options)
46+
assert result.result == str(123123*1000*444)
47+
48+
async def test_invoke_bignumber_with_2args_and_2props():
49+
client = PolywrapClient()
50+
uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}')
51+
args = {
52+
"arg1": "123123",
53+
"arg2": "555",
54+
"obj": {
55+
"prop1": "1000",
56+
"prop2": "4"
57+
}
58+
}
59+
options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False)
60+
result = await client.invoke(options)
61+
assert result.result == str(123123*555*1000*4)
62+
63+
async def test_invoke_bignumber_with_2args_and_2props_floats():
64+
client = PolywrapClient()
65+
uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}')
66+
args = {
67+
"arg1": "123.123",
68+
"arg2": "55.5",
69+
"obj": {
70+
"prop1": "10.001",
71+
"prop2": "4"
72+
}
73+
}
74+
options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False)
75+
result = await client.invoke(options)
76+
print(result)
77+
assert result.result == str(123.123*55.5*10.001*4)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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

Comments
 (0)