Created
September 20, 2022 16:30
-
-
Save fifthdrew/034c60adaa00350efdb5f61601db8fd2 to your computer and use it in GitHub Desktop.
Exemplos de testes funcionais para verificar que o nó 0 enviou um bloco ao nó 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from test_framework.test_framework import BitcoinTestFramework | |
| from test_framework.util import assert_equal | |
| class SendBlockTest(BitcoinTestFramework): | |
| def set_test_params(self): | |
| self.setup_clean_chain = True | |
| self.num_nodes = 2 | |
| def run_test(self): | |
| self.log.info("Starting test!") | |
| self.log.info("Generating a block on node 0") | |
| self.generate(self.nodes[0], 1) | |
| self.log.info("Syncing blocks...") | |
| self.sync_all() | |
| self.log.info("Verifying that node 1 received the block") | |
| assert_equal( | |
| self.nodes[0].getbestblockhash(), | |
| self.nodes[1].getbestblockhash() | |
| ) | |
| self.log.info(f"Hash block node 0: {self.nodes[0].getbestblockhash()}") | |
| self.log.info(f"Hash block node 1: {self.nodes[1].getbestblockhash()}") | |
| if __name__ == '__main__': | |
| SendBlockTest().main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from test_framework.test_framework import BitcoinTestFramework | |
| from test_framework.util import assert_equal | |
| class SendBlockTest(BitcoinTestFramework): | |
| def set_test_params(self): | |
| self.setup_clean_chain = True | |
| self.num_nodes = 3 | |
| def setup_network(self): | |
| self.setup_nodes() | |
| self.connect_nodes(0, 1) | |
| self.sync_all(self.nodes[0:2]) | |
| def run_test(self): | |
| self.log.info("Starting test!") | |
| self.log.info("Generating a block on node 0") | |
| self.generate(self.nodes[0], sync_fun=lambda: self.sync_all(self.nodes[0:2]), nblocks=1) | |
| self.log.info("Verifying that node 1 received the block") | |
| assert_equal( | |
| self.nodes[0].getbestblockhash(), | |
| self.nodes[1].getbestblockhash() | |
| ) | |
| self.log.info("Verifying that the node 2 do not received the block") | |
| assert self.nodes[2].getbestblockhash() not in [ self.nodes[0].getbestblockhash(), self.nodes[1].getbestblockhash()] | |
| self.log.info(f"Hash block node 0: {self.nodes[0].getbestblockhash()}") | |
| self.log.info(f"Hash block node 1: {self.nodes[1].getbestblockhash()}") | |
| self.log.info(f"Hash block node 2: {self.nodes[2].getbestblockhash()}") | |
| if __name__ == '__main__': | |
| SendBlockTest().main() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Se precisar de alguma explicação de como cheguei nesse código, comente aqui por favor.