Update .new_address() method to return subaddress index

This commit is contained in:
Michał Sałaban 2019-09-09 12:57:06 +02:00
parent 6bf97ddca2
commit c2af7acc31
8 changed files with 75 additions and 6 deletions

View file

@ -0,0 +1,26 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"subaddress_accounts": [
{
"account_index": 0,
"balance": 111141601989972,
"base_address": "56cXYWG13YKaT9z1aEy2hb9TZNnxrW3zE9S4nTQVDux5Qq7UYsmjuux3Zstxkorj9HAufyWLU3FwHW4uERQF6tkeUVogGN3",
"label": "Primary account",
"tag": "",
"unlocked_balance": 111141601989972
},
{
"account_index": 1,
"balance": 1000000000000,
"base_address": "79kTZg96pMf2Dt9rLEWnLzTUB8XC1wMhxaJyxa79hJu6bK9CfFnfbSL1GJNZbqhv9xPqJhRj2Yfb7QUWa2zeEw56H4KiUfN",
"label": "Untitled account",
"tag": "",
"unlocked_balance": 1000000000000
}
],
"total_balance": 112141601989972,
"total_unlocked_balance": 112141601989972
}
}

View file

@ -0,0 +1,8 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"address": "7AEBRUmNcjhUjiqdVpeKKYiAVZ216AYdhBFx8UUfjPhWdKujoosnsUtHCohLcYWUXFdNiqnBsMmCFCyDkSmat3Ys4H4yHUp",
"address_index": 232
}
}

View file

@ -0,0 +1,8 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"address": "74PY6ZcC4N5U4MN4aTPQE58d35zGsFYK17NBx9GA66Bc37V5q6UU7eG6uLExg5m2TH5DJZc9BuEs64jEStTSV2PNLt2Y3wb",
"address_index": 3
}
}

View file

@ -7,7 +7,7 @@ except ImportError:
from mock import patch, Mock
from monero.wallet import Wallet
from monero.address import BaseAddress, Address
from monero.address import BaseAddress, Address, SubAddress
from monero.seed import Seed
from monero.transaction import IncomingPayment, OutgoingPayment, Transaction
from monero.backends.jsonrpc import JSONRPCWallet
@ -165,6 +165,25 @@ class JSONRPCWalletTestCase(JSONTestCase):
self.assertEqual('account 1', w.accounts[1].label)
self.assertEqual([acc0, acc1], w.accounts)
@responses.activate
def test_new_address(self):
responses.add(responses.POST, self.jsonrpc_url,
json=self._read('test_new_address-00-get_accounts.json'),
status=200)
responses.add(responses.POST, self.jsonrpc_url,
json=self._read('test_new_address-10-new_address_account_0.json'),
status=200)
responses.add(responses.POST, self.jsonrpc_url,
json=self._read('test_new_address-20-new_address_account_1.json'),
status=200)
w = Wallet(JSONRPCWallet())
subaddr, index = w.new_address()
self.assertIsInstance(subaddr, SubAddress)
self.assertIsInstance(index, int)
subaddr, index = w.accounts[1].new_address()
self.assertIsInstance(subaddr, SubAddress)
self.assertIsInstance(index, int)
@patch('monero.backends.jsonrpc.requests.post')
def test_incoming_confirmed(self, mock_post):
mock_post.return_value.status_code = 200