Skip to content

Commit

Permalink
Updates for web3py v7.6. Includes version bump to v0.0.48 (#151)
Browse files Browse the repository at this point in the history
This PR updates pypechain to work with web3py v7.6. Solves both
#149 and
#150. Includes version bump
to v0.0.48.

## Breaking Changes
- `my_contract.events.MyEvent` is no longer a type, but instead the
instantiated object. This means calls to e.g.,
`events.MyEvent().process_receipt_typed()` will now be
`events.MyEvent.process_receipt_typed()`.

## Major changes
- Changing handling of `my_contract.events`. Note overloaded events
still are not implemented.
- Adding new pypechain class `PypechainOverloadedFunctions` that acts as
a wrapper to the underlying overloaded functions.
- Delay calling the overloaded function factory until the arguments gets
bound to the contract function.

## Minor changes
- Pin web3py to v7.6 for futureproofing.
- Separate makefile builds to test and example.
- Using solidity compiler 0.8.24 for test gen.
  • Loading branch information
slundqui authored Dec 5, 2024
1 parent 02d6973 commit 6346cf4
Show file tree
Hide file tree
Showing 119 changed files with 1,610 additions and 949 deletions.
43 changes: 31 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
.PHONY: build build-test build-test-sol build-test-types clean
.PHONY: build clean build-test build-sol-test build-types-test clean-test build-example build-sol-example build-types-example clean-example

build:
make build-test
make build-example

clean:
make clean-test
make clean-example

build-test:
make build-test-sol
make build-test-types
make build-test-format-abi
make build-sol-test
make build-types-test

build-test-sol:
sh scripts/rebuild_sol.sh
build-sol-test:
sh scripts/build_sol_test.sh
python scripts/format_json_dir_test.py

build-test-format-abi:
python scripts/format_json_dir.py
build-types-test:
sh scripts/generate_types_test.sh

build-test-types:
sh scripts/regenerate_types.sh
clean-test:
rm -rf rm -rf pypechain/test/*/abis/* && rm -rf pypechain/test/*/types/*

clean:
rm -rf example/abis/* && rm -rf example/types/* && rm -rf pypechain/test/*/abis/* && rm -rf pypechain/test/*/types/*
build-example:
make build-sol-example
make build-types-example

build-sol-example:
sh scripts/build_sol_example.sh
python scripts/format_json_dir_example.py

build-types-example:
sh scripts/generate_types_example.sh

clean-example:
rm -rf example/abis/* && rm -rf example/types/*



20 changes: 2 additions & 18 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import json
import os
import shutil
import subprocess
Expand All @@ -16,6 +15,7 @@
from web3.types import RPCEndpoint

from pypechain import pypechain
from pypechain.utilities.format import format_json_dir

# pylint: disable=redefined-outer-name

Expand Down Expand Up @@ -153,22 +153,6 @@ def initialize_web3_with_http_provider(
return web3


def _format_json_dir(json_dir):
for root, dirs, files in os.walk(json_dir):
# Format any outer json files
for file in files:
if file.endswith(".json"):
json_file = os.path.join(root, file)
# Format the JSON file
with open(json_file, "r", encoding="utf-8") as file:
data = json.load(file)
with open(json_file, "w", encoding="utf-8") as file:
json.dump(data, file, ensure_ascii=False, indent=2)

for d in dirs:
_format_json_dir(d)


@pytest.fixture(scope="class")
def process_contracts(request):
"""Generate ABIs for all contracts and pypechain types from those abis."""
Expand Down Expand Up @@ -207,7 +191,7 @@ def process_contracts(request):
# subprocess.run(command, shell=True, check=True)

# Format the output json files
_format_json_dir(abis_dir)
format_json_dir(abis_dir)

# Run the pypechain module after processing all contracts
pypechain(f"{test_dir}/abis", f"{test_dir}/types")
8 changes: 4 additions & 4 deletions example/abis/Example.sol/Example.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "bf01bce3e74185365517745b4f71bf07",
"id": "54eb1770cae4968bdb277915aa91b04b",
"source_id_to_path": {
"0": "example/contracts/Example.sol"
},
Expand Down
Loading

0 comments on commit 6346cf4

Please sign in to comment.