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 14, 2024
1 parent 88dc5ce commit 9a9fc65
Show file tree
Hide file tree
Showing 7 changed files with 856 additions and 5 deletions.
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
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 9a9fc65

Please sign in to comment.