Commit graph

95 commits

Author SHA1 Message Date
Sjors Provoost
285fe9fb51
rpc: add test for waitforblock and waitfornewblock 2024-09-17 09:27:43 +02:00
Martin Zumsande
6a1aa510e3 rpc: check block index before reading block / undo data
This avoids low-level log errors that are supposed to only occur when
there is an actual problem with the block on disk missing unexpectedly,
but not in the case where the block and/or undo data are expected not to be there.

It changes behavior such that in the first case (block index indicates
data is available but retrieving it fails) an error is thrown.

It also adjusts a functional tests that tried to simulate not
having undo data (but having block data) by deleting the undo file.
This situation should occur reality because block and undo data are pruned together.
Instead, test this situation with a block that hasn't been connected.
2024-09-13 10:50:49 -04:00
Martin Zumsande
69fc867ea1 test: add coverage to getblock and getblockstats
also removes an unnecessary newline.

Co-authored-by: tdb3 <106488469+tdb3@users.noreply.github.com>
2024-09-13 10:50:49 -04:00
Sjors Provoost
dd154b0568
consensus: lower regtest nPowTargetTimespan to 144
This currently has no effect due to fPowNoRetargeting,
except for the getnetworkhashps when called with -1.

It will when the next commit enforces the timewarp attack mitigation on regtest.
2024-08-20 10:07:30 +02:00
Hennadii Stepanov
a0473442d1
scripted-diff: Add __file__ argument to BitcoinTestFramework.init()
-BEGIN VERIFY SCRIPT-
sed -i -e 's/\s*().main\s*()/(__file__).main()/' $(git ls-files test/functional/*.py)
sed -i -e 's/def __init__(self)/def __init__(self, test_file)/' test/functional/test_framework/test_framework.py
-END VERIFY SCRIPT-
2024-07-16 22:06:47 +01:00
Jameson Lopp
9ac114e5cd
Throw error if invalid parameters passed to getnetworkhashps RPC endpoint 2023-11-07 12:58:42 -05:00
Andrew Chow
5f88622191
Merge bitcoin/bitcoin#27852: test: add coverage to rpc_blockchain.py
376dc2cfb3 test: add coverage to rpc_blockchain.py (kevkevin)

Pull request description:

  Included a test that checks the functionality of setting
  the first param of getnetworkhashps to negative value returns
  the average network hashes per second from the last difficulty change.

ACKs for top commit:
  jlopp:
    tACK 376dc2cfb3
  achow101:
    ACK 376dc2cfb3
  ismaelsadeeq:
    Tested ACK 376dc2cfb3
  pablomartin4btc:
    tACK 376dc2cfb3

Tree-SHA512: 02d52f622e9cb7a1240c5d124510dd75d03f696f119b2625b0befd60b004ec50ff1a2d5515e0e227601adeecd837e0778ed131ee2a8c5f75f1b824be711213a7
2023-11-02 15:19:37 -04:00
Fabian Jahr
cb0336817e
scripted-diff: Rename hash_serialized_2 to hash_serialized_3
-BEGIN VERIFY SCRIPT-
sed -i 's/hash_serialized_2/hash_serialized_3/g' $( git grep -l 'hash_serialized_2' ./src ./contrib ./test )
-END VERIFY SCRIPT-
2023-10-20 22:53:06 +02:00
kevkevin
376dc2cfb3
test: add coverage to rpc_blockchain.py
Included a test that checks the functionality of setting
the first param of getnetworkhashps to negative value returns
the average network hashes per second from the last difficulty change.

Co-authored-by: ismaelsadeeq <ask4ismailsadiq@gmail.com>
2023-09-25 00:00:19 -05:00
MarcoFalke
fafe43cb6c
scripted-diff: Use blocks_path where possible
-BEGIN VERIFY SCRIPT-
  sed -i 's|].chain_path / "blocks"|].blocks_path|g' $(git grep -l chain_path)
-END VERIFY SCRIPT-
2023-07-25 15:51:36 +02:00
MarcoFalke
aaaa3aefbd
test: Use TestNode *_path properties where possible
Seems odd to place the burden on test writers to hardcode the chain or
datadir path for the nodes under test.
2023-06-21 08:49:18 +02:00
dergoegge
05eeba2c5f [test] Add manual prune startup test case 2023-03-13 13:10:11 +01:00
MarcoFalke
fafeddfe0e
rpc: Throw more user friendly arg type check error 2023-01-20 13:26:47 +01:00
Jon Atack
459cb637ac script, test: fix python linter E275 errors with flake8 5.0.4 2023-01-03 10:59:56 -08:00
Hennadii Stepanov
306ccd4927
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
- 2021: f47dda2c58
- 2020: fa0074e2d8
- 2019: aaaaad6ac9
2022-12-24 23:49:50 +00:00
MacroFake
fafc96aaf4
test: Test year 2106 block timestamps
* Use maximum timestamp in getblocktemplate test
* Mine block with maximum timestamp and MTP in blockchain test
2022-10-20 14:45:50 +02:00
furszy
55566630c6
rpc: treat univalue type check error as RPC_TYPE_ERROR, not RPC_MISC_ERROR
By throwing a custom exception from `Univalue::checkType` (instead of a plain
std::runtime_error) and catching it on the RPC server request handler.

So we properly return RPC_TYPE_ERROR (-3) on arg type errors and
not the general RPC_MISC_ERROR (-1).
2022-09-15 10:24:53 -03:00
MacroFake
e864f2e4af
Merge bitcoin/bitcoin#25976: QA: rpc_blockchain: Test output of getblock verbosity 0, False, and True
f663b43df0 QA: rpc_blockchain: Test output of getblock verbosity 0, False, and True (Luke Dashjr)

Pull request description:

  Currently getblock's "verbosity" is documented as a NUM, though it has a fallback to Boolean for the (deprecated?) "verbose" alias.

  Since we've been doing more generic type-checking on RPC stuff, I think it would be a good idea to actually test the Boolean values work.

  I didn't see an existing test for verbosity=0, so this adds that too.

ACKs for top commit:
  aureleoules:
    ACK f663b43df0.

Tree-SHA512: 321a7795a2f32e469d28879dd323c85cb6b221828030e2a33ad9afd35a648191151a79b04e359b2f58314e43360f81c25f05be07deb42f61efdf556850a7266c
2022-09-05 14:15:29 +02:00
Luke Dashjr
f663b43df0 QA: rpc_blockchain: Test output of getblock verbosity 0, False, and True 2022-09-01 18:47:45 +00:00
Suhas Daftuar
ed6cddd98e Require callers of AcceptBlockHeader() to perform anti-dos checks
In order to prevent memory DoS, we must ensure that we don't accept a new
header into memory until we've performed anti-DoS checks, such as verifying
that the header is part of a sufficiently high work chain. This commit adds a
new argument to AcceptBlockHeader() so that we can ensure that all call-sites
which might cause a new header to be accepted into memory have to grapple with
the question of whether the header is safe to accept, or needs further
validation.

This patch also fixes two places where low-difficulty-headers could have been
processed without such validation (processing an unrequested block from the
network, and processing a compact block).

Credit to Niklas Gögge for noticing this issue, and thanks to Sjors Provoost
for test code.
2022-08-29 08:10:35 -04:00
MacroFake
fae5ce8795
univalue: Return more detailed type check error messages 2022-07-18 11:31:36 +02:00
Jon Atack
5d7c69b887
rpc: rename getdeploymentinfo status-next to status_next 2022-03-11 10:21:48 +01:00
MarcoFalke
fa462ea787
Avoid implicit-integer-sign-change in VerifyLoadedChainstate 2022-02-21 10:29:37 +01:00
MarcoFalke
d4e92d8436
Merge bitcoin/bitcoin#23508: Add getdeploymentinfo RPC
a380922891 Release notes for getdeploymentinfo rpc (Anthony Towns)
240cad09ba rpc: getdeploymentinfo: include signalling info (Anthony Towns)
376c0c6dae rpc: getdeploymentinfo: include block hash/height (Anthony Towns)
a7469bcd35 rpc: getdeploymentinfo: change stats to always refer to current period (Anthony Towns)
7f15c1841b rpc: getdeploymentinfo: allow specifying a blockhash other than tip (Anthony Towns)
fd826130a0 rpc: move softfork info from getblockchaininfo to getdeploymentinfo (Anthony Towns)

Pull request description:

  The aim of this PR is to improve the ability to monitor soft fork status. It first moves the softfork section from getblockchaininfo into a new RPC named getdeploymentinfo, which is then also able to query the status of forks at an arbitrary block rather than only at the tip. In addition, bip9 status is changed to indicate the status of the given block, rather than just for the next block, and an additional field is included to indicate whether each block in the signalling period signaled.

ACKs for top commit:
  laanwj:
    Code review and lightly tested ACK a380922891
  Sjors:
    tACK a380922891
  fjahr:
    tACK a380922891

Tree-SHA512: 7417d733b47629f229c5128586569909250481a3e94356c52fe67a03fd42cd81745246e384b98c4115fb61587714c879e4bc3e5f5c74407d9f8f6773472a33cb
2022-01-28 08:46:03 +01:00
Anthony Towns
240cad09ba rpc: getdeploymentinfo: include signalling info 2022-01-15 04:37:56 +10:00
Anthony Towns
376c0c6dae rpc: getdeploymentinfo: include block hash/height 2022-01-15 04:37:56 +10:00
Anthony Towns
a7469bcd35 rpc: getdeploymentinfo: change stats to always refer to current period
On a period boundary, getdeploymentinfo (and previously getblockchaininfo)
would report the status and statistics for the next block rather than
the current block. Change this to always report the status/statistics
of the current block, but add status-next to report the status for the
next block.
2022-01-15 04:37:56 +10:00
Anthony Towns
fd826130a0 rpc: move softfork info from getblockchaininfo to getdeploymentinfo 2022-01-15 04:37:56 +10:00
MarcoFalke
fa24a3df87
rpc: Quote user supplied strings in error messages 2021-12-13 15:18:35 +01:00
MarcoFalke
fa551b3bdd
Remove GetAdjustedTime from init.cpp 2021-11-30 17:19:49 +01:00
fanquake
ffdab41f94
Merge bitcoin/bitcoin#23474: test: scripted-diff cleanups after generate* changes
fac23c2114 scripted-diff: Bump copyright headers (MarcoFalke)
fa974f1f14 scripted-diff: Remove redundant sync_all and sync_blocks (MarcoFalke)
fad13991ae test: Properly set sync_fun in NodeNetworkLimitedTest (MarcoFalke)
faeff57709 test: Use 4 spaces for indentation (MarcoFalke)

Pull request description:

  Some cleanups after commit 94db963de5

ACKs for top commit:
  fanquake:
    ACK fac23c2114

Tree-SHA512: 5acfd5bb9679b41969d0fc6fc85801ccadcd6530ea692bac6352668e06fc7a9b0e1db3fd6fba435e84afe983d2eb07bd0a47c8364462bb7110004bd3d102b698
2021-11-16 11:22:06 +08:00
MarcoFalke
fac23c2114
scripted-diff: Bump copyright headers
The previous diff touched most files in ./test/, so bump the headers to
avoid having to touch them again for a bump later.

-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./test/
-END VERIFY SCRIPT-
2021-11-10 11:10:24 +01:00
Sebastian Falbesoner
4a2edf2bf7 test: generate blocks to MiniWallet address in rpc_blockchain.py 2021-11-09 12:24:48 +01:00
MarcoFalke
facc352648
test: Implicitly sync after generate*, unless opted out 2021-10-29 13:34:52 +02:00
fyquah
4330af6f72 rpc: Add test for level 3 verbosity getblock rpc call. 2021-10-05 10:42:34 +02:00
MarcoFalke
fa4ca8d579
test: Add -testactivationheight tests to rpc_blockchain 2021-09-24 15:32:00 +02:00
merge-script
8e9801bfc4
Merge bitcoin/bitcoin#22818: test: Activate all regtest softforks at height 1, unless overridden
fa4db8671b test: Activate all regtest softforks at height 1, unless overridden (MarcoFalke)
faad1e5ffd Introduce -testactivationheight=name@height setting (MarcoFalke)
fadb2ef2fa test: Add extra_args argument to TestChain100Setup constructor (MarcoFalke)
faa46986aa test: Remove version argument from build_next_block in p2p_segwit test (MarcoFalke)
fa086ef539 test: Remove unused ~TestChain100Setup (MarcoFalke)

Pull request description:

  All softforks that are active at the tip of mainnet, should also be active from genesis in regtest. Otherwise their rules might not be enforced in user testing, thus making their testing less useful.

  To still allow tests to check pre-softfork rules, a runtime argument can change the activation height.

ACKs for top commit:
  laanwj:
    Code review ACK fa4db8671b
  theStack:
    re-ACK fa4db8671b

Tree-SHA512: 6397d46ff56ebc48c007a4cda633904d6ac085bc76b4ecf83097c546c7eec93ac0c44b88083b2611b9091c8d1fb8ee1e314065de078ef15e922c015de7ade8bf
2021-09-24 14:04:51 +02:00
MarcoFalke
fa7e3f1fc1
test: Replace MiniWallet scan_blocks with rescan_utxos 2021-09-20 08:31:04 +02:00
MarcoFalke
fa4db8671b
test: Activate all regtest softforks at height 1, unless overridden 2021-09-16 18:53:04 +02:00
MarcoFalke
fa0b916971
scripted-diff: Use generate* from TestFramework
-BEGIN VERIFY SCRIPT-
 sed --regexp-extended -i \
     's/((self\.)?(nodes\[[^]]+\]|[a-z_]*(wallet|node)[0-9a-z_]*))\.(generate(|toaddress|block|todescriptor)(\(|, ))/self.\5\1, /g' \
     $(git grep -l generate ./test | grep -v 'test_framework/' | grep -v 'feature_rbf')
-END VERIFY SCRIPT-
2021-09-02 10:34:35 +02:00
MarcoFalke
faf7e485e9
Set regtest.BIP65Height = 111 to speed up tests 2021-08-26 11:08:24 +02:00
MarcoFalke
fafe896a0b
test: Set regtest.BIP66Height = 102 to speed up tests 2021-08-05 12:08:33 +02:00
MarcoFalke
ad0fc453cc
Merge bitcoin/bitcoin#16333: test: Set BIP34Height = 2 for regtest
222290f543 test: Set BIP34Height = 2 for regtest (MarcoFalke)
fac90c55be test: Create all blocks with version 4 or higher (MarcoFalke)

Pull request description:

  BIP34 is active on the current tip of mainnet, so all miners must obey it. It would be nice if it also was active in fresh regtest instances from the earliest time possible.

  I changed the BIP34 height to `2`, so that the block at height=1 may be used to mine a duplicate coinbase. (Needed to test mainnet behaviour)

  This pull is done in two commits:

  *  test: Create all blocks with version 4 or higher:
     Now that BIP34 is activated earlier, we need to create blocks with a higher version number. Just bump it to 4 instead of 2 to avoid having to bump it again later.

  *  test: Set BIP34Height = 2 for regtest:
     This fixes the BIP34 implementation in the tests (to match the one of the Core codebase) and updates the tests where needed

ACKs for top commit:
  ajtowns:
    ACK 222290f543
  jonatack:
    ACK 222290f543 tested and reviewed rebased to current master 5e213822f8
  theStack:
    Tested ACK 222290f543

Tree-SHA512: d69c637a62a64b8e87de8c7f0b305823d8f4d115c1852514b923625dbbcf9a4854b5bb3771ff41702ebf47c4c182a4442c6d7c0b9f282c95a34b83e56a73939b
2021-08-03 10:10:43 +02:00
Jon Atack
ef5e9304cd
test: update logging and docstring in rpc_blockchain.py 2021-07-22 01:43:45 +02:00
Jon Atack
d548dc71e4
test: replace magic values by constants in rpc_blockchain.py 2021-07-22 01:43:34 +02:00
Jon Atack
78c361086f
test: assert on mediantime in getblockheader and getblockchaininfo 2021-07-21 18:01:09 +02:00
Jon Atack
0a9129c588
test: assert on the value of getblockchaininfo#time 2021-07-21 17:38:19 +02:00
João Barbosa
20edf4bcf6 rpc: Return block time in getblockchaininfo 2021-07-20 10:43:26 +01:00
Sebastian Falbesoner
1914054208 scripted-diff: test: rename FromHex to from_hex
-BEGIN VERIFY SCRIPT-
sed -i 's/\<FromHex\>/from_hex/g' $(git grep -l FromHex)
-END VERIFY SCRIPT-

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
2021-06-21 14:33:59 +02:00
MarcoFalke
222290f543
test: Set BIP34Height = 2 for regtest 2021-06-18 20:58:03 +02:00