-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from collections.abc import Generator | ||
|
||
import pytest | ||
from algopy_testing import arc4 | ||
from algopy_testing.box import Box | ||
from algopy_testing.context import AlgopyTestContext, algopy_testing_context | ||
from algopy_testing.primitives.biguint import BigUInt | ||
from algopy_testing.primitives.bytes import Bytes | ||
from algopy_testing.primitives.string import String | ||
from algopy_testing.primitives.uint64 import UInt64 | ||
from algopy_testing.utils import as_bytes, as_string | ||
|
||
|
||
@pytest.fixture() | ||
def context() -> Generator[AlgopyTestContext, None, None]: | ||
with algopy_testing_context() as ctx: | ||
yield ctx | ||
ctx.reset() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("value_type", "key"), | ||
[ | ||
(UInt64, ""), | ||
(Bytes, b""), | ||
(String, Bytes()), | ||
(BigUInt, String()), | ||
(arc4.String, ""), | ||
(arc4.DynamicArray, b""), | ||
], | ||
) | ||
def test_box_init_without_key( | ||
context: AlgopyTestContext, | ||
value_type: type, | ||
key: bytes | str | Bytes | String, | ||
) -> None: | ||
box = Box(value_type, key=key) | ||
assert not bool(box) | ||
assert len(box.key) > 0 | ||
with pytest.raises(ValueError, match="Box has not been created"): | ||
_ = box.value | ||
|
||
with pytest.raises(ValueError, match="Box has not been created"): | ||
_ = box.length | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("value_type", "key"), | ||
[ | ||
(UInt64, "key"), | ||
(Bytes, b"key"), | ||
(String, Bytes(b"key")), | ||
(BigUInt, String("key")), | ||
(arc4.String, "Key"), | ||
(arc4.DynamicArray, b"Key"), | ||
], | ||
) | ||
def test_box_init_with_key( | ||
context: AlgopyTestContext, | ||
value_type: type, | ||
key: bytes | str | Bytes | String, | ||
) -> None: | ||
box = Box(value_type, key=key) | ||
assert not bool(box) | ||
assert len(box.key) > 0 | ||
|
||
key_bytes = ( | ||
String(as_string(key)).bytes if isinstance(key, str | String) else Bytes(as_bytes(key)) | ||
) | ||
assert box.key == key_bytes | ||
|
||
with pytest.raises(ValueError, match="Box has not been created"): | ||
_ = box.value | ||
|
||
with pytest.raises(ValueError, match="Box has not been created"): | ||
_ = box.length |