Last active
April 27, 2021 14:45
-
-
Save Danilo-Araujo-Silva/9dec9b83b3c22ab55049f9ede3f8ef6c to your computer and use it in GitHub Desktop.
Revisions
-
Danilo-Araujo-Silva revised this gist
Apr 27, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -48,4 +48,6 @@ 13- `method="generatetoaddress" && params='[10, "<wallet address returned from the previous command>"]' 14- TODO, complete documentation with other instructions from here: https://bitcoin.stackexchange.com/questions/17553/is-there-a-sandbox-in-bitcoin-for-testing/102885#102885 15- Remember that after mining the block, generate more 100 blocks so we can see the values in the balance properly. -
Danilo-Araujo-Silva revised this gist
Apr 27, 2021 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,36 +2,50 @@ pointing to different data folders (The regtest network will only work with at least 2 nodes). - `bitcoind -conf=/path/to/bitcoind-regtest-01/bitcoin.conf -datadir=/path/to/bitcoind-regtest-01/data/folder -daemon` - `bitcoind -conf=/path/to/bitcoind-regtest-02/bitcoin.conf -datadir=/path/to/bitcoind-regtest-02/data/folder -daemon` 02- Create a docker network with the 2 containers - `docker network create bitcoind-regtest-network` - `docker network connect bitcoind-regtest-network bitcoind-regtest-01` - `docker network connect bitcoind-regtest-network bitcoind-regtest-02` 03- Get the ip address of the `bitcoind-regtest-01` container in the network and change the `bitcoind-regtest-02` `bitcoin.conf` accordingly (since the `bitcoind-regtest-02` node should be connecting to `bitcoind-regtest-01`). If this step is not done the `getblocktemplate` method will not work. - `docker network inspect bitcoind-regtest-network` 04- Start the containers, observe the logs and check if there are no connection problems there 05- From the host machine (outside of the containers) export some environment variables (only used for testing purposes): - `rpc_user_pass="<rpc_user>:<rpc_password>"` - `bitcoind_regtest_1_url="http://<bitcoind-regtest-01 ip address in the bitcoind-regtest-network>:<bitcoind-regtest-01 rcp port>/"` - `bitcoind_regtest_2_url="http://<bitcoind-regtest-01 ip address in the bitcoind-regtest-network>:<bitcoind-regtest-01 rcp port>/"` - `command_1="curl --user $rpc_user_password --data-binary \"{\\\"jsonrpc\\\": \\\"1.0\\\", \\\"id\\\": \\\"curltest\\\", \\\"method\\\": \\\"\$method\\\", \\\"params\\\": \$params }\" -H \"content-type: text/plain;\" $bitcoind_regtest_1_url"` - `command_2="curl --user $rpc_user_password --data-binary \"{\\\"jsonrpc\\\": \\\"1.0\\\", \\\"id\\\": \\\"curltest\\\", \\\"method\\\": \\\"\$method\\\", \\\"params\\\": \$params }\" -H \"content-type: text/plain;\" $bitcoind_regtest_2_url"` 06- Test if it is working (a valid ouput should appear in both commands): - method="getblockchaininfo" && params="[]" && eval "$command_1" - method="getblockchaininfo" && params="[]" && eval "$command_2" 07- Check if the `bitcoind-regtest-01` node has an `connections_in` connection with the other one: - `method="getnetworkinfo" && params="[]" && eval "$command_1"` 08- Check if the `bitcoind-regtest-02` node has an `connections_out` connection with the other one: - `method="getnetworkinfo" && params="[]" && eval "$command_2"` 09- Probably no wallet is loaded yet, so let's check it - `method="getwalletinfo" && params="[]" && eval "$command_1"` - The output should be something like: - `{"result":null,"error":{"code":-18,"message":"No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)"},"id":"curltest"}` 10- Create a wallet if there's no one available (https://bitcoincore.org/en/doc/0.21.0/rpc/wallet/createwallet/): - `method=createwallet && params='["/path/inside/the/container/or/shared/volume/where/you/want/to/store/the/wallet/regtest-01", false, false, "<wallet password here>", false, false, false]' && eval "$command_1"` 11- Use the `getwalletinfo` method again, if the wallet is not loaded, load it with - `method="loadwallet" && params='["/path/inside/the/container/or/shared/volume/where/you/want/to/store/the/wallet/regtest-01"]' && eval "$command_1"` - Check if the wallet is loaded properly with the `getwalletinfo` method. 12- `method="getnewaddress" && params="[]" && eval "$command_1"` 13- `method="generatetoaddress" && params='[10, "<wallet address returned from the previous command>"]' 14- -
Danilo-Araujo-Silva revised this gist
Apr 27, 2021 . 2 changed files with 37 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ 01- Create two different docker containers (there are bitcoin.conf examples below) `bitcoind-regtest-01` and `bitcoind-regtest-02` pointing to different data folders (The regtest network will only work with at least 2 nodes). - `bitcoind -conf=/path/to/bitcoind-regtest-01/bitcoin.conf -datadir=/path/to/bitcoind-regtest-01/data/folder -daemon` - `bitcoind -conf=/path/to/bitcoind-regtest-02/bitcoin.conf -datadir=/path/to/bitcoind-regtest-02/data/folder -daemon` 02- Create a docker network with the 2 containers - `docker network create bitcoind-regtest-network` - `docker network connect bitcoind-regtest-network bitcoind-regtest-01` - `docker network connect bitcoind-regtest-network bitcoind-regtest-02` 03- Get the ip address of the `bitcoind-regtest-01` container in the network and change the `bitcoind-regtest-02` `bitcoin.conf` accordingly (since the `bitcoind-regtest-02` node should be connecting to `bitcoind-regtest-01`). If this step is not done the `getblocktemplate` method will not work. - `docker network inspect bitcoind-regtest-network` 04- Start the containers, observe the logs and check if there are no connection problems there 05- From the host machine (outside of the containers) export some environment variables (only used for testing purposes): - `rpc_user_pass="<rpc_user>:<rpc_password>"` - `bitcoind_regtest_1_url="http://<bitcoind-regtest-01 ip address in the bitcoind-regtest-network>:<bitcoind-regtest-01 rcp port>/"` - `bitcoind_regtest_2_url="http://<bitcoind-regtest-01 ip address in the bitcoind-regtest-network>:<bitcoind-regtest-01 rcp port>/"` - `command_1="curl --user $rpc_user_password --data-binary \"{\\\"jsonrpc\\\": \\\"1.0\\\", \\\"id\\\": \\\"curltest\\\", \\\"method\\\": \\\"\$method\\\", \\\"params\\\": \$params }\" -H \"content-type: text/plain;\" $bitcoind_regtest_1_url"` - `command_2="curl --user $rpc_user_password --data-binary \"{\\\"jsonrpc\\\": \\\"1.0\\\", \\\"id\\\": \\\"curltest\\\", \\\"method\\\": \\\"\$method\\\", \\\"params\\\": \$params }\" -H \"content-type: text/plain;\" $bitcoind_regtest_2_url"` 06- Test if it is working (a valid ouput should appear in both commands): - method="getblockchaininfo" && params="[]" && eval "$command_1" - method="getblockchaininfo" && params="[]" && eval "$command_2" 07- Check if the `bitcoind-regtest-01` node has an `connections_in` connection with the other one: - `method="getnetworkinfo" && params="[]" && eval "$command_1"` 08- Check if the `bitcoind-regtest-02` node has an `connections_out` connection with the other one: - `method="getnetworkinfo" && params="[]" && eval "$command_2"` 09- Probably no wallet is loaded yet, so let's check it - `method="getwalletinfo" && params="[]" && eval "$command_1"` - The output should be something like: - `{"result":null,"error":{"code":-18,"message":"No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)"},"id":"curltest"}` 10- Create a wallet if there's no one available (https://bitcoincore.org/en/doc/0.21.0/rpc/wallet/createwallet/): - `method=createwallet && params='["/path/inside/the/container/or/shared/volume/where/you/want/to/store/the/wallet/regtest-01", false, false, "<wallet password here>", false, false, false]' && eval "$command_1"` 11- Use the `getwalletinfo` method again, if the wallet is not loaded, load it with - `method="loadwallet" && params='["/path/inside/the/container/or/shared/volume/where/you/want/to/store/the/wallet/regtest-01"]' && eval "$command_1"` - Check if the wallet is loaded properly with the `getwalletinfo` method. 12- `method="getnewaddress" && params="[]" && eval "$command_1"` 13- `method="generatetoaddress" && params='[10, "<wallet address returned from the previous command>"]' 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ -
Danilo-Araujo-Silva created this gist
Apr 27, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ regtest=1 [regtest] debug=1 server=1 rpcallowip=0.0.0.0/0 rpcbind=127.0.0.1 rpcbind=bitcoind-regtest-01 rpcauth=<rpcuser>:<rpc auth line created by https://github.com/bitcoin/bitcoin/tree/c7ad94428ab6f54661d7a5441e1fdd0ebf034903/share/rpcauth> # Used for inspecting transactions txindex=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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ regtest=1 [regtest] debug=1 server=1 rpcallowip=0.0.0.0/0 rpcbind=127.0.0.1 rpcbind=bitcoind-regtest-02 rpcauth=<rpc auth line created using https://github.com/bitcoin/bitcoin/tree/c7ad94428ab6f54661d7a5441e1fdd0ebf034903/share/rpcauth> # Using different ports from the previous container # The default ones are: 18443 (rpcport), 18444 (port) rpcport=18445 port=18446 connect=<first container ip, fetched from the docker network>:18444 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 1- Create two different docker containers (there are bitcoin.conf examples below) `bitcoind-regtest-01` and `bitcoind-regtest-02` pointing to different data folders (The regtest network will only work with at least 2 nodes). - `bitcoind -conf=/path/to/bitcoind-regtest-01/bitcoin.conf -datadir=/path/to/bitcoind-regtest-01/data/folder -daemon` - `bitcoind -conf=/path/to/bitcoind-regtest-02/bitcoin.conf -datadir=/path/to/bitcoind-regtest-02/data/folder -daemon` 2- Create a docker network with the 2 containers - `docker network create bitcoind-regtest-network` - `docker network connect bitcoind-regtest-network bitcoind-regtest-01` - `docker network connect bitcoind-regtest-network bitcoind-regtest-02` 3- Get the ip address of the `bitcoind-regtest-01` container in the network and change the `bitcoind-regtest-02` `bitcoin.conf` accordingly (since the `bitcoind-regtest-02` node should be connecting to `bitcoind-regtest-01`). If this step is not done the `getblocktemplate` method will not work. - `docker network inspect bitcoind-regtest-network` 4- Start the containers, observe the logs and check if there are no connection problems there 5- From the host machine export the RPC user and password for testing purposes: `export RPC_USER_PASS="<rpc user>:<rpc password>"` 6- Check if it is working: 7- TODO Complete the documentation