def test_get_balance(mocker): safe = Safe(None, '', '', '') safe.w3.eth.getBalance = mocker.MagicMock() safe.w3.eth.getBalance.return_value = 12345678901234 assert safe.get_balance() == 12345678901234 assert float(safe.get_balance('ether')) == 0.000012345678901234
def setUp(self): "Sets up the test case" # The `Safe` object needs two files and we put these inside a folder. os.makedirs(self.base_dir) # We cannot ensure that all data will be removed. self.addCleanup(shutil.rmtree, self.base_dir, ignore_errors=True) self.safe = Safe(file=self.pass_file, secret=self.secret_file)
def test_get_threshold(mocker): safe = Safe(None, '', '', '') safe.contract.functions.getThreshold = mocker.MagicMock() get_threshold_mock = mocker.MagicMock() get_threshold_mock.call.return_value = 123 safe.contract.functions.getThreshold.return_value = get_threshold_mock assert safe.get_threshold() == 123 get_threshold_mock.call.assert_called()
def test_get_owners(mocker): safe = Safe(None, '', '', '') safe.contract.functions.getOwners = mocker.MagicMock() get_owners_mock = mocker.MagicMock() get_owners_mock.call.return_value = 123 safe.contract.functions.getOwners.return_value = get_owners_mock assert safe.get_owners() == 123 get_owners_mock.call.assert_called()
def test_get_nonce(mocker): safe = Safe(None, '', '', '') safe.contract.functions.nonce = mocker.MagicMock() nonce_mock = mocker.MagicMock() nonce_mock.call.return_value = 123 safe.contract.functions.nonce.return_value = nonce_mock assert safe.get_nonce() == 123 nonce_mock.call.assert_called()
def test_get_owners_sentinel(mocker): safe = Safe(None, '', '', '') safe.contract.functions.SENTINEL_OWNERS = mocker.MagicMock() sentinel_owners_mock = mocker.MagicMock() sentinel_owners_mock.call.return_value = 123 safe.contract.functions.SENTINEL_OWNERS.return_value = sentinel_owners_mock assert safe.get_owners_sentinel() == 123 sentinel_owners_mock.call.assert_called()
def test_get_transaction_hash(mocker): safe = Safe(None, '', '', '') transaction = Transaction(safe, '0xto_address', value=0.123, data='0xdata', operation=Operation.Call, gas_token='0xgas_token', safe_tx_gas=123, data_gas=456, gas_price=789, refund_receiver='0xrefund_receiver', nonce=90) safe.contract.functions.getTransactionHash = mocker.MagicMock() get_transation_hash_mock = mocker.MagicMock() get_transation_hash_mock.call.return_value = 123 safe.contract.functions.getTransactionHash.return_value = get_transation_hash_mock assert safe.get_transaction_hash(transaction) == 123 get_transation_hash_mock.call.assert_called()
def cli(ctx, address, network): """Command line interface for the Gnosis Safe. """ if not network: network = 'mainnet' env = ENVS[network] click.echo('\nYou are using: {}\n\n'.format(env['name'])) ctx.obj = Safe(network, address, env['rpc_endpoint_url'], env['safe_relay_url'])
def create_safe(self): """Create a safe for this character.""" location = os.path.join(self.world.path, self.location) if not os.path.exists(location): logger.info("Try to create the {} location for a character".format( repr(location))) os.makedirs(location) # Create a safe for this character safe = Safe(file=os.path.join(location, ".passphrase"), secret=os.path.join(location, "login")) return safe
def execute(context, args): if not validate_args(args): # if we have invalid args, finish the command here return context # check if there's an open safe already if not command_utils.confirm_close_current_safe(context): return context # everything is good to go, start making that safe! pw = create_password("Create a password for the new safe: ") context[consts.CONTEXT_SAFE_KEY] = Safe.init_safe(args[0], pw) pw = "" return context
def execute(context, args): if not validate_args(args): return context # close current safe if one is open if not command_utils.confirm_close_current_safe(context): return context safe_dir = join(args[0], consts.SAFE_ROOT_DIR) given_pw = getpass("Enter password: "******"Unable to open safe: ", ex) raise ex return context
class SafeTests(TestCase): "Test for the `Safe` class" # Files used by the safe class base_dir = os.path.join(os.path.abspath("."), "test_safe_data") pass_file = os.path.join(base_dir, ".passphrase") secret_file = os.path.join(base_dir, "data.secret") def setUp(self): "Sets up the test case" # The `Safe` object needs two files and we put these inside a folder. os.makedirs(self.base_dir) # We cannot ensure that all data will be removed. self.addCleanup(shutil.rmtree, self.base_dir, ignore_errors=True) self.safe = Safe(file=self.pass_file, secret=self.secret_file) def tearDown(self): "Destroys all data produced by the tests" if self.safe: self.safe = None def test_encrypt(self): "Tests if encrypt/decrypt works correctly" salt = self.safe.get_salt_from_key("mykey") value = "Decrypted value" encrypted = self.safe.encrypt(value, salt) self.assertEqual(self.safe.decrypt(encrypted, salt), value) def test_store(self): "Checks if the store/retrieve functions work correctly" key, value = ("mykey", "myvalue") self.safe.store(key, value) self.assertEqual(self.safe.retrieve(key), value)
def setUp(self): self.safe = Safe("test_files/davoodabadi_dynamic.xlsx")
def setUp(self): self.safe = Safe("test_files/safdari.xlsx")
def setUp(self): self.safe = Safe("test_files/sattari_safe.xlsx")
"""The main Bank O'Sean server. This is the single source of truth for all balances held at the Bank O'Sean""" from concurrent import futures import threading import time import uuid import random import grpc import balance_pb2 import balance_pb2_grpc from safe import Safe SAFE = Safe() class Listener(balance_pb2_grpc.BalanceServiceServicer): """The listener function implements the rpc call as described in the balance.proto file""" def __init__(self): self.counter = 0 self.last_print_time = time.time() def __str__(self): return self.__class__.__name__ def createBalance(self, request, context): amount = SAFE.create_balance(request.id) return balance_pb2.Balance(amount=amount["balance"]) def getBalance(self, request, context): amount = SAFE.get_balance(request.id) return balance_pb2.Balance(amount=amount["balance"])