-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Improve createrawtransaction functional tests #11877
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
Conversation
Relates to #11872 (#11872 (comment)). |
assert_raises_rpc_error(-5, "Invalid Bitcoin address", self.nodes[0].createrawtransaction, [], {'foo': 0}) | ||
assert_raises_rpc_error(-3, "Invalid amount", self.nodes[0].createrawtransaction, [], {address: 'foo'}) | ||
assert_raises_rpc_error(-3, "Amount out of range", self.nodes[0].createrawtransaction, [], {address: -1}) | ||
assert_raises_rpc_error(-8, "Invalid parameter, duplicated address: %s" % address, self.nodes[0].createrawtransaction, [], multidict([(address, 1), (address, 1)])) |
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.
So there is already a check for duplicated address?
That's great!
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.
Yes, createrawtransaction
and sendmany
RPC's check for duplicated address.
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.
Indeed! I hadn't expected a check here because passing this is tricky in JSON object format.
utACK 0df137b |
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.
utACK 0df137b8c719a904c792240a0e373ca38c334443
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.
Tested ACK. Great coverage - thanks @promag . One request for an additional comment.
@@ -15,6 +15,16 @@ | |||
from test_framework.test_framework import BitcoinTestFramework | |||
from test_framework.util import * | |||
|
|||
|
|||
class multidict(dict): |
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.
Can you add a comment for this please? Something like:
"""Dictionary that allows duplicate keys.
Constructed with a list of (key, value) tuples. When dumped by the json module, will output invalid json with repeated keys, eg:
>>> json.dumps(multidict([(1,2),(1,2)])
'{"1": 2, "1": 2}'
Used to test calls to rpc methods with invalid repeated keys in the json object."""
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.
Yeah submitting JSON objects in deterministic order and with potentially duplicated keys is the only thing it's good for, it's not quite a traditional multidict implementation.
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.
Done.
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, []) | ||
|
||
# Test `createrawtransaction` invalid extra parameters | ||
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [], {}, 0, False, 'foo') |
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.
nit: My personal style preference is to use named args when passing unnamed parameters. Not sure what others think.
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.
In this case I'm not sure, because that will throw Unknown named parameter
. But for other cases you mean?
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, inputs=[], outputs={}, locktime=0, replaceable=False)
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.
Ah, right. Won't work in this case.
Concept ACK. |
0df137b
to
88af502
Compare
According to what others reviewed, only change should be adding a comment, so trivial to re-ACK. (ping @jnewbery )
|
Tested ACK 88af502. Comment looks good 🙂 |
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
88af502 test: Add createrawtransaction functional tests (João Barbosa) 27c6199 test: Add multidict to support dictionary with duplicate key (laanwj) (João Barbosa) 320669a rpc: Validate replaceable type in createrawtransaction (João Barbosa) Pull request description: This was motivated by the `Invalid parameter, duplicated address` test. Credit to @laanwj for `multidict` implementation. Tree-SHA512: a87139ae11004b73b467db1e8a072b75e23a0622b173a5668eed383b3575d8abc709817ddd2dfdc53f55afc90750fb61331199ad5de38c1ef6d482f2bc220f74
This was motivated by the
Invalid parameter, duplicated address
test.Credit to @laanwj for
multidict
implementation.