コード例 #1
0
    def test_relayTokenTxnBySlave(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

            resp = service.AddNewAddressWithSlaves(xrdwallet_pb2.AddNewAddressWithSlavesReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            slaves = walletd.get_slave_list(qaddress)

            addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][0].pk)), 0)
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]

            resp = service.RelayTokenTxnBySlave(
                xrdwallet_pb2.RelayTokenTxnBySlaveReq(symbol=b'xrd',
                                                      name=b'Quantum Resistant Ledger',
                                                      owner=alice_xmss.qaddress,
                                                      decimals=5,
                                                      addresses=qaddresses,
                                                      amounts=amounts,
                                                      fee=100000000,
                                                      master_address=qaddress), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
コード例 #2
0
    def test_relaySlaveTxnBySlave(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

            resp = service.AddNewAddressWithSlaves(xrdwallet_pb2.AddNewAddressWithSlavesReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            slaves = walletd.get_slave_list(qaddress)

            addr_state.add_slave_pks_access_type(bytes(hstr2bin(slaves[0][0].pk)), 0)
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))

            alice_xmss = get_alice_xmss(4)
            slave_pks = [alice_xmss.pk]
            access_types = [0]

            resp = service.RelaySlaveTxnBySlave(
                xrdwallet_pb2.RelaySlaveTxnBySlaveReq(slave_pks=slave_pks,
                                                      access_types=access_types,
                                                      fee=100000000,
                                                      master_address=qaddress), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
コード例 #3
0
    def test_relaySlaveTxn(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.IsSlave = Mock(
                return_value=xrd_pb2.IsSlaveResp(result=True))
            walletd._public_stub.GetOTS = Mock(
                return_value=xrd_pb2.GetOTSResp(next_unused_ots_index=0,
                                                unused_ots_index_found=True))

            alice_xmss = get_alice_xmss(4)
            slave_pks = [alice_xmss.pk]
            access_types = [0]

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

            resp = service.RelaySlaveTxn(xrdwallet_pb2.RelaySlaveTxnReq(slave_pks=slave_pks,
                                                                        access_types=access_types,
                                                                        fee=100000000,
                                                                        master_address=None,
                                                                        signer_address=qaddress,
                                                                        ots_index=0), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
コード例 #4
0
    def test_relayMessageTxn(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.GetOTS = Mock(
                return_value=xrd_pb2.GetOTSResp(next_unused_ots_index=0,
                                                unused_ots_index_found=True))

            resp = service.RelayMessageTxn(xrdwallet_pb2.RelayMessageTxnReq(message=b'Hello xrd!',
                                                                            fee=100000000,
                                                                            master_address=None,
                                                                            signer_address=qaddress,
                                                                            ots_index=0), context=None)

            self.assertEqual(0, resp.code)
            self.assertIsNotNone(resp.tx)
コード例 #5
0
    def test_unlockWallet(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(len(resp.addresses), 1)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.LockWallet(xrdwallet_pb2.LockWalletReq(), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase="wrong"), context=None)
            self.assertEqual(resp.code, 1)
コード例 #6
0
 def test_addNewAddress(self):
     with set_xrd_dir("wallet_ver1"):
         walletd = WalletD()
         service = WalletAPIService(walletd)
         resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
         self.assertEqual(resp.code, 0)
         self.assertEqual(resp.address[0], 'Q')
コード例 #7
0
    def test_getNodeInfo(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            block_last_hash_str = 'c23f47a10a8c53cc5ded096369255a32c4a218682a961d0ee7db22c500000000'

            version = "1.0.0"
            num_connections = 10
            num_known_peers = 200
            uptime = 10000
            block_height = 102345
            block_last_hash = bytes(hstr2bin(block_last_hash_str))
            network_id = "network id"
            node_info = xrd_pb2.NodeInfo(version=version,
                                         num_connections=num_connections,
                                         num_known_peers=num_known_peers,
                                         uptime=uptime,
                                         block_height=block_height,
                                         block_last_hash=block_last_hash,
                                         network_id=network_id)
            walletd._public_stub.GetNodeState = Mock(
                return_value=xrd_pb2.GetNodeStateResp(info=node_info))

            resp = service.GetNodeInfo(xrdwallet_pb2.NodeInfoReq(), context=None)

            self.assertEqual(resp.version, version)
            self.assertEqual(resp.num_connections, str(num_connections))
            self.assertEqual(resp.num_known_peers, str(num_known_peers))
            self.assertEqual(resp.uptime, uptime)
            self.assertEqual(resp.block_height, block_height)
            self.assertEqual(resp.block_last_hash, block_last_hash_str)
            self.assertEqual(resp.network_id, network_id)
コード例 #8
0
 def test_addAddressFromSeed2(self):
     with set_xrd_dir("wallet_ver1"):
         walletd = WalletD()
         service = WalletAPIService(walletd)
         resp = service.AddAddressFromSeed(xrdwallet_pb2.AddAddressFromSeedReq(seed=self.mnemonic), context=None)
         self.assertEqual(resp.code, 0)
         self.assertEqual(resp.address, self.qaddress)
コード例 #9
0
    def test_getWalletInfo(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.GetWalletInfo(xrdwallet_pb2.GetWalletInfoReq(), context=None)

            self.assertEqual(resp.version, 1)
            self.assertEqual(resp.address_count, 0)
            self.assertFalse(resp.is_encrypted)
コード例 #10
0
    def test_addAddressFromSeed(self):
        with set_xrd_dir("wallet_ver1"):
            qaddress = "Q010400ff39df1ba4d1d5b8753e6d04c51c34b95b01fc3650c10ca7b296a18bdc105412c59d0b3b"
            hex_seed = "0104008441d43524996f76236141d16b7b324323abf796e77ad7c874622a82f5744bb803f9b404d25733d0db82be7ac6f3c4cf"

            walletd = WalletD()
            service = WalletAPIService(walletd)
            resp = service.AddAddressFromSeed(xrdwallet_pb2.AddAddressFromSeedReq(seed=hex_seed), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.address, qaddress)
コード例 #11
0
    def test_listAddresses(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            address = resp.address

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.addresses[0], address)
コード例 #12
0
    def test_addNewAddressWithSlaves(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            walletd._public_stub.PushTransaction = Mock(
                return_value=xrd_pb2.PushTransactionResp(error_code=xrd_pb2.PushTransactionResp.SUBMITTED))

            service = WalletAPIService(walletd)
            resp = service.AddNewAddressWithSlaves(xrdwallet_pb2.AddNewAddressWithSlavesReq(), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.address[0], 'Q')
コード例 #13
0
    def test_getRecoverySeeds(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddAddressFromSeed(xrdwallet_pb2.AddAddressFromSeedReq(seed=self.mnemonic), context=None)
            resp = service.GetRecoverySeeds(xrdwallet_pb2.GetRecoverySeedsReq(address=self.qaddress), context=None)

            self.assertEqual(resp.hexseed, self.hex_seed)
            self.assertEqual(resp.mnemonic, self.mnemonic)
コード例 #14
0
    def test_isValidAddress(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            qaddress = "Q010400ff39df1ba4d1d5b8753e6d04c51c34b95b01fc3650c10ca7b296a18bdc105412c59d0b3b"
            resp = service.IsValidAddress(xrdwallet_pb2.ValidAddressReq(address=qaddress), context=None)
            self.assertEqual(resp.valid, "True")

            qaddress = "Q010400ff39df1ba4d1d5b8753e6d04c51c34b95b01fc3650c10ca7b296a18bdc105412c59d0b00"
            resp = service.IsValidAddress(xrdwallet_pb2.ValidAddressReq(address=qaddress), context=None)
            self.assertEqual(resp.valid, "False")
コード例 #15
0
    def test_getHeight(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            walletd._public_stub.GetHeight = Mock(
                return_value=xrd_pb2.GetHeightResp(height=1001))

            resp = service.GetHeight(xrdwallet_pb2.HeightReq(), context=None)

            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.height, 1001)
コード例 #16
0
    def test_getTotalBalance(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            walletd._public_stub.GetTotalBalance = Mock(
                return_value=xrd_pb2.GetTotalBalanceResp(balance=6000))

            resp = service.GetTotalBalance(xrdwallet_pb2.TotalBalanceReq(), context=None)

            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.balance, "6000")
コード例 #17
0
    def test_getAddressFromPK(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            pk = '01020016ecb9f39b9f4275d5a49e232346a15ae2fa8c50a2927daeac189b8c5f2d1' \
                 '8bc4e3983bd564298c49ae2e7fa6e28d4b954d8cd59398f1225b08d6144854aee0e'

            resp = service.GetAddressFromPK(xrdwallet_pb2.AddressFromPKReq(pk=pk), context=None)

            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.address,
                             'Q010200670246b0026436b717f199e3ec5320ba6ab61d5eddff811ac199a9e9b871d3280178b343')
コード例 #18
0
    def test_relayTokenTxn(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            qaddress = resp.address
            addr_state = AddressState.get_default(walletd.qaddress_to_address(qaddress))
            walletd._public_stub.GetAddressState = Mock(
                return_value=xrd_pb2.GetAddressStateResp(state=addr_state.pbdata))
            walletd._public_stub.IsSlave = Mock(
                return_value=xrd_pb2.IsSlaveResp(result=True))
            walletd._public_stub.GetOTS = Mock(
                return_value=xrd_pb2.GetOTSResp(next_unused_ots_index=0,
                                                unused_ots_index_found=True))

            alice_xmss = get_alice_xmss(4)
            bob_xmss = get_bob_xmss(4)
            qaddresses = [alice_xmss.qaddress, bob_xmss.qaddress]
            amounts = [1000000000, 1000000000]

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

            resp = service.RelayTokenTxn(xrdwallet_pb2.RelayTokenTxnReq(symbol=b'xrd',
                                                                        name=b'Quantum Resistant Ledger',
                                                                        owner=alice_xmss.qaddress,
                                                                        decimals=5,
                                                                        addresses=qaddresses,
                                                                        amounts=amounts,
                                                                        fee=100000000,
                                                                        master_address=None,
                                                                        signer_address=qaddress,
                                                                        ots_index=0), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
コード例 #19
0
    def test_encryptWallet(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 1)
コード例 #20
0
    def test_getTransactionsByAddress(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            walletd._public_stub.GetMiniTransactionsByAddress = Mock(
                return_value=xrd_pb2.GetMiniTransactionsByAddressResp(mini_transactions=[],
                                                                      balance=0))

            resp = service.GetTransactionsByAddress(
                xrdwallet_pb2.TransactionsByAddressReq(address=get_alice_xmss(4).qaddress), context=None)

            self.assertEqual(resp.code, 0)
            self.assertEqual(len(resp.mini_transactions), 0)
            self.assertEqual(resp.balance, 0)
コード例 #21
0
    def test_removeAddress(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            resp = service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)
            address = resp.address

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(len(resp.addresses), 1)

            resp = service.RemoveAddress(xrdwallet_pb2.RemoveAddressReq(address=address), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(len(resp.addresses), 0)
コード例 #22
0
    def test_getBlockByNumber(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            block = xrd_pb2.Block()
            block.header.hash_header = b'001122'
            block.header.block_number = 1

            walletd._public_stub.GetBlockByNumber = Mock(
                return_value=xrd_pb2.GetBlockResp(block=block))

            resp = service.GetBlockByNumber(xrdwallet_pb2.BlockByNumberReq(block_number=1), context=None)

            self.assertEqual(resp.code, 0)
            self.assertEqual(resp.block.header.hash_header, bin2hstr(block.header.hash_header))
            self.assertEqual(resp.block.header.block_number, block.header.block_number)
コード例 #23
0
    def test_getOTS(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            ots_bitfield_by_page = xrd_pb2.OTSBitfieldByPage(ots_bitfield=[b'\x00'] * 10,
                                                             page_number=1)
            walletd._public_stub.GetOTS = Mock(
                return_value=xrd_pb2.GetOTSResp(ots_bitfield_by_page=[ots_bitfield_by_page],
                                                next_unused_ots_index=1,
                                                unused_ots_index_found=True))

            resp = service.GetOTS(xrdwallet_pb2.OTSReq(address=self.qaddress), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(len(resp.ots_bitfield_by_page), 1)
            self.assertEqual(resp.ots_bitfield_by_page[0], ots_bitfield_by_page)
            self.assertEqual(resp.next_unused_ots_index, 1)
コード例 #24
0
    def test_getTransaction(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            tx = xrd_pb2.Transaction()
            tx.fee = 10
            tx.transaction_hash = b'1234'
            tx.message.message_hash = b'hello'
            pk = '01020016ecb9f39b9f4275d5a49e232346a15ae2fa8c50a2927daeac189b8c5f2d1' \
                 '8bc4e3983bd564298c49ae2e7fa6e28d4b954d8cd59398f1225b08d6144854aee0e'
            tx.public_key = bytes(hstr2bin(pk))

            walletd._public_stub.GetTransaction = Mock(
                return_value=xrd_pb2.GetTransactionResp(tx=tx, confirmations=10))

            resp = service.GetTransaction(xrdwallet_pb2.TransactionReq(tx_hash=tx.transaction_hash), context=None)

            self.assertEqual(resp.code, 0)
            self.assertIsNotNone(resp.tx)
            self.assertEqual(resp.tx.transaction_hash, bin2hstr(tx.transaction_hash))
            self.assertEqual(resp.confirmations, "10")
コード例 #25
0
    def test_changePassphrase(self):
        with set_xrd_dir("wallet_ver1"):
            walletd = WalletD()
            service = WalletAPIService(walletd)

            service.AddNewAddress(xrdwallet_pb2.AddNewAddressReq(), context=None)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)
            self.assertEqual(len(resp.addresses), 1)

            resp = service.EncryptWallet(xrdwallet_pb2.EncryptWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.ListAddresses(xrdwallet_pb2.ListAddressesReq(), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.LockWallet(xrdwallet_pb2.LockWalletReq(), context=None)
            self.assertEqual(resp.code, 0)

            new_passphrase = "Hello World"
            resp = service.ChangePassphrase(
                xrdwallet_pb2.ChangePassphraseReq(oldPassphrase=self.passphrase,
                                                  newPassphrase=new_passphrase), context=None)
            self.assertEqual(resp.code, 0)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=self.passphrase), context=None)
            self.assertEqual(resp.code, 1)

            resp = service.UnlockWallet(xrdwallet_pb2.UnlockWalletReq(passphrase=new_passphrase), context=None)
            self.assertEqual(resp.code, 0)