Skip to content

Commit

Permalink
Feat/file fuzzer step (#79)
Browse files Browse the repository at this point in the history
* feat: add a step to execute fuzz test from a file

* tests: add some FileFuzzerStep to the integration tests

* feat: add a json default formatter

* docs: add FileFuzzerStep step documentation

* docs: changelog

* Bump version: 3.0.0-dev2 → 3.0.0-dev3

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
EtienneWallet and github-actions[bot] authored Nov 25, 2024
1 parent f1c6023 commit 682ef2c
Show file tree
Hide file tree
Showing 11 changed files with 402 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
"editor.formatOnSave": true,
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
}
}
2 changes: 2 additions & 0 deletions docs/dictionary/project_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Dev
devnet
EnumWithEverything
EsdtMinter
FileFuzzerStep
françois
Freepik
Fuzzer
GetBaseToken
GetPoolPrice
GetQuoteToken
Expand Down
1 change: 1 addition & 0 deletions docs/source/dev_documentation/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- the data save path of `MxOps` is now configurable through the config var `DATA_PATH`
- chain-simulator network and adapted transaction schema (forward chain until transaction completion)
- FileFuzzerStep


### Changed
Expand Down
42 changes: 42 additions & 0 deletions docs/source/user_documentation/steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,48 @@ results_save_keys:
If you provide sub-keys, the number of sub-keys must exactly match the number of elements returned by the query response.
```

(contract_query_target)=
### File Fuzzer Step

This `Step` is used to execute some fuzz testing. The parameters for the tests (queries or calls) are taken from a file.
At the moment, only yaml format is supported.

```yaml
type: FileFuzzer
contract: "my-contract-id"
file_path: "./path/to/my_fuzzer_parameters.yaml"
```

#### Yaml File Format

```yaml
parameters:
- endpoint: my_endpoint # query or call
sender: bob # name or bech32 of the sender of the tx (optional for query)
gas_limit: 89984 # optional, only for calls
value: 0 # optional, if any EGLD is to be sent with the call
esdt_transfers: # optional, if any esdt are to be sent with the call
- token_identifier: TOKEN-abcdef
amount: 120924
nonce: 0 # optional, default to 0
arguments: # optional, argument to pass to the query/call as usual in MxOps
- 12145
- TOKEN-abcdef
expected_outputs: # optional, excepted output of the query
- 12124115
description: "test description"
- endpoint: my_endpoint
....
```

#### Considerations

At the moment, this step is a work in progress.

- expected output works only for queries
- esdt transfers happening within a transaction cannot be tested

(token_management_target)=
## Token Management Steps

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
parameters:
- endpoint: addAirdropAmount
sender: jean
gas_limit: 5000000
arguments:
- "[thomas]"
- 12471682
description: "adding airdrop"

- endpoint: getAirdropAmount
sender: thomas
gas_limit: 5000000
arguments:
- "[thomas]"
expected_outputs:
- 12471682

- endpoint: claimAirdrop
sender: thomas
gas_limit: 5000000
description: "claiming airdrop"

- endpoint: getAirdropAmount
sender: thomas
gas_limit: 5000000
arguments:
- "[thomas]"
expected_outputs:
- 0

- endpoint: addAirdropAmount
sender: jean
gas_limit: 5000000
arguments:
- "[thomas]"
- 1
description: "adding airdrop"

- endpoint: getAirdropAmount
sender: thomas
gas_limit: 5000000
arguments:
- "[thomas]"
expected_outputs:
- 1

- endpoint: claimAirdrop
sender: thomas
gas_limit: 5000000
description: "claiming airdrop"

- endpoint: getAirdropAmount
sender: thomas
gas_limit: 5000000
arguments:
- "[thomas]"
expected_outputs:
- 0

- endpoint: addAirdropAmount
sender: jean
gas_limit: 5000000
arguments:
- "[thomas]"
- 124789174012701294870129874129
description: "adding airdrop"

- endpoint: getAirdropAmount
sender: thomas
gas_limit: 5000000
arguments:
- "[thomas]"
expected_outputs:
- 124789174012701294870129874129

- endpoint: claimAirdrop
sender: thomas
gas_limit: 5000000
description: "claiming airdrop"

- endpoint: getAirdropAmount
sender: thomas
gas_limit: 5000000
arguments:
- "[thomas]"
expected_outputs:
- 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
parameters:

- endpoint: deposit
sender: thomas
gas_limit: 8000000
description: "depositing esdt"
esdt_transfers:
- token_identifier: "%abc-esdt-minter.EsdtIdentifier"
amount: 1247741982740
nonce: 0

- endpoint: deposit
sender: thomas
gas_limit: 8000000
description: "depositing esdt"
esdt_transfers:
- token_identifier: "%abc-esdt-minter.EsdtIdentifier"
amount: 213
nonce: 0

- endpoint: deposit
sender: thomas
gas_limit: 8000000
description: "depositing esdt"
esdt_transfers:
- token_identifier: "%abc-esdt-minter.EsdtIdentifier"
amount: 41496879
nonce: 0

- endpoint: withdraw
sender: thomas
gas_limit: 8000000
description: "withdrawing esdt"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
allowed_networks:
- localnet
- testnet
- devnet
- chain-simulator

allowed_scenario:
- "integration_test_piggy_bank_user_exploit"

steps:

- type: FileFuzzer
contract: "abc-esdt-minter"
file_path: "./integration_tests/piggy_bank/mxops_scenes/data/fuzz_tests_esdt_minter.yaml"

- type: FileFuzzer
contract: "abc-piggy-bank"
file_path: "./integration_tests/piggy_bank/mxops_scenes/data/fuzz_tests_piggy_bank.yaml"
12 changes: 12 additions & 0 deletions mxops/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ def __str__(self) -> str:
)


class FuzzTestFailed(Exception):
"""
To be raised when a fuzz test fails
"""


#############################################################
#
# User Errors
Expand Down Expand Up @@ -351,3 +357,9 @@ class InvalidQueryResultsDefinition(Exception):
"""
to be raise when the results types of a query are not correctly defined
"""


class WrongFuzzTestFile(Exception):
"""
to be raised when the file given for fuzz testing in not correctly formatted
"""
Loading

0 comments on commit 682ef2c

Please sign in to comment.