[Tests] Add prioritisetransaction RPC test #7063

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
5 participants
@sdaftuar
Member

sdaftuar commented Nov 19, 2015

@morcos mentioned in #6898 (comment) that there's no rpc test for prioritisetransaction. This adds a simple test to exercise this logic.

In writing this test I discovered something unusual -- if you try to set a fee delta using prioritisetransaction that is negative and greater in magnitude than the transaction's fee, you get incorrect results. The CFeeRate constructor that takes a fee and size doesn't work if you pass in a negative fee. I don't really understand the details of how conversion and type promotion work in this kind of situation, but as far as I can tell, on my machine, I think the compiler promotes the int64_t nFeePaid to a uint64_t (nSize is a size_t):

nSatoshisPerK = nFeePaid*1000/nSize;

Link to the code:

nSatoshisPerK = nFeePaid*1000/nSize;

I think this arithmetic may work on a 32-bit platform, because it looked to me like doing arithmetic with an unsigned int rather than a size_t appeared to work.

Anyway I expect that #6898 will fix prioritisetransaction to work properly with fee deltas that bring the modified fee below 0, so I just avoided that issue for now in this test; I can update it in the future to include that case after #6898.

@MarcoFalke

View changes

qa/rpc-tests/prioritise_transaction.py
+ mempool = self.nodes[0].getrawmempool()
+ assert(txids[0][0] not in mempool)
+ assert(txids[0][1] in mempool)
+ print "Prioritised transaction mined: success"

This comment has been minimized.

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

Nit: Shouldn't the print appear in front of assert? So when it fails, we know where it did (Not just by line number)?

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

Nit: Shouldn't the print appear in front of assert? So when it fails, we know where it did (Not just by line number)?

This comment has been minimized.

@sdaftuar

sdaftuar Nov 19, 2015

Member

Well then it would be printing something incorrect if the assertion failed. I guess I could add a different print statement above the asserts, but not sure it's worth it? If the assertion fails I think the stack trace is informative enough, and I don't think the style here is inconsistent with the rest of the tests.

@sdaftuar

sdaftuar Nov 19, 2015

Member

Well then it would be printing something incorrect if the assertion failed. I guess I could add a different print statement above the asserts, but not sure it's worth it? If the assertion fails I think the stack trace is informative enough, and I don't think the style here is inconsistent with the rest of the tests.

This comment has been minimized.

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

Where would you put a comment, when you had put one? Then just replace the # with print and you get in L109:

print "Assert that prioritised transaction was mined"

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

Where would you put a comment, when you had put one? Then just replace the # with print and you get in L109:

print "Assert that prioritised transaction was mined"

This comment has been minimized.

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

rest of the tests

I see no reason to do this. You could as well just remove the print completely.

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

rest of the tests

I see no reason to do this. You could as well just remove the print completely.

@@ -19,9 +19,6 @@
# 4 bytes of OP_TRUE and push 2-byte redeem script of "OP_1 OP_DROP" or "OP_2 OP_DROP"
SCRIPT_SIG = ["0451025175", "0451025275"]
-def satoshi_round(amount):
- return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)

This comment has been minimized.

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

Long overdue to have this moved to the test framework. Thanks!

@MarcoFalke

MarcoFalke Nov 19, 2015

Member

Long overdue to have this moved to the test framework. Thanks!

@jonasschnelli jonasschnelli added the Tests label Nov 20, 2015

@sipa

This comment has been minimized.

Show comment
Hide comment
@sipa

sipa Nov 28, 2015

Member

utACK

Member

sipa commented Nov 28, 2015

utACK

@sdaftuar

This comment has been minimized.

Show comment
Hide comment
@sdaftuar

sdaftuar Nov 30, 2015

Member

Rebased, moved prints

Member

sdaftuar commented Nov 30, 2015

Rebased, moved prints

laanwj added a commit that referenced this pull request Dec 1, 2015

Merge pull request #7063
2b31ab9 Add rpc test for prioritisetransaction (Suhas Daftuar)
6e8b07f Add rounding helper function to util.py (Suhas Daftuar)
@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Dec 1, 2015

Member

Merged via 6abf6eb (needed trivial rebase change in rpc-tests.py)

Member

laanwj commented Dec 1, 2015

Merged via 6abf6eb (needed trivial rebase change in rpc-tests.py)

@MarcoFalke

This comment has been minimized.

Show comment
Hide comment
Member

MarcoFalke commented Dec 1, 2015

utACK 6abf6eb

@MarcoFalke

This comment has been minimized.

Show comment
Hide comment
@MarcoFalke

MarcoFalke Dec 1, 2015

Member

PR can be closed!?

Member

MarcoFalke commented Dec 1, 2015

PR can be closed!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment