Skip to content

Instantly share code, notes, and snippets.

@fjahr
Created December 31, 2019 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjahr/d56b68e58b4275ef52cd5f4eb50b1d4e to your computer and use it in GitHub Desktop.
Save fjahr/d56b68e58b4275ef52cd5f4eb50b1d4e to your computer and use it in GitHub Desktop.
Destination Group coin selection

This succeeds:

  • 50 outputs of 1 BTC in the same destination
  • Send 10.5 BTC
  • 2 groups are used for the inputs, in total there are 20 inputs
    def test_destination_groupings(self):
        '''
        If a destination has more than 10 outputs, exactly 10 outputs should
        be used when spending from that destination
        '''
        self.log.info("Test destination groupings")

        new_addr = self.nodes[1].getnewaddress()
        ret_addr = self.nodes[0].getnewaddress()

        for _ in range(50):
            self.nodes[0].sendtoaddress(new_addr, 1)

        self.nodes[0].generate(1)
        self.sync_all()

        txid = self.nodes[1].sendtoaddress(ret_addr, 10.5)
        inputs = self.nodes[1].getrawtransaction(txid, 1)["vin"]

        assert_equal(len(inputs), 20)

This fails:

  • 11 outputs of 1 BTC in the same destination
  • Send 10.5 BTC
  • Results in Insufficient funds
    def test_destination_groupings(self):
        '''
        If a destination has more than 10 outputs, exactly 10 outputs should
        be used when spending from that destination
        '''
        self.log.info("Test destination groupings")

        new_addr = self.nodes[1].getnewaddress()
        ret_addr = self.nodes[0].getnewaddress()

        for _ in range(21):
            self.nodes[0].sendtoaddress(new_addr, 1)

        self.nodes[0].generate(1)
        self.sync_all()

        txid = self.nodes[1].sendtoaddress(ret_addr, 10.5)
        inputs = self.nodes[1].getrawtransaction(txid, 1)["vin"]

        assert_equal(len(inputs), 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment