def filter_params(self): params = { "topics": self.topics, "fromBlock": self.fromBlock, "toBlock": self.toBlock, "address": self.address } return valfilter(lambda x: x is not None, params)
def test_signed_transaction(w3, fund_account, transaction, expected, key_object, from_): w3.middleware_stack.add(construct_sign_and_send_raw_middleware(key_object)) # Drop any falsy addresses to_from = valfilter(bool, {'to': w3.eth.accounts[0], 'from': from_}) _transaction = merge(transaction, to_from) if isinstance(expected, type) and issubclass(expected, Exception): with pytest.raises(expected): start_balance = w3.eth.getBalance( _transaction.get('from', w3.eth.accounts[0])) w3.eth.sendTransaction(_transaction) else: start_balance = w3.eth.getBalance( _transaction.get('from', w3.eth.accounts[0])) w3.eth.sendTransaction(_transaction) assert w3.eth.getBalance( _transaction.get('from')) <= start_balance + expected
def validate_abi(abi): """ Helper function for validating an ABI """ if not is_list_like(abi): raise ValueError("'abi' is not a list") if not all(is_dict(e) for e in abi): raise ValueError("'abi' is not a list of dictionaries") functions = filter_by_type('function', abi) selectors = groupby( compose(encode_hex, function_abi_to_4byte_selector), functions ) duplicates = valfilter(lambda funcs: len(funcs) > 1, selectors) if duplicates: raise ValueError( 'Abi contains functions with colliding selectors. ' 'Functions {0}'.format(_prepare_selector_collision_msg(duplicates)) )
def test_signed_transaction( w3, fund_account, transaction, expected, key_object, from_): w3.middleware_stack.add(construct_sign_and_send_raw_middleware(key_object)) # Drop any falsy addresses to_from = valfilter(bool, {'to': w3.eth.accounts[0], 'from': from_}) _transaction = merge(transaction, to_from) if isinstance(expected, type) and issubclass(expected, Exception): with pytest.raises(expected): start_balance = w3.eth.getBalance(_transaction.get('from', w3.eth.accounts[0])) w3.eth.sendTransaction(_transaction) else: start_balance = w3.eth.getBalance(_transaction.get('from', w3.eth.accounts[0])) w3.eth.sendTransaction(_transaction) assert w3.eth.getBalance(_transaction.get('from')) <= start_balance + expected
def drop_items_with_none_value(params): return valfilter(lambda x: x is not None, params)