mirror of https://github.com/nucypher/nucypher.git
Test cleanup - don't repeat entire condition for certain more invloved tests eg. tuples.
parent
1485234bda
commit
51bb2d5ca2
|
@ -446,97 +446,94 @@ def test_abi_tuple_output_with_index(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_abi_multiple_output_values(get_random_checksum_address):
|
def test_abi_multiple_output_values(
|
||||||
condition_dict = {
|
contract_condition_dict, get_random_checksum_address
|
||||||
"conditionType": "contract",
|
):
|
||||||
"contractAddress": "0x01B67b1194C75264d06F808A921228a95C765dd7",
|
contract_condition_dict["functionAbi"] = {
|
||||||
"method": "isSubscribedToToken",
|
"inputs": [
|
||||||
"parameters": [
|
{"internalType": "address", "name": "subscriber", "type": "address"},
|
||||||
"0x5082F249cDb2f2c1eE035E4f423c46EA2daB3ab1",
|
{
|
||||||
"subscriptionCode",
|
"internalType": "bytes32",
|
||||||
4,
|
"name": "subscriptionCode",
|
||||||
|
"type": "bytes32",
|
||||||
|
},
|
||||||
|
{"internalType": "uint256", "name": "tokenId", "type": "uint256"},
|
||||||
],
|
],
|
||||||
"functionAbi": {
|
"name": "isSubscribedToToken",
|
||||||
"inputs": [
|
"outputs": [
|
||||||
{"internalType": "address", "name": "subscriber", "type": "address"},
|
{
|
||||||
{
|
"name": "",
|
||||||
"internalType": "bytes32",
|
"type": "tuple",
|
||||||
"name": "subscriptionCode",
|
"components": [
|
||||||
"type": "bytes32",
|
{
|
||||||
},
|
"name": "sponsor",
|
||||||
{"internalType": "uint256", "name": "tokenId", "type": "uint256"},
|
"type": "address",
|
||||||
],
|
"internalType": "address payable",
|
||||||
"name": "isSubscribedToToken",
|
},
|
||||||
"outputs": [
|
{
|
||||||
{
|
"name": "startTimestamp",
|
||||||
"name": "",
|
"type": "uint32",
|
||||||
"type": "tuple",
|
"internalType": "uint32",
|
||||||
"components": [
|
},
|
||||||
{
|
{
|
||||||
"name": "sponsor",
|
"name": "endTimestamp",
|
||||||
"type": "address",
|
"type": "uint32",
|
||||||
"internalType": "address payable",
|
"internalType": "uint32",
|
||||||
},
|
},
|
||||||
{
|
{"name": "size", "type": "uint16", "internalType": "uint16"},
|
||||||
"name": "startTimestamp",
|
{"name": "owner", "type": "address", "internalType": "address"},
|
||||||
"type": "uint32",
|
],
|
||||||
"internalType": "uint32",
|
"internalType": "struct SubscriptionManager.Policy",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "endTimestamp",
|
"name": "valid",
|
||||||
"type": "uint32",
|
"type": "bool",
|
||||||
"internalType": "uint32",
|
"internalType": "bool",
|
||||||
},
|
},
|
||||||
{"name": "size", "type": "uint16", "internalType": "uint16"},
|
{
|
||||||
{"name": "owner", "type": "address", "internalType": "address"},
|
"name": "randoValue",
|
||||||
],
|
"type": "uint256",
|
||||||
"internalType": "struct SubscriptionManager.Policy",
|
"internalType": "uint256",
|
||||||
},
|
},
|
||||||
{
|
],
|
||||||
"name": "valid",
|
"stateMutability": "view",
|
||||||
"type": "bool",
|
"type": "function",
|
||||||
"internalType": "bool",
|
"constant": True,
|
||||||
},
|
}
|
||||||
{
|
contract_condition_dict["returnValueTest"] = {
|
||||||
"name": "randoValue",
|
"comparator": "==",
|
||||||
"type": "uint256",
|
"value": True,
|
||||||
"internalType": "uint256",
|
"index": 1,
|
||||||
},
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function",
|
|
||||||
"constant": True,
|
|
||||||
},
|
|
||||||
"chain": 137,
|
|
||||||
"returnValueTest": {
|
|
||||||
"comparator": "==",
|
|
||||||
"value": True,
|
|
||||||
"index": 1,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# process index 0 (tuple)
|
# process index 0 (tuple)
|
||||||
condition_dict["returnValueTest"]["index"] = 0
|
contract_condition_dict["returnValueTest"]["index"] = 0
|
||||||
condition_dict["returnValueTest"]["value"] = [
|
contract_condition_dict["returnValueTest"]["value"] = [
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
]
|
]
|
||||||
contract_condition = ContractCondition.from_json(json.dumps(condition_dict))
|
contract_condition = ContractCondition.from_json(
|
||||||
|
json.dumps(contract_condition_dict)
|
||||||
|
)
|
||||||
assert isinstance(contract_condition.return_value_test.value, Sequence)
|
assert isinstance(contract_condition.return_value_test.value, Sequence)
|
||||||
|
|
||||||
# process index 1 (bool)
|
# process index 1 (bool)
|
||||||
condition_dict["returnValueTest"]["index"] = 1
|
contract_condition_dict["returnValueTest"]["index"] = 1
|
||||||
condition_dict["returnValueTest"]["value"] = False
|
contract_condition_dict["returnValueTest"]["value"] = False
|
||||||
contract_condition = ContractCondition.from_json(json.dumps(condition_dict))
|
contract_condition = ContractCondition.from_json(
|
||||||
|
json.dumps(contract_condition_dict)
|
||||||
|
)
|
||||||
assert isinstance(contract_condition.return_value_test.value, bool)
|
assert isinstance(contract_condition.return_value_test.value, bool)
|
||||||
|
|
||||||
# process index 2 (int)
|
# process index 2 (int)
|
||||||
condition_dict["returnValueTest"]["index"] = 2
|
contract_condition_dict["returnValueTest"]["index"] = 2
|
||||||
condition_dict["returnValueTest"]["value"] = 123456789
|
contract_condition_dict["returnValueTest"]["value"] = 123456789
|
||||||
contract_condition = ContractCondition.from_json(json.dumps(condition_dict))
|
contract_condition = ContractCondition.from_json(
|
||||||
|
json.dumps(contract_condition_dict)
|
||||||
|
)
|
||||||
assert isinstance(contract_condition.return_value_test.value, int)
|
assert isinstance(contract_condition.return_value_test.value, int)
|
||||||
|
|
||||||
# test execution logic - multiple outputs including tuples
|
# test execution logic - multiple outputs including tuples
|
||||||
|
@ -547,7 +544,7 @@ def test_abi_multiple_output_values(get_random_checksum_address):
|
||||||
]
|
]
|
||||||
for i in range(len(result)):
|
for i in range(len(result)):
|
||||||
_check_execution_logic(
|
_check_execution_logic(
|
||||||
condition_dict=condition_dict,
|
condition_dict=contract_condition_dict,
|
||||||
execution_result=tuple(result),
|
execution_result=tuple(result),
|
||||||
comparator_value=result[i],
|
comparator_value=result[i],
|
||||||
comparator="==",
|
comparator="==",
|
||||||
|
@ -556,7 +553,7 @@ def test_abi_multiple_output_values(get_random_checksum_address):
|
||||||
)
|
)
|
||||||
|
|
||||||
_check_execution_logic(
|
_check_execution_logic(
|
||||||
condition_dict=condition_dict,
|
condition_dict=contract_condition_dict,
|
||||||
execution_result=tuple(result),
|
execution_result=tuple(result),
|
||||||
comparator_value=result[i],
|
comparator_value=result[i],
|
||||||
comparator="!=",
|
comparator="!=",
|
||||||
|
@ -565,116 +562,111 @@ def test_abi_multiple_output_values(get_random_checksum_address):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_abi_nested_tuples_output_values(get_random_checksum_address):
|
def test_abi_nested_tuples_output_values(
|
||||||
condition_dict = {
|
contract_condition_dict, get_random_checksum_address
|
||||||
"conditionType": "contract",
|
):
|
||||||
"contractAddress": "0x01B67b1194C75264d06F808A921228a95C765dd7",
|
contract_condition_dict["functionAbi"] = {
|
||||||
"method": "isSubscribedToToken",
|
"inputs": [
|
||||||
"parameters": [
|
{"internalType": "address", "name": "subscriber", "type": "address"},
|
||||||
"0x5082F249cDb2f2c1eE035E4f423c46EA2daB3ab1",
|
{
|
||||||
"subscriptionCode",
|
"internalType": "bytes32",
|
||||||
4,
|
"name": "subscriptionCode",
|
||||||
|
"type": "bytes32",
|
||||||
|
},
|
||||||
|
{"internalType": "uint256", "name": "tokenId", "type": "uint256"},
|
||||||
],
|
],
|
||||||
"functionAbi": {
|
"name": "isSubscribedToToken",
|
||||||
"inputs": [
|
"outputs": [
|
||||||
{"internalType": "address", "name": "subscriber", "type": "address"},
|
{
|
||||||
{
|
"name": "",
|
||||||
"internalType": "bytes32",
|
"type": "tuple",
|
||||||
"name": "subscriptionCode",
|
"components": [
|
||||||
"type": "bytes32",
|
{
|
||||||
},
|
"name": "sponsor",
|
||||||
{"internalType": "uint256", "name": "tokenId", "type": "uint256"},
|
"type": "address",
|
||||||
],
|
"internalType": "address payable",
|
||||||
"name": "isSubscribedToToken",
|
},
|
||||||
"outputs": [
|
{
|
||||||
{
|
"name": "",
|
||||||
"name": "",
|
"type": "tuple",
|
||||||
"type": "tuple",
|
"components": [
|
||||||
"components": [
|
{
|
||||||
{
|
"name": "startTimestamp",
|
||||||
"name": "sponsor",
|
"type": "uint32",
|
||||||
"type": "address",
|
"internalType": "uint32",
|
||||||
"internalType": "address payable",
|
},
|
||||||
},
|
{
|
||||||
{
|
"name": "endTimestamp",
|
||||||
"name": "",
|
"type": "uint32",
|
||||||
"type": "tuple",
|
"internalType": "uint32",
|
||||||
"components": [
|
},
|
||||||
{
|
],
|
||||||
"name": "startTimestamp",
|
"internalType": "struct SubscriptionManager.Timeframe",
|
||||||
"type": "uint32",
|
},
|
||||||
"internalType": "uint32",
|
{"name": "owner", "type": "address", "internalType": "address"},
|
||||||
},
|
],
|
||||||
{
|
"internalType": "struct SubscriptionManager.Policy",
|
||||||
"name": "endTimestamp",
|
},
|
||||||
"type": "uint32",
|
{
|
||||||
"internalType": "uint32",
|
"name": "valid",
|
||||||
},
|
"type": "bool",
|
||||||
],
|
"internalType": "bool",
|
||||||
"internalType": "struct SubscriptionManager.Timeframe",
|
},
|
||||||
},
|
],
|
||||||
{"name": "owner", "type": "address", "internalType": "address"},
|
"stateMutability": "view",
|
||||||
],
|
"type": "function",
|
||||||
"internalType": "struct SubscriptionManager.Policy",
|
"constant": True,
|
||||||
},
|
}
|
||||||
{
|
contract_condition_dict["returnValueTest"] = {
|
||||||
"name": "valid",
|
"comparator": "==",
|
||||||
"type": "bool",
|
"value": True,
|
||||||
"internalType": "bool",
|
"index": 1,
|
||||||
},
|
|
||||||
],
|
|
||||||
"stateMutability": "view",
|
|
||||||
"type": "function",
|
|
||||||
"constant": True,
|
|
||||||
},
|
|
||||||
"chain": 137,
|
|
||||||
"returnValueTest": {
|
|
||||||
"comparator": "==",
|
|
||||||
"value": True,
|
|
||||||
"index": 1,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# process index 0 (nested tuples)
|
# process index 0 (nested tuples)
|
||||||
condition_dict["returnValueTest"]["index"] = 0
|
contract_condition_dict["returnValueTest"]["index"] = 0
|
||||||
condition_dict["returnValueTest"]["value"] = [
|
contract_condition_dict["returnValueTest"]["value"] = [
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
[1, 2],
|
[1, 2],
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
]
|
]
|
||||||
contract_condition = ContractCondition.from_json(json.dumps(condition_dict))
|
contract_condition = ContractCondition.from_json(
|
||||||
|
json.dumps(contract_condition_dict)
|
||||||
|
)
|
||||||
assert isinstance(contract_condition.return_value_test.value, Sequence)
|
assert isinstance(contract_condition.return_value_test.value, Sequence)
|
||||||
|
|
||||||
# invalid if entire tuple not populated
|
# invalid if entire tuple not populated
|
||||||
condition_dict["returnValueTest"]["value"] = [
|
contract_condition_dict["returnValueTest"]["value"] = [
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
[1],
|
[1],
|
||||||
get_random_checksum_address(), # missing tuple value
|
get_random_checksum_address(), # missing tuple value
|
||||||
]
|
]
|
||||||
with pytest.raises(InvalidCondition, match="Invalid return value comparison type"):
|
with pytest.raises(InvalidCondition, match="Invalid return value comparison type"):
|
||||||
ContractCondition.from_json(json.dumps(condition_dict))
|
ContractCondition.from_json(json.dumps(contract_condition_dict))
|
||||||
|
|
||||||
condition_dict["returnValueTest"]["value"] = [
|
contract_condition_dict["returnValueTest"]["value"] = [
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
get_random_checksum_address(), # incorrect tuple value for Timeframe
|
get_random_checksum_address(), # incorrect tuple value for Timeframe
|
||||||
]
|
]
|
||||||
with pytest.raises(InvalidCondition, match="Invalid return value comparison type"):
|
with pytest.raises(InvalidCondition, match="Invalid return value comparison type"):
|
||||||
ContractCondition.from_json(json.dumps(condition_dict))
|
ContractCondition.from_json(json.dumps(contract_condition_dict))
|
||||||
|
|
||||||
condition_dict["returnValueTest"]["value"] = [
|
contract_condition_dict["returnValueTest"]["value"] = [
|
||||||
get_random_checksum_address(),
|
get_random_checksum_address(),
|
||||||
[1, 2, 3],
|
[1, 2, 3],
|
||||||
get_random_checksum_address(), # too many values
|
get_random_checksum_address(), # too many values
|
||||||
]
|
]
|
||||||
with pytest.raises(InvalidCondition, match="Invalid return value comparison type"):
|
with pytest.raises(InvalidCondition, match="Invalid return value comparison type"):
|
||||||
ContractCondition.from_json(json.dumps(condition_dict))
|
ContractCondition.from_json(json.dumps(contract_condition_dict))
|
||||||
|
|
||||||
# process index 1 (bool)
|
# process index 1 (bool)
|
||||||
condition_dict["returnValueTest"]["index"] = 1
|
contract_condition_dict["returnValueTest"]["index"] = 1
|
||||||
condition_dict["returnValueTest"]["value"] = False
|
contract_condition_dict["returnValueTest"]["value"] = False
|
||||||
contract_condition = ContractCondition.from_json(json.dumps(condition_dict))
|
contract_condition = ContractCondition.from_json(
|
||||||
|
json.dumps(contract_condition_dict)
|
||||||
|
)
|
||||||
assert isinstance(contract_condition.return_value_test.value, bool)
|
assert isinstance(contract_condition.return_value_test.value, bool)
|
||||||
|
|
||||||
# test execution logic - nested tuples
|
# test execution logic - nested tuples
|
||||||
|
@ -684,7 +676,7 @@ def test_abi_nested_tuples_output_values(get_random_checksum_address):
|
||||||
]
|
]
|
||||||
for i in range(len(result)):
|
for i in range(len(result)):
|
||||||
_check_execution_logic(
|
_check_execution_logic(
|
||||||
condition_dict=condition_dict,
|
condition_dict=contract_condition_dict,
|
||||||
execution_result=tuple(result),
|
execution_result=tuple(result),
|
||||||
comparator_value=result[i],
|
comparator_value=result[i],
|
||||||
comparator="==",
|
comparator="==",
|
||||||
|
@ -693,7 +685,7 @@ def test_abi_nested_tuples_output_values(get_random_checksum_address):
|
||||||
)
|
)
|
||||||
|
|
||||||
_check_execution_logic(
|
_check_execution_logic(
|
||||||
condition_dict=condition_dict,
|
condition_dict=contract_condition_dict,
|
||||||
execution_result=tuple(result),
|
execution_result=tuple(result),
|
||||||
comparator_value=result[i],
|
comparator_value=result[i],
|
||||||
comparator="!=",
|
comparator="!=",
|
||||||
|
|
Loading…
Reference in New Issue