# Path: tests/misc/MockHelper/mock_function.py
# class MockFunction:
#     def __init__(self, default=None):
#         self.data = dict()
#         self.default = default
# 
#     def put(self, key, value):
#         self.data[key] = value
# 
#     def get(self, key):
#         if key in self.data:
#             return self.data[key]
# 
#         return self.default
# 
#     def remove(self, key):
#         del self.data[key]


from unittest import TestCase
from mock import Mock
from pyqrllib.pyqrllib import bin2hstr, hstr2bin
from qrl.daemon.walletd import WalletD
from qrl.generated import qrl_pb2
from qrl.core.AddressState import AddressState
from qrl.core.txs.TransferTransaction import TransferTransaction
from qrl.core.txs.MessageTransaction import MessageTransaction
from qrl.daemon.helper.DaemonHelper import WalletDecryptionError
from qrl.core.misc import logger
from tests.misc.helper import set_qrl_dir, get_alice_xmss, get_bob_xmss
from tests.misc.MockHelper.mock_function import MockFunction
            walletd.get_address_state = m.get

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            qaddress = walletd.add_new_address_with_slaves(height=10)
            walletd.encrypt_wallet(self.passphrase)
            walletd.unlock_wallet(self.passphrase)

            master_addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            m.put(qaddress, master_addr_state)

            slaves = walletd.get_slave_list(qaddress)

            self.assertEqual(len(slaves), 1)
            self.assertEqual(len(slaves[0]), 3)

            master_addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][0].pk)), 0)
            master_addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][1].pk)), 0)
            master_addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][2].pk)), 0)
            slave00_addr_state = AddressState.get_default(walletd.qaddress_to_address(slaves[0][0].qaddress))
            slave01_addr_state = AddressState.get_default(walletd.qaddress_to_address(slaves[0][1].qaddress))
            slave02_addr_state = AddressState.get_default(walletd.qaddress_to_address(slaves[0][2].qaddress))

            self.assertEqual(slaves[0][0].index, 0)
            for i in range(0, 1024):
                slave00_addr_state.set_ots_key(i)
            walletd._wallet.set_slave_ots_index(0, 0, 0, 1020)
            m.put(slaves[0][0].qaddress, slave00_addr_state)


# Path: tests/misc/MockHelper/mock_function.py
# class MockFunction:
#     def __init__(self, default=None):
#         self.data = dict()
#         self.default = default
# 
#     def put(self, key, value):
#         self.data[key] = value
# 
#     def get(self, key):
#         if key in self.data:
#             return self.data[key]
# 
#         return self.default
# 
#     def remove(self, key):
#         del self.data[key]


# Path: tests/daemon/test_walletd.py
from unittest import TestCase
from mock import Mock
from pyqrllib.pyqrllib import bin2hstr, hstr2bin
from qrl.daemon.walletd import WalletD
from qrl.generated import qrl_pb2
from qrl.core.AddressState import AddressState
from qrl.core.txs.TransferTransaction import TransferTransaction
from qrl.core.txs.MessageTransaction import MessageTransaction
from qrl.daemon.helper.DaemonHelper import WalletDecryptionError
from qrl.core.misc import logger
from tests.misc.helper import set_qrl_dir, get_alice_xmss, get_bob_xmss
from tests.misc.MockHelper.mock_function import MockFunction

            walletd.get_address_state = m.get

            walletd._public_stub.PushTransaction = Mock(
                return_value=qrl_pb2.PushTransactionResp(error_code=qrl_pb2.PushTransactionResp.SUBMITTED))

            qaddress = walletd.add_new_address_with_slaves(height=10)
            walletd.encrypt_wallet(self.passphrase)
            walletd.unlock_wallet(self.passphrase)

            master_addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            m.put(qaddress, master_addr_state)

            slaves = walletd.get_slave_list(qaddress)

            self.assertEqual(len(slaves), 1)
            self.assertEqual(len(slaves[0]), 3)

            master_addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][0].pk)), 0)
            master_addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][1].pk)), 0)
            master_addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][2].pk)), 0)
            slave00_addr_state = AddressState.get_default(walletd.qaddress_to_address(slaves[0][0].qaddress))
            slave01_addr_state = AddressState.get_default(walletd.qaddress_to_address(slaves[0][1].qaddress))
            slave02_addr_state = AddressState.get_default(walletd.qaddress_to_address(slaves[0][2].qaddress))

            self.assertEqual(slaves[0][0].index, 0)
            for i in range(0, 1024):
                slave00_addr_state.set_ots_key(i)
            walletd._wallet.set_slave_ots_index(0, 0, 0, 1020)
            m.put(slaves[0][0].qaddress, slave00_addr_state)


            self.assertEqual(slaves[0][1].index, 0)