Skip to content

Commit 8bc987e

Browse files
committed
Remove concise contract and implicit contract deprecation warnings
1 parent 6574a17 commit 8bc987e

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

newsfragments/1475.misc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove deprecation warnings in concise contract and implicit contract tests

tests/core/contracts/test_concise_contract.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def zero_address_contract(web3, WithConstructorAddressArgumentsContract, EMPTY_A
4040
_address_contract = WithConstructorAddressArgumentsContract(
4141
address=deploy_receipt['contractAddress'],
4242
)
43-
return ConciseContract(_address_contract)
43+
with pytest.warns(DeprecationWarning, match='deprecated in favor of contract.caller'):
44+
return ConciseContract(_address_contract)
4445

4546

4647
def test_concisecontract_call_default():
@@ -105,7 +106,8 @@ def test_conciscecontract_keeps_custom_normalizers_on_base(web3, MATH_ABI):
105106

106107
# create concisce contract with custom contract
107108
new_normalizers_size = len(base_contract._return_data_normalizers)
108-
concise = ConciseContract(base_contract)
109+
with pytest.warns(DeprecationWarning, match='deprecated in favor of contract.caller'):
110+
concise = ConciseContract(base_contract)
109111

110112
# check that concise contract includes the new normalizers
111113
concise_normalizers_size = len(concise._classic_contract._return_data_normalizers)
@@ -127,7 +129,8 @@ def getValue():
127129

128130
setattr(ConciseContract, 'getValue', getValue)
129131

130-
concise_contract = ConciseContract(contract)
132+
with pytest.warns(DeprecationWarning, match='deprecated in favor of contract.caller'):
133+
concise_contract = ConciseContract(contract)
131134

132135
assert isinstance(concise_contract, ConciseContract)
133136

tests/core/contracts/test_implicit_contract.py

+27-14
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, address_conversion_fu
2929
bytecode_runtime=MATH_RUNTIME,
3030
ContractFactoryClass=ImplicitContract,
3131
)
32-
contract = MathContract(math_address)
33-
assert contract.address == math_address
34-
return contract
32+
with pytest.warns(DeprecationWarning, match='deprecated in favor of contract.caller'):
33+
contract = MathContract(math_address)
34+
assert contract.address == math_address
35+
return contract
3536

3637

3738
@pytest.fixture()
@@ -51,7 +52,8 @@ def get_transaction_count(blocknum_or_label):
5152
def test_implicitcontract_call_default(math_contract, get_transaction_count):
5253
# When a function is called that defaults to call
5354
blocknum, starting_txns = get_transaction_count("pending")
54-
start_count = math_contract.counter()
55+
with pytest.warns(DeprecationWarning, match='deprecated in favor of classic contract syntax'):
56+
start_count = math_contract.counter()
5557
assert is_integer(start_count)
5658
# Check that a call was made and not a transact
5759
# (Auto-mining is enabled, so query by block number)
@@ -62,13 +64,19 @@ def test_implicitcontract_call_default(math_contract, get_transaction_count):
6264

6365
def test_implicitcontract_transact_default(web3, math_contract, get_transaction_count):
6466
# Use to verify correct operation later on
65-
start_count = math_contract.counter()
67+
with pytest.warns(DeprecationWarning, match='deprecated in favor of classic contract syntax'):
68+
start_count = math_contract.counter()
69+
6670
assert is_integer(start_count) # Verify correct type
6771
# When a function is called that defaults to transact
6872
blocknum, starting_txns = get_transaction_count("pending")
69-
math_contract.increment(transact={})
70-
# Check that a transaction was made and not a call
71-
assert math_contract.counter() - start_count == 1
73+
with pytest.warns(DeprecationWarning,
74+
match='deprecated in favor of classic contract syntax') as warnings:
75+
math_contract.increment(transact={})
76+
# Check that a transaction was made and not a call
77+
assert math_contract.counter() - start_count == 1
78+
# Check that the correct number of warnings are raised
79+
assert len(warnings) == 2
7280
# (Auto-mining is enabled, so query by block number)
7381
assert get_transaction_count(blocknum) == starting_txns + 1
7482
# Check that only one block was mined
@@ -78,7 +86,8 @@ def test_implicitcontract_transact_default(web3, math_contract, get_transaction_
7886
def test_implicitcontract_call_override(math_contract, get_transaction_count):
7987
# When a function is called with transact override that defaults to call
8088
blocknum, starting_txns = get_transaction_count("pending")
81-
math_contract.counter(transact={})
89+
with pytest.warns(DeprecationWarning, match='deprecated in favor of classic contract syntax'):
90+
math_contract.counter(transact={})
8291
# Check that a transaction was made and not a call
8392
# (Auto-mining is enabled, so query by block number)
8493
assert get_transaction_count(blocknum) == starting_txns + 1
@@ -88,19 +97,23 @@ def test_implicitcontract_call_override(math_contract, get_transaction_count):
8897

8998
def test_implicitcontract_transact_override(math_contract, get_transaction_count):
9099
# Use to verify correct operation later on
91-
start_count = math_contract.counter()
100+
with pytest.warns(DeprecationWarning, match='deprecated in favor of classic contract syntax'):
101+
start_count = math_contract.counter()
92102
assert is_integer(start_count) # Verify correct type
93103
# When a function is called with call override that defaults to transact
94104
blocknum, starting_txns = get_transaction_count("pending")
95-
math_contract.increment(call={})
96-
# Check that a call was made and not a transact
97-
assert math_contract.counter() - start_count == 0
105+
with pytest.warns(DeprecationWarning,
106+
match='deprecated in favor of classic contract syntax') as warnings:
107+
math_contract.increment(call={})
108+
# Check that a call was made and not a transact
109+
assert math_contract.counter() - start_count == 0
110+
assert len(warnings) == 2
98111
# (Auto-mining is enabled, so query by block number)
99112
assert get_transaction_count(blocknum) == starting_txns
100113
# Check that no blocks were mined
101114
assert get_transaction_count("pending") == (blocknum, 0)
102115

103116

104117
def test_implicitcontract_deprecation_warning(math_contract):
105-
with pytest.warns(DeprecationWarning):
118+
with pytest.warns(DeprecationWarning, match='deprecated in favor of classic contract syntax'):
106119
math_contract.counter(transact={})

0 commit comments

Comments
 (0)