Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev #53

Merged
merged 14 commits into from
Dec 17, 2024
Merged

dev #53

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.4.0-beta.2
current_version = 1.4.0-beta.3
commit = True
tag = True
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<stage>[^.]*)\.(?P<devnum>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
export USE_TESTNET=1 &&
export ENS_ACCOUNT_NAME=${{secrets.ENS_ACCOUNT_NAME}} &&
export ENS_ACCOUNT_SECRET=${{secrets.ENS_ACCOUNT_SECRET}} &&
pytest --cov tests -n 3 --dist loadgroup
pytest --cov tests -n 3 --dist loadscope
- name: Upload coverage reports to Codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/local-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
pip install ".[tester]"
- name: Run test
run: |
pytest tests -n 3 --dist loadgroup
make test
2 changes: 1 addition & 1 deletion .github/workflows/testnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
export ENS_ACCOUNT_NAME=${{secrets.ENS_ACCOUNT_NAME}} &&
export ENS_ACCOUNT_SECRET=${{secrets.ENS_ACCOUNT_SECRET}} &&
export TEST_FINALIZATION=1 &&
pytest tests -n 3 --dist loadgroup
make test
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ doc: rm-doc gen-doc-config
# make html

test:
pytest tests && export USE_TESTNET=1 && pytest tests
pytest tests -vv -n 3 --dist loadscope
# && export USE_TESTNET=1 && pytest tests
# cd ./docs && make doctest
11 changes: 5 additions & 6 deletions conflux_web3/_utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
build_non_strict_registry,
AddressEncoder,
)
from cfx_address import (
Base32Address,
validate_base32
from cfx_address.utils import (
normalize_to
)
from cfx_utils.exceptions import (
InvalidBase32Address
Expand All @@ -26,16 +25,16 @@

class Base32AddressEncoder(AddressEncoder):

encode_fn = lambda self, address: AddressEncoder.encode_fn(Base32Address(address).hex_address)
encode_fn = lambda self, address: AddressEncoder.encode_fn(normalize_to(address, None))

@classmethod
def validate_value(cls, value: Any) -> None:
if is_cns_name(value):
return
try:
validate_base32(value)
normalize_to(value, None)
except InvalidBase32Address:
raise EncodingError(InvalidBase32Address)
raise EncodingError(f"Not a valid Base32 address nor hex address: {value}")

class CfxAddressDecoder(AddressDecoder):
decode_fn = lambda x: x
Expand Down
7 changes: 6 additions & 1 deletion conflux_web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ def from_hex_to_drip(val: Any):
}
log_entry_formatter = apply_formatters_to_dict(LOG_ENTRY_FORMATTERS)

STORAGE_CHANGE_FORMATTER = apply_formatters_to_dict({
"address": from_trust_to_base32,
"collaterals": to_integer_if_hex,
})

RECEIPT_FORMATTERS = {
"type": to_integer_if_hex,
"transactionHash": to_hash32,
Expand All @@ -245,7 +250,7 @@ def from_hex_to_drip(val: Any):
# "gasCoveredBySponsor": bool,
"storageCollateralized": to_integer_if_hex,
# "storageCoveredBySponsor": bool,
"storageReleased": apply_list_to_array_formatter(to_hex_if_integer),
"storageReleased": apply_list_to_array_formatter(STORAGE_CHANGE_FORMATTER),
"contractCreated": apply_formatter_if(is_not_null, from_trust_to_base32),

"stateRoot": to_hash32,
Expand Down
17 changes: 9 additions & 8 deletions conflux_web3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
ConfluxContract
)
from conflux_web3.contract.metadata import (
get_contract_metadata
get_contract_metadata,
EMBEDDED_CONTRACT_NAMES
)
from conflux_web3._utils.transactions import (
fill_transaction_defaults
Expand Down Expand Up @@ -433,7 +434,7 @@ def default_account_munger(

@overload
def contract(
self, address: Union[Base32Address, str], *, name: Optional[str]=None, with_deployment_info: Optional[bool]=None, **kwargs: Any
self, address: Union[Base32Address, str], *, name: Optional[EMBEDDED_CONTRACT_NAMES]=None, with_deployment_info: Optional[bool]=None, **kwargs: Any
) -> ConfluxContract:
...

Expand All @@ -445,27 +446,27 @@ def contract(

@overload
def contract(
self, address: None=None, *, name: str=..., with_deployment_info: None=None, **kwargs: Any
self, address: None=None, *, name: EMBEDDED_CONTRACT_NAMES=..., with_deployment_info: None=None, **kwargs: Any
) -> Union[Type[ConfluxContract], ConfluxContract]:
...

@overload
def contract(
self, address: None=None, *, name: str=..., with_deployment_info: Literal[False]=..., **kwargs: Any
self, address: None=None, *, name: EMBEDDED_CONTRACT_NAMES=..., with_deployment_info: Literal[False]=..., **kwargs: Any
) -> Type[ConfluxContract]:
...

@overload
def contract(
self, address: None=None, *, name: str=..., with_deployment_info: Literal[True]=..., **kwargs: Any
self, address: None=None, *, name: EMBEDDED_CONTRACT_NAMES=..., with_deployment_info: Literal[True]=..., **kwargs: Any
) -> ConfluxContract:
...

def contract(
self,
address: Optional[Union[Base32Address, str]] = None,
*,
name: Optional[str] = None,
name: Optional[EMBEDDED_CONTRACT_NAMES] = None,
with_deployment_info: Optional[bool] = None,
**kwargs: Any,
) -> Union[Type[ConfluxContract], ConfluxContract]:
Expand Down Expand Up @@ -984,11 +985,11 @@ def wait_for_transaction_receipt(
receipt = cast(TxReceipt, super().wait_for_transaction_receipt(transaction_hash, timeout, poll_latency)) # type: ignore
except TimeExhausted:
raise TimeExhausted(
f"Transaction {HexBytes(transaction_hash) !r} is not executed"
f"Transaction {HexBytes(transaction_hash) !r} is not executed "
f"after {timeout} seconds"
)
if receipt["outcomeStatus"] != 0:
raise RuntimeError(f'transaction "${transaction_hash}" execution failed, outcomeStatus ${receipt["outcomeStatus"]}')
raise RuntimeError(f'transaction "0x{receipt["transactionHash"].hex()}" execution failed, outcomeStatus {receipt["outcomeStatus"]} with error: {receipt["txExecErrorMsg"]}')
return receipt

def wait_till_transaction_executed(
Expand Down
55 changes: 1 addition & 54 deletions conflux_web3/contract/metadata/AdminControl.json
Original file line number Diff line number Diff line change
@@ -1,54 +1 @@
{
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "contractAddr",
"type": "address"
}
],
"name": "destroy",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "contractAddr",
"type": "address"
}
],
"name": "getAdmin",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "contractAddr",
"type": "address"
},
{
"internalType": "address",
"name": "newAdmin",
"type": "address"
}
],
"name": "setAdmin",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
}
{ "abi": [ { "inputs": [ { "internalType": "address", "name": "contractAddr", "type": "address" } ], "name": "destroy", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "contractAddr", "type": "address" } ], "name": "getAdmin", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "contractAddr", "type": "address" }, { "internalType": "address", "name": "newAdmin", "type": "address" } ], "name": "setAdmin", "outputs": [], "stateMutability": "nonpayable", "type": "function" } ] }
1 change: 1 addition & 0 deletions conflux_web3/contract/metadata/ConfluxContext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "abi": [ { "inputs": [], "name": "epochNumber", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "posHeight", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "finalizedEpochNumber", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "name": "epochHash", "outputs": [ { "internalType": "bytes32", "name": "", "type": "bytes32" } ], "stateMutability": "view", "type": "function" } ] }
48 changes: 1 addition & 47 deletions conflux_web3/contract/metadata/Create2Factory.json
Original file line number Diff line number Diff line change
@@ -1,47 +1 @@
{
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "isDeployed",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "code",
"type": "bytes"
},
{
"internalType": "uint256",
"name": "salt",
"type": "uint256"
}
],
"name": "deploy",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
}
{ "abi": [ { "inputs": [ { "internalType": "address", "name": "addr", "type": "address" } ], "name": "isDeployed", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "bytes", "name": "code", "type": "bytes" }, { "internalType": "uint256", "name": "salt", "type": "uint256" } ], "name": "deploy", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "nonpayable", "type": "function" } ] }
Loading
Loading