-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: make helper script for updating test contracts (#2254)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Test Data | ||
|
||
All contracts use `.JSON` contract types because core tests cannot assume `ape-vyper` or `ape-solidity` is installed. | ||
These artifacts are stored in `tests/functional/data/contracts/ethereum/local`. | ||
Their counter-part actual source files are located in `tests/functional/data/sources` and have corresponding names (e.g. `SolidityContract.json` matches up with `SolidityContract.sol`). | ||
|
||
## Making Changes | ||
|
||
To make changes to the source files, first ensure you have `ape-solidity` and/or `ape-vyper` installed and then edit the files in `sources/`. | ||
After you are ready to test your changes, from this directory, run the following script: | ||
|
||
```shell | ||
ape run update <MyContract> | ||
``` | ||
|
||
Now, it's corresponding JSON file should have been updated. |
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,32 @@ | ||
from pathlib import Path | ||
|
||
import click | ||
|
||
from ape.cli import ape_cli_context | ||
|
||
BASE_PATH = Path(__file__).parent.parent | ||
SOURCES_PATH = BASE_PATH / "sources" | ||
ARTIFACTS_PATH = BASE_PATH / "contracts" / "ethereum" / "local" | ||
|
||
|
||
def _contract_callback(ctx, param, val): | ||
for ext in ("sol", "vy"): | ||
path = SOURCES_PATH / f"{val}.{ext}" | ||
if path.is_file(): | ||
return path | ||
|
||
raise click.BadArgumentUsage(f"Contract not found: {val}") | ||
|
||
|
||
@click.command() | ||
@ape_cli_context() | ||
@click.argument("contract", callback=_contract_callback) | ||
def cli(cli_ctx, contract): | ||
cm = cli_ctx.compiler_manager | ||
compiler = "vyper" if contract.suffix == ".vy" else "solidity" | ||
code = contract.read_text(encoding="utf-8") | ||
destination = ARTIFACTS_PATH / f"{contract.stem}.json" | ||
contract_type = cm.compile_source(compiler, code, contractName=contract.stem) | ||
destination.unlink() | ||
destination.write_text(contract_type.model_dump_json()) | ||
click.echo("Done!") |