dtr-org / unit-e

A digital currency for a new era of decentralized trust
https://unit-e.io
MIT License
45 stars 15 forks source link

Factor out generate_block function #1037

Closed frolosofsky closed 5 years ago

frolosofsky commented 5 years ago

At the moment, the way we generate blocks in functional tests is quite meditative and repeatable. This commit factors out simple function generate_block that eliminates the need to copy-paste every time we generate new blocks in tests.

Conceptually, the change is:

-node.generatetoaddress(10, node.getnewaddress('', 'bech32'))
+generate_block(node, count=10)

count=1 is omitted.

The script which makes dirty job:

for f in $(git grep -l generatetoaddress '*finalization*.py' '*esperanza*.py' '*snapshot*.py' '*commits*.py' '*finalizer*.py' '*forkchoice*.py' '*fork_choice*.py'); do
    echo $f
    LANG=C LC_CTYPE=C sed -e 's/\([][a-z0-9_.]*\)\.generatetoaddress(1, \1\.getnewaddress(.*, .*))/generate_block(\1)/' -i '' $f
    LANG=C LC_CTYPE=C sed -e 's/\([][a-z0-9_.]*\)\.generatetoaddress(\([^,]*\), \1\.getnewaddress(.*, .*))/generate_block(\1, count=\2)/' -i '' $f
done

Also, applies alphabetical sort in affected files import sections.

frolosofsky commented 5 years ago

I won't merge this until we finish 0.17 transition. Just wanna collect opinions.

scravy commented 5 years ago

Sweet! @Gnappuraz and I were discussing precisely something like that for quite a while :-)

Big Concept ACK

AM5800 commented 5 years ago

I knew this will happen sooner or later. The only intrigue was - who would do it. I, of course, welcome this change Concept ACK

castarco commented 5 years ago

ConceptACK, just waiting until we merge 0.17 to review again.