-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: assert failure on non-policy asset consolidation in CreateTransactionInternal #1277
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2e7125c
fix: assert failure on non-policy asset consolidation in CreateTransa…
goatpig d3ffd2a
test: add functional test for issue #1259
delta1 5b72ae2
coinselection: fail if each non-policy asset doesn't have a solution
jamesdorfman 04cba29
coinselection: fail KnapsackSolver if the policy asset doesn't have a…
jamesdorfman 39be0f0
wallet: fix tx credit calculation issues introduced in merge of bitco…
jamesdorfman e02024e
test: add new elements_code_tutorial functional test
jamesdorfman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2017-2020 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Tests reissuance functionality from the elements code tutorial | ||
See: https://elementsproject.org/elements-code-tutorial/reissuing-assets | ||
|
||
TODO: add functionality from contrib/assets_tutorial/assets_tutorial.py into here | ||
""" | ||
from test_framework.blocktools import COINBASE_MATURITY | ||
from test_framework.test_framework import BitcoinTestFramework | ||
|
||
class WalletTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 2 | ||
self.extra_args = [[ | ||
"-blindedaddresses=1", | ||
"-initialfreecoins=2100000000000000", | ||
"-con_blocksubsidy=0", | ||
"-con_connect_genesis_outputs=1", | ||
"-txindex=1", | ||
]] * self.num_nodes | ||
self.extra_args[0].append("-anyonecanspendaremine=1") | ||
|
||
def skip_test_if_missing_module(self): | ||
self.skip_if_no_wallet() | ||
|
||
def run_test(self): | ||
self.generate(self.nodes[0], COINBASE_MATURITY + 1) | ||
self.sync_all() | ||
|
||
assert self.nodes[0].dumpassetlabels() == {'bitcoin': 'b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23'} | ||
|
||
issuance = self.nodes[0].issueasset(100, 1) | ||
asset = issuance['asset'] | ||
#token = issuance['token'] | ||
issuance_txid = issuance['txid'] | ||
issuance_vin = issuance['vin'] | ||
|
||
assert len(self.nodes[0].listissuances()) == 2 # asset & reisuance token | ||
|
||
self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress(), invalid_call=False) # confirm the tx | ||
|
||
issuance_addr = self.nodes[0].gettransaction(issuance_txid)['details'][0]['address'] | ||
self.nodes[1].importaddress(issuance_addr) | ||
|
||
issuance_key = self.nodes[0].dumpissuanceblindingkey(issuance_txid, issuance_vin) | ||
self.nodes[1].importissuanceblindingkey(issuance_txid, issuance_vin, issuance_key) | ||
issuances = self.nodes[1].listissuances() | ||
assert (issuances[0]['tokenamount'] == 1 and issuances[0]['assetamount'] == 100) \ | ||
or (issuances[1]['tokenamount'] == 1 and issuances[1]['assetamount'] == 100) | ||
|
||
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) | ||
self.generate(self.nodes[0], 10) | ||
|
||
reissuance_tx = self.nodes[0].reissueasset(asset, 99) | ||
reissuance_txid = reissuance_tx['txid'] | ||
issuances = self.nodes[0].listissuances(asset) | ||
assert len(issuances) == 2 | ||
assert issuances[0]['isreissuance'] or issuances[1]['isreissuance'] | ||
|
||
self.generate(self.nodes[0], 1) | ||
|
||
expected_amt = { | ||
'bitcoin': 0, | ||
'8f1560e209f6bcac318569a935a0b2513c54f326ee4820ccd5b8c1b1b4632373': 0, | ||
'4fa41f2929d4bf6975a55967d9da5b650b6b9bfddeae4d7b54b04394be328f7f': 99 | ||
} | ||
assert self.nodes[0].gettransaction(reissuance_txid)['amount'] == expected_amt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could use some asserts of the balances before and after this whole process. not a showstopper though. |
||
|
||
if __name__ == '__main__': | ||
WalletTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2017-2020 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
"""Tests that fundrawtransaction correctly handles the case of sending many | ||
inputs of an issued asset, with no policy asset recipient. | ||
|
||
See: https://github.com/ElementsProject/elements/issues/1259 | ||
|
||
This test issues an asset and creates many utxos, which are then used as inputs in | ||
a consolidation transaction created with the various raw transaction calls. | ||
""" | ||
from decimal import Decimal | ||
|
||
from test_framework.blocktools import COINBASE_MATURITY | ||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import ( | ||
assert_equal, | ||
) | ||
|
||
class WalletTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 3 | ||
self.extra_args = [[ | ||
"-blindedaddresses=1", | ||
"-initialfreecoins=2100000000000000", | ||
"-con_blocksubsidy=0", | ||
"-con_connect_genesis_outputs=1", | ||
"-txindex=1", | ||
]] * self.num_nodes | ||
self.extra_args[0].append("-anyonecanspendaremine=1") | ||
|
||
def skip_test_if_missing_module(self): | ||
self.skip_if_no_wallet() | ||
|
||
def run_test(self): | ||
self.generate(self.nodes[0], COINBASE_MATURITY + 1) | ||
self.sync_all() | ||
|
||
self.log.info(f"Send some policy asset to node 1") | ||
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 10) | ||
self.generate(self.nodes[0], 1) | ||
|
||
self.log.info(f"Issuing an asset from node 0") | ||
issuance = self.nodes[0].issueasset(1000, 1, True) | ||
self.generate(self.nodes[0], 1) | ||
asset = issuance["asset"] | ||
self.log.info(f"Asset ID is {asset}") | ||
|
||
# create many outputs of the new asset on node 1 | ||
num_utxos = 45 | ||
value = 10 | ||
fee_rate = 10 | ||
self.log.info(f"Sending {num_utxos} utxos of asset to node 1") | ||
for i in range(num_utxos): | ||
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), value, "", "", False, False, None, None, None, asset, False, fee_rate, True) | ||
self.generate(self.nodes[0], 1) | ||
|
||
# create a raw tx on node 1 consolidating the asset utxos | ||
self.log.info(f"Create the raw consolidation transaction") | ||
hex = self.nodes[1].createrawtransaction([], [{ 'asset': asset, self.nodes[2].getnewaddress(): num_utxos * value }]) | ||
|
||
# fund the raw tx | ||
self.log.info(f"Fund the raw transaction") | ||
raw_tx = self.nodes[1].fundrawtransaction(hex, True) | ||
|
||
# blind and sign the tx | ||
self.log.info(f"Blind and sign the raw transaction") | ||
hex = self.nodes[1].blindrawtransaction(raw_tx['hex']) | ||
signed_tx = self.nodes[1].signrawtransactionwithwallet(hex) | ||
assert_equal(signed_tx['complete'], True) | ||
|
||
# decode tx | ||
tx = self.nodes[1].decoderawtransaction(signed_tx['hex']) | ||
|
||
assert_equal(len(tx['vin']), num_utxos + 1) | ||
assert_equal(len(tx['vout']), 3) | ||
assert_equal(tx['fee'], {'b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23': Decimal('0.00112380')}) # fee output | ||
|
||
# send and mine the tx | ||
self.log.info(f"Send the raw transaction") | ||
self.nodes[1].sendrawtransaction(signed_tx['hex']) | ||
self.generate(self.nodes[1], 1) | ||
self.sync_all() | ||
balance = self.nodes[2].getbalance() | ||
assert_equal(balance[asset], Decimal(num_utxos * value)) | ||
|
||
|
||
if __name__ == '__main__': | ||
WalletTest().main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these args should match the conf files from the tutorial. can be done as part of #1278