Skip to content

Commit

Permalink
[spec] Add Behave (cucumber) specifications to python
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Aug 15, 2024
1 parent 88dc5ce commit 67894ee
Show file tree
Hide file tree
Showing 9 changed files with 890 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Aptos Python SDK will be captured in this file. This changelog is written by hand for now.

## Unreleased
- Set max Uleb128 to MAX_U32
- Add Behave behavioral specifications for BCS and AccountAddress

## 0.8.6
- add client for graphql indexer service with light demo in coin transfer
- add mypy to ignore missing types for graphql and ecdsa
Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ 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

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

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")

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

0 comments on commit 67894ee

Please sign in to comment.