Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spec] Add Behave (cucumber) specifications to python #25

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to the Aptos Python SDK will be captured in this file. This
## Unreleased
- Add Multikey support for Python, with an example
- Deprecate and remove non-BCS transaction submission
- Set max Uleb128 to MAX_U32
- Add Behave behavioral specifications for BCS and AccountAddress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of features we should call it validator or validation? and maybe add something to our readme or contributors doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder? It's required I think for the behavioral spec framework


## 0.8.6
- add client for graphql indexer service with light demo in coin transfer
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@

test:
poetry run python -m unittest discover -s aptos_sdk/ -p '*.py' -t ..
poetry run behave

test-coverage:
poetry run python -m coverage run -m unittest discover -s aptos_sdk/ -p '*.py' -t ..
poetry run python -m coverage report

test-spec:
poetry run behave

gregnazario marked this conversation as resolved.
Show resolved Hide resolved
fmt:
find ./examples ./aptos_sdk . -type f -name "*.py" | xargs poetry run autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports
poetry run isort aptos_sdk examples
poetry run black aptos_sdk examples
find ./examples ./aptos_sdk ./features . -type f -name "*.py" | xargs poetry run autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports
poetry run isort aptos_sdk examples features
poetry run black aptos_sdk examples features

gregnazario marked this conversation as resolved.
Show resolved Hide resolved
lint:
poetry run mypy aptos_sdk examples
poetry run flake8 aptos_sdk examples
poetry run mypy aptos_sdk examples features
poetry run flake8 aptos_sdk examples features

examples:
poetry run python -m examples.aptos_token
Expand Down
2 changes: 1 addition & 1 deletion aptos_sdk/bcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def uleb128(self) -> int:
break
shift += 7

if value > MAX_U128:
if value > MAX_U32:
raise Exception("Unexpectedly large uleb128 value")
davidiw marked this conversation as resolved.
Show resolved Hide resolved

return value
Expand Down
68 changes: 68 additions & 0 deletions features/account_address.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Feature: Account Address
"""
AccountAddress is a 32-byte value that represents an address on chain.
"""

Scenario Outline: Parse account address <label>
Given string <str>
When I parse the account address
Then the result should be address <address>
Examples:
| label | str | address |
| address one short | "0x1" | 0x1 |
| address one long | "0x0000000000000000000000000000000000000001" | 0x1 |
| address two short | "0x2" | 0x2 |
| address two long | "0x0000000000000000000000000000000000000002" | 0x2 |
| full address | "0x1111111111111111111111111111111111111112" | 0x1111111111111111111111111111111111111112 |
| address with leading 0 | "0x0111111111111111111111111111111111111112" | 0x0111111111111111111111111111111111111112 |
| address missing leading 0 | "0x111111111111111111111111111111111111112" | 0x111111111111111111111111111111111111112 |

Scenario Outline: Address <label> to string
"""
TODO: AIP-40 doesn't shorten 0xB
TODO: Uppercase or lowercase?
"""
Given address <address>
When I convert the address to a string
Then the result should be string <str>

Examples:
| label | str | address |
| address one | "0x1" | 0x1 |
| address two | "0x2" | 0x2 |
| address two long | "0x2" | 0x0000000000000000000000000000000000000002 |
| address A | "0xa" | 0xA |
| address B | "0xb" | 0xB |
| full address | "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | 0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef |
| address with leading 0 | "0x0000000000000000000000000111111111111111111111111111111111111112" | 0x0111111111111111111111111111111111111112 |

Scenario Outline: Address <label> to string long
"""
This is required for indexer support
"""
Given address <address>
When I convert the address to a string long
Then the result should be string <str>

Examples:
| label | str | address |
| address one | "0x0000000000000000000000000000000000000000000000000000000000000001" | 0x1 |
| address two | "0x0000000000000000000000000000000000000000000000000000000000000002" | 0x2 |
| address A | "0x000000000000000000000000000000000000000000000000000000000000000a" | 0xA |
| address B | "0x000000000000000000000000000000000000000000000000000000000000000b" | 0xB |
| full address | "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | 0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef |
| address with leading 0 | "0x0000000000000000000000000111111111111111111111111111111111111112" | 0x0111111111111111111111111111111111111112 |
| address missing leading 0 | "0x0000000000000000000000000111111111111111111111111111111111111112" | 0x111111111111111111111111111111111111112 |


Scenario Outline: Parse account address with invalid address <label>
Given string "<address>"
When I parse the account address
Then I should fail to parse the account address
Examples:
| label | address |
| address no digits | 0x |
| address too long | 0xA0000000000000000000000000000000000000000000000000000000000000001 |
| address too long with zeros | 0x00000000000000000000000000000000000000000000000000000000000000001 |
| address invalid character | 0xG |

Loading
Loading