Skip to content

Commit 2cd08ef

Browse files
Ivan Stankovićfredo
authored andcommitted
tests: use ContractDeployer from raiden-contracts to... deploy contracts
ContractDeployer supports linking, which our previous deployment mechanism based on JSONRPCClient does not.
1 parent bfaca6b commit 2cd08ef

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

raiden/network/rpc/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,11 @@ def get_block(self, block_identifier: BlockIdentifier) -> BlockData:
10781078
"""Given a block number, query the chain to get its corresponding block hash"""
10791079
return self.web3.eth.getBlock(block_identifier)
10801080

1081+
def sync_nonce(self) -> None:
1082+
self._available_nonce = discover_next_available_nonce(
1083+
self.web3, self.eth_node, self.address
1084+
)
1085+
10811086
def get_confirmed_blockhash(self) -> BlockHash:
10821087
"""Gets the block CONFIRMATION_BLOCKS in the past and returns its block hash"""
10831088
confirmed_block_number = BlockNumber(

raiden/tests/utils/smoketest.py

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@
8989
CONTRACT_SERVICE_REGISTRY,
9090
CONTRACT_TOKEN_NETWORK_REGISTRY,
9191
CONTRACT_USER_DEPOSIT,
92+
LIBRARY_TOKEN_NETWORK_UTILS,
93+
LIBRARY_TOKEN_NETWORK_UTILS_LINK_KEY,
9294
TEST_SETTLE_TIMEOUT_MAX,
9395
TEST_SETTLE_TIMEOUT_MIN,
9496
)
97+
9598
from raiden_contracts.contract_manager import ContractManager, contracts_precompiled_path
99+
from raiden_contracts.deploy.contract_deployer import ContractDeployer
100+
96101

97102
if TYPE_CHECKING:
98103
# pylint: disable=unused-import
@@ -113,6 +118,15 @@ def __call__(self, description: str, error: bool = False) -> None:
113118
...
114119

115120

121+
def _deploy_contract(
122+
deployer: ContractDeployer, name: str, args: list, libs: dict = None
123+
) -> Address:
124+
receipt = deployer.deploy(name, libs=libs, args=args)
125+
address = receipt["contractAddress"]
126+
assert address is not None, "must be a valid address"
127+
return to_canonical_address(address)
128+
129+
116130
def ensure_executable(cmd):
117131
"""look for the given command and make sure it can be executed"""
118132
if not shutil.which(cmd):
@@ -133,12 +147,12 @@ def deploy_smoketest_contracts(
133147
elif client.eth_node is EthClient.PARITY:
134148
client.web3.parity.personal.unlockAccount(client.web3.eth.accounts[0], DEFAULT_PASSPHRASE)
135149

136-
contract_proxy, _ = client.deploy_single_contract(
137-
contract_name=CONTRACT_SECRET_REGISTRY,
138-
contract=contract_manager.get_contract(CONTRACT_SECRET_REGISTRY),
139-
constructor_parameters=None,
150+
gas_price = 2
151+
gas_limit = 7_000_000
152+
deployer = ContractDeployer(
153+
client.web3, client.privkey, gas_limit=gas_limit, gas_price=gas_price
140154
)
141-
secret_registry_address = Address(to_canonical_address(contract_proxy.address))
155+
secret_registry_address = _deploy_contract(deployer, CONTRACT_SECRET_REGISTRY, [])
142156

143157
secret_registry_constructor_arguments = (
144158
to_checksum_address(secret_registry_address),
@@ -152,50 +166,45 @@ def deploy_smoketest_contracts(
152166
contract=contract_manager.get_contract(CONTRACT_TOKEN_NETWORK_REGISTRY),
153167
constructor_parameters=secret_registry_constructor_arguments,
154168
)
155-
token_network_registry_address = Address(to_canonical_address(contract_proxy.address))
156-
157-
service_registry_constructor_arguments = (
158-
token_address,
159-
EMPTY_ADDRESS,
160-
int(500e18),
161-
6,
162-
5,
163-
180 * SECONDS_PER_DAY,
164-
1000,
165-
200 * SECONDS_PER_DAY,
166-
)
167-
service_registry_contract, _ = client.deploy_single_contract(
168-
contract_name=CONTRACT_SERVICE_REGISTRY,
169-
contract=contract_manager.get_contract(CONTRACT_SERVICE_REGISTRY),
170-
constructor_parameters=service_registry_constructor_arguments,
171-
)
172-
service_registry_address = Address(to_canonical_address(service_registry_contract.address))
173169

174-
user_deposit_contract, _ = client.deploy_single_contract(
175-
contract_name=CONTRACT_USER_DEPOSIT,
176-
contract=contract_manager.get_contract(CONTRACT_USER_DEPOSIT),
177-
constructor_parameters=(token_address, UINT256_MAX),
170+
service_registry_address = _deploy_contract(
171+
deployer,
172+
CONTRACT_SERVICE_REGISTRY,
173+
args=[
174+
token_address,
175+
EMPTY_ADDRESS,
176+
int(500e18),
177+
6,
178+
5,
179+
180 * SECONDS_PER_DAY,
180+
1000,
181+
200 * SECONDS_PER_DAY,
182+
],
178183
)
179-
user_deposit_address = Address(to_canonical_address(user_deposit_contract.address))
180184

181-
monitoring_service_contract, _ = client.deploy_single_contract(
182-
contract_name=CONTRACT_MONITORING_SERVICE,
183-
contract=contract_manager.get_contract(CONTRACT_MONITORING_SERVICE),
184-
constructor_parameters=(
185+
user_deposit_address = _deploy_contract(
186+
deployer, CONTRACT_USER_DEPOSIT, args=[token_address, UINT256_MAX]
187+
)
188+
monitoring_service_address = _deploy_contract(
189+
deployer,
190+
CONTRACT_MONITORING_SERVICE,
191+
args=[
185192
token_address,
186193
service_registry_address,
187194
user_deposit_address,
188195
token_network_registry_address,
189-
),
196+
],
190197
)
191-
monitoring_service_address = Address(to_canonical_address(monitoring_service_contract.address))
192-
193-
one_to_n_contract, _ = client.deploy_single_contract(
194-
contract_name=CONTRACT_ONE_TO_N,
195-
contract=contract_manager.get_contract(CONTRACT_ONE_TO_N),
196-
constructor_parameters=(user_deposit_address, chain_id, service_registry_address),
198+
one_to_n_address = _deploy_contract(
199+
deployer,
200+
CONTRACT_ONE_TO_N,
201+
args=[user_deposit_address, chain_id, service_registry_address],
197202
)
198-
one_to_n_address = Address(to_canonical_address(one_to_n_contract.address))
203+
204+
# Since the contracts have been deployed without the use of our
205+
# JSONRPCClient, we need to sync the client's internal nonce so that
206+
# it reflects the fact that we just sent 7 transactions.
207+
client.sync_nonce()
199208

200209
proxy_manager = ProxyManager(
201210
rpc_client=client,
@@ -207,9 +216,7 @@ def deploy_smoketest_contracts(
207216
)
208217
user_deposit_proxy = UserDeposit(
209218
jsonrpc_client=client,
210-
user_deposit_address=UserDepositAddress(
211-
to_canonical_address(user_deposit_contract.address)
212-
),
219+
user_deposit_address=UserDepositAddress(user_deposit_address),
213220
contract_manager=contract_manager,
214221
proxy_manager=proxy_manager,
215222
block_identifier=BLOCK_ID_LATEST,

0 commit comments

Comments
 (0)