change convention

This commit is contained in:
Alfredo Garcia 2020-01-20 12:23:52 -03:00
parent 574963ef87
commit 7cb45243fe
2 changed files with 12 additions and 11 deletions

View File

@ -101,15 +101,16 @@ class MerkleBlockTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getblock("0")["height"], 0)
assert_raises(JSONRPCException, self.nodes[0].getblock, ["108"])
assert_equal(self.nodes[0].getblock("107")["height"], 107)
assert_equal(self.nodes[0].getblock("-1")["height"], 106)
assert_equal(self.nodes[0].getblock("-2")["height"], 105)
assert_equal(self.nodes[0].getblock("-20")["height"], 87)
assert_equal(self.nodes[0].getblock("-107")["height"], 0)
assert_raises(JSONRPCException, self.nodes[0].getblock, ["-108"])
assert_equal(self.nodes[0].getblock("-1")["height"], 107)
assert_equal(self.nodes[0].getblock("-2")["height"], 106)
assert_equal(self.nodes[0].getblock("-20")["height"], 88)
assert_equal(self.nodes[0].getblock("-107")["height"], 1)
assert_equal(self.nodes[0].getblock("-108")["height"], 0)
assert_raises(JSONRPCException, self.nodes[0].getblock, ["-109"])
# Test getblockhash negative heights
hash = self.nodes[0].getblockhash(106)
assert_equal(self.nodes[0].getblockhash(-1), hash)
assert_equal(self.nodes[0].getblockhash(-1), self.nodes[0].getblockhash(107))
assert_equal(self.nodes[0].getblockhash(-2), self.nodes[0].getblockhash(106))
if __name__ == '__main__':
MerkleBlockTest().main()

View File

@ -576,7 +576,7 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
"getblockhash index\n"
"\nReturns hash of block in best-block-chain at index provided.\n"
"\nArguments:\n"
"1. index (numeric, required) The block index. If negative then the index will be: last known valid block - abs(index)\n"
"1. index (numeric, required) The block index. If negative then -1 is the last known valid block\n"
"\nResult:\n"
"\"hash\" (string) The block hash\n"
"\nExamples:\n"
@ -589,7 +589,7 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
int nHeight = params[0].get_int();
if(nHeight < 0) {
nHeight += chainActive.Height();
nHeight += chainActive.Height() + 1;
}
if (nHeight < 0 || nHeight > chainActive.Height())
@ -665,7 +665,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
"If verbosity is 1, returns an Object with information about the block.\n"
"If verbosity is 2, returns an Object with information about the block and information about each transaction. \n"
"\nArguments:\n"
"1. \"hash|height\" (string, required) The block hash or height. Height can be negative, if so: height = last known valid block - abs(height)\n"
"1. \"hash|height\" (string, required) The block hash or height. Height can be negative where -1 is the last known valid block\n"
"2. verbosity (numeric, optional, default=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data\n"
"\nResult (for verbosity = 0):\n"
"\"data\" (string) A string that is serialized, hex-encoded data for the block.\n"
@ -725,7 +725,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
}
if(nHeight < 0) {
nHeight += chainActive.Height();
nHeight += chainActive.Height() + 1;
}
if (nHeight < 0 || nHeight > chainActive.Height()) {