def test_3_confirm_tx(web3_provider, ethr_signers, configuration: Config, erc20_contract, ethr_leader): secret_token_addr = TokenPairing.objects().get(src_network="Ethereum", src_coin="ERC").dst_address assert increase_block_number(web3_provider, configuration.eth_confirmations) # To allow the new EthrSigner to "catch up", we start it after the event submission event in Ethereum # ethr_signers[-1].start() sleep(configuration.sleep_interval + 3) # Validate the tx is confirmed in the smart contract last_nonce = SwapTrackerObject.last_processed(src=secret_token_addr) assert last_nonce > -1 # account for fee fee = erc20_contract.contract.functions.balanceOf(PAYABLE_ADDRESS).call() assert fee > 0 assert TRANSFER_AMOUNT_ERC == erc20_contract.contract.functions.balanceOf( ethr_leader.signer.address).call() + fee assert increase_block_number(web3_provider, configuration.eth_confirmations) sleep(configuration.sleep_interval) last_nonce = SwapTrackerObject.last_processed(secret_token_addr) swap = Swap.objects().get(src_tx_hash=f'{last_nonce}|{secret_token_addr}') assert swap.status == Status.SWAP_CONFIRMED
def test_3_confirm_and_finalize_eth_tx(web3_provider, ethr_signers, configuration: Config): # To allow the new EthrSigner to "catch up", we start it after the event submission event in Ethereum secret_token_addr = TokenPairing.objects().get(src_network="Ethereum", src_coin="ETH").dst_address prev_bal = web3_provider.eth.getBalance(zero_address, "latest") prev_bal_fee = web3_provider.eth.getBalance(PAYABLE_ADDRESS, "latest") ethr_signers[-1].start() sleep(1) assert increase_block_number(web3_provider, configuration.eth_confirmations) sleep(configuration.sleep_interval * 5) # Validate the tx is confirmed in the smart contract last_nonce = SwapTrackerObject.last_processed(secret_token_addr) # ethr_signers[-1].signer.multisig_contract.contract.functions.confirmations(last_nonce, # ethr_signers[-1].account).call() assert last_nonce >= 0 bal_fee = web3_provider.eth.getBalance(PAYABLE_ADDRESS, "latest") assert bal_fee > prev_bal_fee bal = web3_provider.eth.getBalance(zero_address, "latest") assert bal > prev_bal last_nonce = SwapTrackerObject.last_processed(secret_token_addr) swap = Swap.objects().get(src_tx_hash=f'{last_nonce}|{secret_token_addr}') assert swap.status == Status.SWAP_CONFIRMED configuration.eth_start_block = web3_provider.eth.blockNumber
def test_2_swap_s20_to_eth(setup, web3_provider, ethr_leader, configuration: Config, ethr_signers, scrt_signers): swap_contract_addr = configuration['scrt_swap_address'] secret_token_addr = TokenPairing.objects().get(src_network="Ethereum", src_coin="ETH").dst_address # start the eth signers for signer in ethr_signers[:-1]: signer.start() # Generate swap tx on secret network swap = {"send": {"amount": str(TRANSFER_AMOUNT_ETH), "msg": base64.standard_b64encode(zero_address.encode()).decode(), "recipient": swap_contract_addr}} sleep(configuration['sleep_interval']) last_nonce = SwapTrackerObject.last_processed(secret_token_addr) print(f"last processed before: {last_nonce}") tx_hash = run(f"secretcli tx compute execute {secret_token_addr} " f"'{json.dumps(swap)}' --from t1 --gas 300000 -y", shell=True, stdout=PIPE, stderr=PIPE) tx_hash = json.loads(tx_hash.stdout)['txhash'] sleep(configuration['sleep_interval'] + 6) assert query_data_success(tx_hash) != {} last_nonce_after = SwapTrackerObject.last_processed(secret_token_addr) print(f"last processed before: {last_nonce_after}") assert last_nonce + 1 == last_nonce_after # Give ethr signers time to handle the secret20 swap tx increase_block_number(web3_provider, configuration['eth_confirmations']) sleep(configuration['sleep_interval'] + 5)
def catch_up(self, to_block: int): from_block = SwapTrackerObject.last_processed('Ethereum') + 1 self.logger.debug(f'Starting to catch up from block {from_block}') if self.config.eth_start_block > from_block: self.logger.debug( f'Due to config fast forwarding to block {self.config.eth_start_block}' ) from_block = self.config.eth_start_block SwapTrackerObject.update_last_processed('Ethereum', from_block) if to_block <= 0 or to_block < from_block: return self.logger.debug(f'Catching up to current block: {to_block}') evt_filter = self.contract.contract.events.Swap.createFilter( fromBlock=from_block, toBlock=to_block) for event in evt_filter.get_all_entries(): self._handle(event) evt_filter = self.contract.contract.events.SwapToken.createFilter( fromBlock=from_block, toBlock=to_block) for event in evt_filter.get_all_entries(): self._handle(event) # for event_name in self.contract.tracked_event(): # for event in self.event_listener.events_in_range(event_name, from_block, to_block): # self.logger.info(f'Found new event at block: {event["blockNumber"]}') SwapTrackerObject.update_last_processed('Ethereum', to_block)
def test_2_swap_s20_to_erc(web3_provider, ethr_leader, configuration: Config, ethr_signers, erc20_contract): swap_contract_addr = configuration['scrt_swap_address'] secret_token_addr = TokenPairing.objects().get(src_network="Ethereum", src_coin="ERC").dst_address # for signer in ethr_signers[:-1]: # signer.start() # Generate swap tx on secret network swap = {"send": {"amount": str(TRANSFER_AMOUNT_ERC), "msg": base64.b64encode(ethr_leader.signer.address.encode()).decode(), "recipient": swap_contract_addr}} last_nonce = SwapTrackerObject.last_processed(src=secret_token_addr) tx_hash = run(f"secretcli tx compute execute {secret_token_addr} " f"'{json.dumps(swap)}' --from t1 -b block -y --gas 300000", shell=True, stdout=PIPE, stderr=PIPE) tx_hash = json.loads(tx_hash.stdout)['txhash'] print(f'{tx_hash=}') # Verify that leader recognized the burn tx assert increase_block_number(web3_provider, configuration['eth_confirmations']) sleep(configuration['sleep_interval']) assert last_nonce + 1 == SwapTrackerObject.last_processed(src=secret_token_addr)