mirror of https://github.com/nucypher/nucypher.git
Merge pull request #3014 from theref/functionAbi
Resolve `function_abi` AFTER condition is initializedpull/3020/head
commit
0f27f974b3
|
@ -0,0 +1 @@
|
||||||
|
Call `_resolve_abi` after the condition is initialized
|
|
@ -251,14 +251,13 @@ class ContractCondition(RPCCondition):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.w3 = Web3() # used to instantiate contract function without a provider
|
self.w3 = Web3() # used to instantiate contract function without a provider
|
||||||
|
|
||||||
|
if standard_contract_type and function_abi:
|
||||||
|
raise InvalidCondition(
|
||||||
|
"Only one of 'standard_contract_type' or 'function_abi' may be provided."
|
||||||
|
)
|
||||||
|
|
||||||
# preprocessing
|
# preprocessing
|
||||||
contract_address = to_checksum_address(contract_address)
|
contract_address = to_checksum_address(contract_address)
|
||||||
function_abi = _resolve_abi(
|
|
||||||
w3=self.w3,
|
|
||||||
standard_contract_type=standard_contract_type,
|
|
||||||
method=self.method,
|
|
||||||
function_abi=function_abi
|
|
||||||
)
|
|
||||||
|
|
||||||
# spec
|
# spec
|
||||||
self.contract_address = contract_address
|
self.contract_address = contract_address
|
||||||
|
@ -281,9 +280,15 @@ class ContractCondition(RPCCondition):
|
||||||
|
|
||||||
def _get_unbound_contract_function(self) -> ContractFunction:
|
def _get_unbound_contract_function(self) -> ContractFunction:
|
||||||
"""Gets an unbound contract function to evaluate for this condition"""
|
"""Gets an unbound contract function to evaluate for this condition"""
|
||||||
|
function_abi = _resolve_abi(
|
||||||
|
w3=self.w3,
|
||||||
|
standard_contract_type=self.standard_contract_type,
|
||||||
|
method=self.method,
|
||||||
|
function_abi=self.function_abi,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
contract = self.w3.eth.contract(
|
contract = self.w3.eth.contract(
|
||||||
address=self.contract_address, abi=[self.function_abi]
|
address=self.contract_address, abi=[function_abi]
|
||||||
)
|
)
|
||||||
contract_function = getattr(contract.functions, self.method)
|
contract_function = getattr(contract.functions, self.method)
|
||||||
return contract_function
|
return contract_function
|
||||||
|
|
|
@ -111,3 +111,17 @@ def test_invalid_contract_condition():
|
||||||
":hrac",
|
":hrac",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# standard contract type and function ABI
|
||||||
|
with pytest.raises(InvalidCondition):
|
||||||
|
_ = ContractCondition(
|
||||||
|
contract_address="0xaDD9D957170dF6F33982001E4c22eCCdd5539118",
|
||||||
|
method="balanceOf",
|
||||||
|
chain=TESTERCHAIN_CHAIN_ID,
|
||||||
|
standard_contract_type="ERC20",
|
||||||
|
function_abi={"rando": "ABI"},
|
||||||
|
return_value_test=ReturnValueTest("!=", 0),
|
||||||
|
parameters=[
|
||||||
|
":hrac",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
|
@ -37,7 +37,6 @@ def test_evm_condition_json_serializers(ERC1155_balance_condition_data):
|
||||||
serialized_data = condition.to_json()
|
serialized_data = condition.to_json()
|
||||||
|
|
||||||
deserialized_data = json.loads(serialized_data)
|
deserialized_data = json.loads(serialized_data)
|
||||||
deserialized_data.pop("functionAbi")
|
|
||||||
|
|
||||||
assert json.loads(original_data) == deserialized_data
|
assert json.loads(original_data) == deserialized_data
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue