-
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.
Merge pull request #3 from algorandfoundation/feat/unit-testing-boxes
feat: stub implementation of Box, BoxRef and BoxMap
- Loading branch information
Showing
19 changed files
with
1,788 additions
and
131 deletions.
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
Empty file.
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,20 @@ | ||
from algopy import ARC4Contract, Box, OnCompleteAction, TransactionType, arc4, op | ||
|
||
|
||
class BoxContract(ARC4Contract): | ||
|
||
def __init__(self) -> None: | ||
self.oca = Box(OnCompleteAction) | ||
self.txn = Box(TransactionType) | ||
|
||
@arc4.abimethod() | ||
def store_enums(self) -> None: | ||
self.oca.value = OnCompleteAction.OptIn | ||
self.txn.value = TransactionType.ApplicationCall | ||
|
||
@arc4.abimethod() | ||
def read_enums(self) -> tuple[OnCompleteAction, TransactionType]: | ||
assert op.Box.get(b"oca")[0] == op.itob(self.oca.value) | ||
assert op.Box.get(b"txn")[0] == op.itob(self.txn.value) | ||
|
||
return self.oca.value, self.txn.value |
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,26 @@ | ||
from collections.abc import Generator | ||
|
||
import pytest | ||
from algopy import op | ||
from algopy_testing import AlgopyTestContext, algopy_testing_context | ||
|
||
from .contract import BoxContract | ||
|
||
|
||
@pytest.fixture() | ||
def context() -> Generator[AlgopyTestContext, None, None]: | ||
with algopy_testing_context() as ctx: | ||
yield ctx | ||
|
||
|
||
def test_enums(context: AlgopyTestContext) -> None: | ||
# Arrange | ||
contract = BoxContract() | ||
|
||
# Act | ||
contract.store_enums() | ||
oca, txn = contract.read_enums() | ||
|
||
# Assert | ||
assert context.get_box(b"oca") == op.itob(oca) | ||
assert context.get_box(b"txn") == op.itob(txn) |
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
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
Oops, something went wrong.