Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_labels.py
Show All 32 Lines | def run_test(self): | ||||
# the same address, so we call twice to get two addresses w/50 each | # the same address, so we call twice to get two addresses w/50 each | ||||
node.generatetoaddress( | node.generatetoaddress( | ||||
nblocks=1, address=node.getnewaddress( | nblocks=1, address=node.getnewaddress( | ||||
label='coinbase')) | label='coinbase')) | ||||
node.generatetoaddress( | node.generatetoaddress( | ||||
nblocks=101, | nblocks=101, | ||||
address=node.getnewaddress( | address=node.getnewaddress( | ||||
label='coinbase')) | label='coinbase')) | ||||
assert_equal(node.getbalance(), 100) | assert_equal(node.getbalance(), 100000000) | ||||
# there should be 2 address groups | # there should be 2 address groups | ||||
# each with 1 address with a balance of 50 Bitcoins | # each with 1 address with a balance of 50 Bitcoins | ||||
address_groups = node.listaddressgroupings() | address_groups = node.listaddressgroupings() | ||||
assert_equal(len(address_groups), 2) | assert_equal(len(address_groups), 2) | ||||
# the addresses aren't linked now, but will be after we send to the | # the addresses aren't linked now, but will be after we send to the | ||||
# common address | # common address | ||||
linked_addresses = set() | linked_addresses = set() | ||||
for address_group in address_groups: | for address_group in address_groups: | ||||
assert_equal(len(address_group), 1) | assert_equal(len(address_group), 1) | ||||
assert_equal(len(address_group[0]), 3) | assert_equal(len(address_group[0]), 3) | ||||
assert_equal(address_group[0][1], 50) | assert_equal(address_group[0][1], 50000000) | ||||
assert_equal(address_group[0][2], 'coinbase') | assert_equal(address_group[0][2], 'coinbase') | ||||
linked_addresses.add(address_group[0][0]) | linked_addresses.add(address_group[0][0]) | ||||
# send 50 from each address to a third address not in this wallet | # send 50 from each address to a third address not in this wallet | ||||
common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr" | common_address = "msf4WtN1YQKXvNtvdFYt9JBnUD2FB41kjr" | ||||
node.sendmany( | node.sendmany( | ||||
amounts={common_address: 100}, | amounts={common_address: 100000000}, | ||||
subtractfeefrom=[common_address], | subtractfeefrom=[common_address], | ||||
minconf=1, | minconf=1, | ||||
) | ) | ||||
# there should be 1 address group, with the previously | # there should be 1 address group, with the previously | ||||
# unlinked addresses now linked (they both have 0 balance) | # unlinked addresses now linked (they both have 0 balance) | ||||
address_groups = node.listaddressgroupings() | address_groups = node.listaddressgroupings() | ||||
assert_equal(len(address_groups), 1) | assert_equal(len(address_groups), 1) | ||||
assert_equal(len(address_groups[0]), 2) | assert_equal(len(address_groups[0]), 2) | ||||
assert_equal(set([a[0] for a in address_groups[0]]), linked_addresses) | assert_equal(set([a[0] for a in address_groups[0]]), linked_addresses) | ||||
assert_equal([a[1] for a in address_groups[0]], [0, 0]) | assert_equal([a[1] for a in address_groups[0]], [0, 0]) | ||||
node.generate(1) | node.generate(1) | ||||
# we want to reset so that the "" label has what's expected. | # we want to reset so that the "" label has what's expected. | ||||
# otherwise we're off by exactly the fee amount as that's mined | # otherwise we're off by exactly the fee amount as that's mined | ||||
# and matures in the next 100 blocks | # and matures in the next 100 blocks | ||||
amount_to_send = 1.0 | amount_to_send = 1000000 | ||||
# Create labels and make sure subsequent label API calls | # Create labels and make sure subsequent label API calls | ||||
# recognize the label/address associations. | # recognize the label/address associations. | ||||
labels = [Label(name) | labels = [Label(name) | ||||
for name in ("a", "b", "c", "d", "e")] | for name in ("a", "b", "c", "d", "e")] | ||||
for label in labels: | for label in labels: | ||||
address = node.getnewaddress(label.name) | address = node.getnewaddress(label.name) | ||||
label.add_receive_address(address) | label.add_receive_address(address) | ||||
Show All 18 Lines | def run_test(self): | ||||
for i, label in enumerate(labels): | for i, label in enumerate(labels): | ||||
to_label = labels[(i + 1) % len(labels)] | to_label = labels[(i + 1) % len(labels)] | ||||
node.sendtoaddress(to_label.addresses[0], amount_to_send) | node.sendtoaddress(to_label.addresses[0], amount_to_send) | ||||
node.generate(1) | node.generate(1) | ||||
for label in labels: | for label in labels: | ||||
address = node.getnewaddress(label.name) | address = node.getnewaddress(label.name) | ||||
label.add_receive_address(address) | label.add_receive_address(address) | ||||
label.verify(node) | label.verify(node) | ||||
assert_equal(node.getreceivedbylabel(label.name), 2) | assert_equal(node.getreceivedbylabel(label.name), 2000000) | ||||
label.verify(node) | label.verify(node) | ||||
node.generate(101) | node.generate(101) | ||||
# Check that setlabel can assign a label to a new unused address. | # Check that setlabel can assign a label to a new unused address. | ||||
for label in labels: | for label in labels: | ||||
address = node.getnewaddress() | address = node.getnewaddress() | ||||
node.setlabel(address, label.name) | node.setlabel(address, label.name) | ||||
label.add_address(address) | label.add_address(address) | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |