├── .github ├── ISSUE_TEMPLATE │ ├── BUG_REPORT.md │ └── config.yml ├── developer-certificate-of-origin ├── pull_request_template.md └── workflows │ └── test-docker-hub-image.yml ├── .gitignore ├── BUILD.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── casper-nctl.Dockerfile ├── clean-build-artifacts.sh ├── cors ├── cors-anywhere.Dockerfile └── server.js ├── docker-compose.yml ├── hooks └── post_push ├── nctl-activate.ps1 ├── nctl-activate.sh ├── net-1-predefined-accounts.tar.gz ├── restart.sh └── test ├── conftest.py └── test_nctl.py /.github/ISSUE_TEMPLATE/BUG_REPORT.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "🐞 Bug report" 3 | about: Report an issue with the Casper NCTL - Docker Container 4 | title: '' 5 | labels: 'bug' 6 | assignees: 'davidatwhiletrue' 7 | 8 | --- 9 | 10 | **What happened?** 11 | 12 | **What did you expect to happen?** 13 | 14 | **Are you willing to submit a pull request to fix this bug?** 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: ❓ Ask a question or discuss an idea 4 | url: https://discord.gg/caspernetwork 5 | about: Ask your questions and discuss your ideas in the `#smart-contracts` channel 6 | -------------------------------------------------------------------------------- /.github/developer-certificate-of-origin: -------------------------------------------------------------------------------- 1 | Developer Certificate of Origin 2 | Version 1.1 3 | 4 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 5 | 660 York Street, Suite 102, 6 | San Francisco, CA 94110 USA 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | Developer's Certificate of Origin 1.1 12 | 13 | By making a contribution to this project, I certify that: 14 | 15 | (a) The contribution was created in whole or in part by me and I 16 | have the right to submit it under the open source license 17 | indicated in the file; or 18 | 19 | (b) The contribution is based upon previous work that, to the best 20 | of my knowledge, is covered under an appropriate open source 21 | license and I have the right under that license to submit that 22 | work with modifications, whether created in whole or in part 23 | by me, under the same open source license (unless I am 24 | permitted to submit under a different license), as indicated 25 | in the file; or 26 | 27 | (c) The contribution was provided directly to me by some other 28 | person who certified (a), (b) or (c) and I have not modified 29 | it. 30 | 31 | (d) I understand and agree that this project and the contribution 32 | are public and that a record of the contribution (including all 33 | personal information I submit with it, including my sign-off) is 34 | maintained indefinitely and may be redistributed consistent with 35 | this project or the open source license(s) involved. 36 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | * Resolves: # 3 | 4 | ### Summary 5 | 6 | 7 | ### TODO 8 | 9 | - [ ] ... 10 | 11 | ### Checklist 12 | 13 | - [ ] Code is properly formatted 14 | - [ ] All commits are signed 15 | - [ ] Tests included/updated or not needed 16 | - [ ] Documentation has been updated or is not required 17 | 18 | -------------------------------------------------------------------------------- /.github/workflows/test-docker-hub-image.yml: -------------------------------------------------------------------------------- 1 | name: test_docker_hub_image 2 | 3 | on: 4 | # Allows you to run this workflow manually from the Actions tab 5 | workflow_dispatch: 6 | inputs: 7 | imageToTest: 8 | description: 'Image to test' 9 | required: true 10 | default: 'makesoftware/casper-nctl:latest' 11 | 12 | jobs: 13 | test_docker_hub_image: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up Python 3.10 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: "3.10" 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | pip install flake8 pytest testinfra 27 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 28 | - name: Lint with flake8 29 | run: | 30 | # stop the build if there are Python syntax errors or undefined names 31 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 32 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 33 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 34 | - name: Test with pytest 35 | run: | 36 | pytest -p no:cacheprovider --image ${{ github.event.inputs.imageToTest }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # python env and test outputs 2 | env/* 3 | test/__pycache__/* -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # Casper NCTL - Docker Container 2 | 3 | ## Build the Docker image locally 4 | 5 | To build the NCTL docker image run `docker build` as follows: 6 | 7 | ```bash 8 | docker build -f casper-nctl.Dockerfile --build-arg NODE_GITBRANCH=release-1.5.4 --build-arg CLIENT_GITBRANCH=release-2.0.0 -t casper-nctl:v154 . 9 | ``` 10 | 11 | The argument `NODE_GITBRANCH` indicates which branch from the `casper-node` repository docker 12 | will download and build. 13 | 14 | The argument `CLIENT_GITBRANCH` indicates which branch from the `casper-client-rs` repository docker 15 | will download and build. 16 | 17 | In the command above, the image is tagged as v154, which is the latest `casper-node` version 18 | at the moment of writing these instructions. To keep other scripts independent of the version, 19 | tag the image also as `latest` once the first build completes. 20 | 21 | ```bash 22 | docker tag casper-nctl:v154 casper-nctl:latest 23 | ``` 24 | 25 | ## Test the docker image 26 | 27 | You can test the new image with `pytest`. First, install it with `pip`: 28 | 29 | ```bash 30 | python -m pip install --upgrade pip 31 | pip install pytest testinfra 32 | ``` 33 | 34 | Then, run `pytest` indicating the name of the docker image to test: 35 | 36 | ``` 37 | pytest --image casper-nctl:v154 38 | ``` 39 | 40 | ## Configure Docker Hub Automated Builds 41 | 42 | Docker Hub can automatically build and push a new image when a specific event happens in 43 | the source code repository (e.g. a new commit in a branch or a new tag). 44 | 45 | As an example, to build automatically an image when there is a new version tag applied to 46 | the source code repository, 47 | configure a Build Rule in Docker Hub as follows: 48 | 49 | | Field | Value | 50 | |---------------------|:--------------------------------| 51 | | Source Type | Tag | 52 | | Source | `/v([0-9.]+)$/` | 53 | | Docker Tag | `v{\1}` | 54 | | Dockerfile location | `./casper-nctl.Dockerfile` | 55 | | Build context | `/` | 56 | 57 | More information: [Set up Automated Builds](https://docs.docker.com/docker-hub/builds/) -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | community@make.services. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Casper NCTL - Docker Container 2 | 3 | The following is a set of rules and guidelines for contributing to this repo. Please feel free to propose changes to this document in a pull request. 4 | 5 | ## Submitting issues 6 | 7 | If you have questions about how to use Casper NCTL - Docker Container, please direct these to the related discord channels: 8 | * [#smart-contracts](https://discord.gg/caspernetwork) 9 | * [#sdk-development](https://discord.gg/caspernetwork) 10 | 11 | ### Guidelines 12 | * Please search the existing issues first, it's likely that your issue was already reported or even fixed. 13 | - Go to the main page of the repository, click "issues" and type any word in the top search/command bar. 14 | - You can also filter by appending e. g. "state:open" to the search string. 15 | - More info on [search syntax within GitHub](https://help.github.com/articles/searching-issues) 16 | 17 | ## Contributing to Casper NCTL - Docker Container 18 | 19 | All contributions to this repository are considered to be licensed under Apache License 2.0. 20 | 21 | Workflow for bug fixes: 22 | * Check open issues and unmerged pull requests to make sure the topic is not already covered elsewhere 23 | * Fork the repository 24 | * Do your changes on your fork 25 | * Make sure to add or update relevant test cases 26 | * Create a pull request, with a suitable title and description, referring to the related issue 27 | 28 | ### Sign your work 29 | 30 | We use the Developer Certificate of Origin (DCO) as an additional safeguard 31 | for the Casper NCTL - Docker Container project. This is a well established and widely used 32 | mechanism to assure contributors have confirmed their right to license 33 | their contribution under the project's license. 34 | Please read [developer-certificate-of-origin](.github/developer-certificate-of-origin). 35 | If you can certify it, then just add a line to every git commit message: 36 | 37 | ```` 38 | Signed-off-by: Random J Developer 39 | ```` 40 | 41 | Use your real name (sorry, no pseudonyms or anonymous contributions). 42 | If you set your `user.name` and `user.email` git configs, you can sign your 43 | commit automatically with `git commit -s`. You can also use git [aliases](https://git-scm.com/book/tr/v2/Git-Basics-Git-Aliases) 44 | like `git config --global alias.ci 'commit -s'`. Now you can commit with 45 | `git ci` and the commit will be signed. 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Casper NCTL - Docker Container 2 | 3 | > **Warning** 4 | > Images published on Docker Hub are not stable on Apple computers with M1/M2 chips. We recommend that you build the docker image locally using the [BUILD](./BUILD.md) instructions. 5 | 6 | [NCTL](https://github.com/casper-network/casper-node/tree/release-1.4.3/utils/nctl) is a CLI application to control one or multiple Casper networks locally. Many developers wish to spin up relatively small test networks to localize their testing before deploying to the blockchain. 7 | 8 | ## How to use this image 9 | 10 | ### Start a network with five nodes 11 | 12 | To create a container with the NCTL image write: 13 | 14 | ```bash 15 | docker run --rm -it --name mynctl -d -p 11101:11101 -p 14101:14101 -p 18101:18101 makesoftware/casper-nctl 16 | ``` 17 | 18 | where `mynctl` is the name of the container. The ports for the first node in the network are published to the host. 19 | 20 | Alternatively, you can use `docker-compose` to start and stop the container. Download the file [`docker-compose.yml`](https://raw.githubusercontent.com/make-software/casper-nctl-docker/master/docker-compose.yml) 21 | in this repository and write: 22 | 23 | ```bash 24 | docker-compose up 25 | ``` 26 | 27 | ### Activate `nctl-*` commands 28 | 29 | To activate `nctl-*` commands in your local host, run the following command in a bash console: 30 | 31 | ```bash 32 | source nctl-activate.sh mynctl 33 | ``` 34 | 35 | In a Powershell terminal, run: 36 | 37 | ```bash 38 | . .\nctl-activate.ps1 mynctl 39 | ``` 40 | 41 | where `mynctl` is the name of the container. 42 | 43 | Now you can write in the host machine commands like `nctl-view-faucet-account`, `nctl-transfer-native`, etc. For a complete list of commands, visit [this page](https://github.com/casper-network/casper-node/blob/release-1.4.3/utils/nctl/docs/commands.md). 44 | 45 | Sometimes you may need the secret key of the faucet, a node or one of the predefined users. After activating `nctl-*` commands you can execute the following commands: 46 | 47 | ```bash 48 | nctl-view-faucet-secret-key 49 | ``` 50 | 51 | ```bash 52 | nctl-view-node-secret-key node=1 53 | ``` 54 | 55 | ```bash 56 | nctl-view-user-secret-key user=3 57 | ``` 58 | 59 | ### Run the container with predefined account keys 60 | 61 | Each time the container is started, nctl runs with a set of randomly generated account keys. To use a set of predefined and pregenerated account keys, run the container with the environment variable `PREDEFINED_ACCOUNTS` set to `true`: 62 | 63 | ```bash 64 | docker run --rm -it --name mynctl -d -p 11101:11101 --env PREDEFINED_ACCOUNTS=true makesoftware/casper-nctl 65 | ``` 66 | 67 | If you're using the `docker-compose` command, add the environment variable to the `nctl` service. 68 | 69 | ### Change the settings using environment variables 70 | 71 | Using environment variables you can tweak few parameters to change the frequency of blocks and the deploys processing speed. 72 | 73 | | Environment variable | Default value | Description | 74 | |------------------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 75 | | MINIMUM_ROUND_EXPONENT | 12 | Integer between 0 and 255 (0 included). The power of two that is the number of milliseconds in the minimum round length, and therefore the minimum delay between a block and its child. E.g. 12 means 2^12 milliseconds, i.e. about 4 seconds. | 76 | | MAXIMUM_ROUND_EXPONENT | 19 | Integer between 0 and 255 (255 included). Must be greater than `minimum_round_exponent`. The power of two that is the number of milliseconds in the maximum round length, and therefore the maximum delay between a block and its child. E.g. 19 means 2^19 milliseconds, i.e. about 8.7 minutes. | 77 | | DEPLOY_DELAY | 1min | Deploys are only proposed in a new block if they have been received at least this long ago. | 78 | 79 | :warning: **Change these values carefully**. Too low or too high minimum/maximum round exponent values will make the nodes malfunction. 80 | 81 | You can also use your custom chainspec.toml and config.toml files: 82 | 83 | | Environment variable | Description | 84 | |----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| 85 | | PATH_TO_CHAINSPEC | Absolute path to your custom `chainspec.toml` file. Usually you'll need to mount a volume connected to your host to make the file available in the container. | 86 | | PATH_TO_CONFIG_TOML | Absolute path to your custom `config.toml` configuration file for the nodes. | 87 | 88 | Usually you'll need to mount a volume connected to your host to make the file available in the container. 89 | 90 | ### Stop the container 91 | 92 | To stop the container write: 93 | 94 | ```bash 95 | docker stop mynctl 96 | ``` 97 | 98 | Or, if you're using `docker-compose` write: 99 | 100 | ```bash 101 | docker-compose stop 102 | ``` 103 | 104 | ### Container shell access 105 | 106 | The docker exec command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your nctl container: 107 | 108 | ```bash 109 | docker exec -it mynctl bash 110 | ``` 111 | 112 | In the container shell you can use the `casper-client` tool as well as the `nctl-*` set of commands. 113 | 114 | ## Use `cors-anywhere` to interact with the nodes from a browser 115 | 116 | Browsers block direct RPC calls to Casper nodes due to CORS. If you're developing a web app you may use `cors-anywhere` to overcome this situation. 117 | 118 | The `cors` folder in this repository contains a Docker Compose configuration to start a node.js server running `cors-anywhere` in addition to the NCTL container. To start both containers run the following command: 119 | 120 | ```bash 121 | docker-compose --profile cors-anywhere up 122 | ``` 123 | 124 | Next, change your web app configuration to send the RPC calls to the node.js server indicating the casper node it has to redirect the traffic to: 125 | 126 | ``` 127 | http://127.0.0.1:11100/http://mynctl:11101/rpc 128 | ``` 129 | 130 | ## Use the Docker image in a GitHub action 131 | 132 | An example of a GitHub Action running NCTL as a service container to execute integration tests. 133 | 134 | ```yaml 135 | name: CI 136 | 137 | on: 138 | # Allows you to run this workflow manually from the Actions tab 139 | workflow_dispatch: 140 | 141 | jobs: 142 | integration-test: 143 | # The type of runner that the job will run on 144 | runs-on: ubuntu-latest 145 | 146 | # Service containers to run with `runner-job` 147 | services: 148 | # Label used to access the service container 149 | casper-nctl: 150 | # Docker Hub image 151 | image: makesoftware/casper-nctl:latest 152 | options: --name casper-nctl 153 | env: 154 | PREDEFINED_ACCOUNTS: 'true' 155 | MINIMUM_ROUND_EXPONENT: '12' 156 | MAXIMUM_ROUND_EXPONENT: '14' 157 | DEPLOY_DELAY: '12sec' 158 | ports: 159 | # Opens RPC, REST and events ports on the host and service container 160 | - 11101:11101 161 | - 14101:14101 162 | - 18101:18101 163 | 164 | steps: 165 | - uses: actions/checkout@v2 166 | - name: Setup .NET 167 | uses: actions/setup-dotnet@v1 168 | with: 169 | dotnet-version: 5.0.x 170 | - name: Obtain faucet secret key from container 171 | run: docker exec -t casper-nctl cat /home/casper/casper-node/utils/nctl/assets/net-1/faucet/secret_key.pem > Casper.Network.SDK.Test/TestData/faucetact.pem 172 | - name: Restore dependencies 173 | run: dotnet restore 174 | - name: Build 175 | run: dotnet build --no-restore 176 | - name: Test 177 | run: dotnet test --no-build --verbosity normal --settings Casper.Network.SDK.Test/test.runsettings --filter="TestCategory=NCTL" 178 | ``` 179 | 180 | ## Build the Docker image from sources 181 | 182 | To build the NCTL Docker image from the `casper-node` sources, follow the instructions in [BUILD](./BUILD.md) page. -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | If you find a security vulnerability in Casper NCTL - Docker Container, please send an email to *security@make.software*. 6 | -------------------------------------------------------------------------------- /casper-nctl.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:focal 2 | 3 | ARG NODE_GITBRANCH=release-1.5.5 4 | ARG CLIENT_GITBRANCH=release-2.0.0 5 | 6 | # DEBIAN_FRONTEND required for tzdata dependency install 7 | RUN apt-get update \ 8 | && DEBIAN_FRONTEND="noninteractive" \ 9 | apt-get install -y sudo tzdata curl gnupg gcc git ca-certificates \ 10 | protobuf-compiler libprotobuf-dev supervisor \ 11 | pkg-config libssl-dev make build-essential gettext-base lsof \ 12 | && rm -rf /var/lib/apt/lists/* 13 | 14 | SHELL ["/bin/bash", "-c"] 15 | 16 | # install cmake 17 | RUN curl -Ls https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.tar.gz | sudo tar -C /usr/local --strip-components=1 -xz 18 | 19 | # install rust nigthly and rustup 20 | RUN curl -f -L https://static.rust-lang.org/rustup.sh -O \ 21 | && sh rustup.sh -y 22 | ENV PATH="$PATH:/root/.cargo/bin" 23 | 24 | # set few environment variables needed for the nctl build scripts 25 | ENV NCTL="/root/casper-node/utils/nctl" 26 | ENV NCTL_CASPER_HOME="/root/casper-node" 27 | ENV NCTL_COMPILE_TARGET="release" 28 | 29 | # clone the casper-node repos and build binaries 30 | RUN git clone https://github.com/casper-network/casper-node-launcher.git ~/casper-node-launcher \ 31 | && cd ~/casper-node-launcher && cargo build --release 32 | RUN git clone -b $CLIENT_GITBRANCH https://github.com/casper-ecosystem/casper-client-rs ~/casper-client-rs \ 33 | && cd ~/casper-client-rs && cargo build --release 34 | RUN git clone -b $NODE_GITBRANCH https://github.com/casper-network/casper-node.git ~/casper-node \ 35 | && source ~/casper-node/utils/nctl/sh/assets/compile.sh 36 | 37 | # run clean-build-artifacts.sh to remove intermediate files and keep the image lighter 38 | COPY ./clean-build-artifacts.sh . 39 | RUN chmod +x clean-build-artifacts.sh 40 | RUN ./clean-build-artifacts.sh 41 | 42 | ## Second stage. Leave behind build tools and: 43 | ## (1) reinstall needed dependencies to run NCTL nodes. 44 | ## (2) copy binaries built in first stage. 45 | ## (3) add scripts and predefined accounts. 46 | ## 47 | FROM ubuntu:focal 48 | 49 | RUN apt-get update \ 50 | && apt-get install -y sudo curl git ca-certificates jq supervisor lsof python3-pip \ 51 | && rm -rf /var/lib/apt/lists/* 52 | 53 | RUN useradd -ms /bin/bash casper && echo "casper:casper" | chpasswd && adduser casper sudo 54 | RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers 55 | 56 | USER casper 57 | 58 | SHELL ["/bin/bash", "-c"] 59 | 60 | WORKDIR /home/casper 61 | 62 | RUN python3 -m pip install toml 63 | 64 | COPY --from=0 --chown=casper:casper /root/casper-node-launcher ./casper-node-launcher 65 | COPY --from=0 --chown=casper:casper /root/casper-client-rs ./casper-client-rs 66 | COPY --from=0 --chown=casper:casper /root/casper-node ./casper-node 67 | 68 | ENV NCTL="/home/casper/casper-node/utils/nctl" 69 | ENV NCTL_CASPER_HOME="/home/casper/casper-node" 70 | ENV NCTL_CASPER_NODE_LAUNCHER_HOME="/home/casper/casper-node-launcher" 71 | ENV NCTL_CASPER_CLIENT_HOME="/home/casper/casper-client-rs" 72 | RUN echo "source casper-node/utils/nctl/activate" >> .bashrc 73 | RUN echo "alias casper-client=/home/casper/casper-client-rs/target/release/casper-client" >> .bashrc 74 | 75 | COPY --chown=casper:casper ./restart.sh . 76 | COPY --chown=casper:casper ./net-1-predefined-accounts.tar.gz . 77 | 78 | EXPOSE 11101-11105 14101-14105 18101-18105 79 | 80 | HEALTHCHECK CMD casper-client get-block --node-address http://localhost:11101/rpc | jq 'has("result")' 81 | 82 | CMD ["/bin/bash", "-c", "source /home/casper/restart.sh"] 83 | -------------------------------------------------------------------------------- /clean-build-artifacts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /root 3 | rm casper-node/target/release/*.rlib 4 | rm -r casper-node/target/release/build 5 | rm -r casper-node/target/release/deps 6 | rm -r casper-node/target/release/.fingerprint 7 | rm -r casper-node/target/wasm32-unknown-unknown/release/build 8 | rm -r casper-node/target/wasm32-unknown-unknown/release/deps 9 | rm -r casper-node/target/wasm32-unknown-unknown/release/.fingerprint 10 | rm -r casper-node-launcher/target/release/build 11 | rm -r casper-node-launcher/target/release/deps 12 | rm -r casper-node-launcher/target/release/.fingerprint 13 | rm -r casper-client-rs/target/release/build 14 | rm -r casper-client-rs/target/release/deps 15 | rm -r casper-client-rs/target/release/.fingerprint -------------------------------------------------------------------------------- /cors/cors-anywhere.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14-alpine 2 | 3 | ENV NODE_ENV=production 4 | ENV NODE_PATH=/usr/local/lib/node_modules 5 | ARG version=latest 6 | RUN npm install -g cors-anywhere@$version 7 | COPY server.js . 8 | CMD ["node", "server.js"] 9 | 10 | EXPOSE 11100 -------------------------------------------------------------------------------- /cors/server.js: -------------------------------------------------------------------------------- 1 | // Listen on a specific host via the HOST environment variable 2 | var host = process.env.HOST || '0.0.0.0'; 3 | // Listen on a specific port via the PORT environment variable 4 | var port = process.env.PORT || 11100; 5 | 6 | var cors_proxy = require('cors-anywhere'); 7 | cors_proxy.createServer({ 8 | originWhitelist: [], // Allow all origins 9 | requireHeader: ['origin', 'x-requested-with'], 10 | removeHeaders: ['cookie', 'cookie2'] 11 | }).listen(port, host, function() { 12 | console.log('Running CORS Anywhere on ' + host + ':' + port); 13 | }); -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | mynctl: 5 | image: makesoftware/casper-nctl:latest 6 | container_name: mynctl 7 | ports: 8 | - 11101-11105:11101-11105 9 | - 14101-14105:14101-14105 10 | - 18101-18105:18101-18105 11 | environment: 12 | PREDEFINED_ACCOUNTS: 'true' 13 | #PATH_TO_CONFIG_TOML: '/home/casper/config/config.toml' 14 | #PATH_TO_CHAINSPEC: '/home/casper/config/chainspec.toml' 15 | #MINIMUM_ROUND_EXPONENT: '12' 16 | #MAXIMUM_ROUND_EXPONENT: '14' 17 | DEPLOY_DELAY: '5sec' 18 | 19 | cors-anywhere: 20 | container_name: cors-anywhere 21 | profiles: ["cors-anywhere"] 22 | build: 23 | context: ./cors 24 | dockerfile: cors-anywhere.Dockerfile 25 | tty: true 26 | environment: 27 | PORT: 11100 28 | ports: 29 | - 11100:11100 30 | -------------------------------------------------------------------------------- /hooks/post_push: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #tag new image as latest 4 | docker tag $IMAGE_NAME $DOCKER_REPO:latest 5 | docker push $DOCKER_REPO:latest 6 | -------------------------------------------------------------------------------- /nctl-activate.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [parameter(Mandatory=$false)] 3 | [String]$container 4 | ) 5 | 6 | $NCTL_DOCKER_CONTAINER="mynctl" 7 | $NCTL_HOME="/home/casper/casper-node/utils/nctl" 8 | 9 | if($PSBoundParameters.ContainsKey('container')) { 10 | $NCTL_DOCKER_CONTAINER=$container 11 | } 12 | 13 | # ############################################################### 14 | # ALIASES 15 | # ############################################################### 16 | 17 | # Assets. 18 | function nctl-assets-dump($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/dump.sh $params" } 19 | function nctl-assets-ls($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/list.sh $params" } 20 | function nctl-assets-setup($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/setup.sh $params" } 21 | function nctl-assets-setup-from-stage($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/setup_from_stage.sh $params" } 22 | function nctl-assets-teardown($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/teardown.sh $params" } 23 | function nctl-assets-upgrade-from-stage($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/upgrade_from_stage.sh $params" } 24 | 25 | # Binaries. 26 | function nctl-compile($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile.sh $params" } 27 | function nctl-compile-client($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile_client.sh $params" } 28 | function nctl-compile-node($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile_node.sh $params" } 29 | function nctl-compile-node-launcher($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile_node_launcher.sh $params" } 30 | 31 | # Staging. 32 | function nctl-stage-build($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/build.sh $params" } 33 | function nctl-stage-build-from-settings($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/build_from_settings.sh $params" } 34 | function nctl-stage-init-settings($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/init_settings.sh $params" } 35 | function nctl-stage-set-remote($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/set_remote.sh $params" } 36 | function nctl-stage-set-remotes($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/set_remotes.sh $params" } 37 | function nctl-stage-teardown($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/teardown.sh $params" } 38 | 39 | # Node control. 40 | function nctl-clean($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/clean.sh $params" } 41 | function nctl-clean-logs($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/clean_logs.sh $params" } 42 | function nctl-interactive($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/interactive.sh $params" } 43 | function nctl-join($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/join.sh $params" } 44 | function nctl-leave($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/leave.sh $params" } 45 | function nctl-ports {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c 'lsof -i tcp | grep casper-no | grep LISTEN | sort' } 46 | function nctl-processes {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c 'ps -aux | grep "$NCTL"' } 47 | function nctl-restart($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/restart.sh $params" } 48 | function nctl-rotate($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/rotate_nodeset.sh $params" } 49 | function nctl-start($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/start.sh $params" } 50 | function nctl-start-after-n-blocks($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/start_after_n_blocks.sh $params" } 51 | function nctl-start-after-n-eras($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/start_after_n_eras.sh $params" } 52 | function nctl-status($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/status.sh $params" } 53 | function nctl-stop($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/stop.sh $params" } 54 | function nctl-upgrade-protocol($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/upgrade.sh $params" } 55 | function nctl-emergency-upgrade($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/emergency_upgrade.sh $params" } 56 | 57 | # Blocking commands. 58 | function nctl-await-n-blocks($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_n_blocks.sh $params" } 59 | function nctl-await-n-eras($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_n_eras.sh $params" } 60 | function nctl-await-until-block-n($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_until_block_n.sh $params" } 61 | function nctl-await-until-era-n($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_until_era_n.sh $params" } 62 | 63 | # Views #1: chain. 64 | function nctl-view-chain-account($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_account.sh $params" } 65 | function nctl-view-chain-auction-info($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_auction_info.sh $params" } 66 | function nctl-view-chain-balance($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_balance.sh $params" } 67 | function nctl-view-chain-balances($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_balances.sh $params" } 68 | function nctl-view-chain-block($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_block.sh $params" } 69 | function nctl-view-chain-block-transfers($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_block_transfers.sh $params" } 70 | function nctl-view-chain-deploy($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_deploy.sh $params" } 71 | function nctl-view-chain-era($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_era.sh $params" } 72 | function nctl-view-chain-era-info($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_era_info.sh $params" } 73 | function nctl-view-chain-height($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_height.sh $params" } 74 | function nctl-view-chain-state-root-hash($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_state_root_hash.sh $params" } 75 | function nctl-view-chain-lfb($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_lfb.sh $params" } 76 | function nctl-view-chain-spec($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_spec.sh $params" } 77 | function nctl-view-chain-spec-accounts($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_spec_accounts.sh $params" } 78 | 79 | # Views #2: node. 80 | function nctl-view-node-config($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_config.sh $params" } 81 | function nctl-view-node-error-log($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_log_stderr.sh $params" } 82 | function nctl-view-node-log($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_log_stdout.sh $params" } 83 | function nctl-view-node-peers($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_peers.sh $params" } 84 | function nctl-view-node-peer-count($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_peer_count.sh $params" } 85 | function nctl-view-node-ports($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_ports.sh $params" } 86 | function nctl-view-node-rpc-endpoint($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_rpc_endpoint.sh $params" } 87 | function nctl-view-node-rpc-schema($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_rpc_schema.sh $params" } 88 | function nctl-view-node-status($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_status.sh $params" } 89 | function nctl-view-node-storage($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_storage.sh $params" } 90 | 91 | # Views #3: node metrics. 92 | function nctl-view-node-metrics($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh $params" } 93 | function nctl-view-node-pending-deploy-count($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh metric=pending_deploy $params" } 94 | function nctl-view-node-finalised-block-count($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh metric=amount_of_blocks $params" } 95 | function nctl-view-node-finalisation-time($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh metric=finalization_time $params" } 96 | 97 | # Views #4: faucet. 98 | function nctl-view-faucet-account($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_faucet_account.sh $params" } 99 | 100 | # Views #5: user. 101 | function nctl-view-user-account($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_user_account.sh $params" } 102 | 103 | # Views #6: validator. 104 | function nctl-view-validator-account($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_validator_account.sh $params" } 105 | 106 | # Contracts #1: KV storage. 107 | function nctl-contracts-hello-world-install($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-hello-world/do_install.sh $params" } 108 | 109 | # Contracts #2: Transfers. 110 | function nctl-transfer($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_native.sh $params" } 111 | function nctl-transfer-native($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_native.sh $params" } 112 | function nctl-transfer-native-batch-dispatch($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_native_batch.sh $params" } 113 | function nctl-transfer-native-batch-prepare($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_prepare_native_batch.sh $params" } 114 | function nctl-transfer-wasm($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_wasm.sh $params" } 115 | function nctl-transfer-wasm-batch-dispatch($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_wasm_batch.sh $params" } 116 | function nctl-transfer-wasm-batch-prepare($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_prepare_wasm_batch.sh $params" } 117 | 118 | # Contracts #3: Auction. 119 | function nctl-auction-activate($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_bid_activate.sh $params" } 120 | function nctl-auction-bid($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_bid.sh $params" } 121 | function nctl-auction-withdraw($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_bid_withdraw.sh $params" } 122 | function nctl-auction-delegate($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_delegate.sh $params" } 123 | function nctl-auction-undelegate($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_delegate_withdraw.sh $params" } 124 | 125 | # Contracts #4: ERC-20. 126 | function nctl-erc20-approve($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_approve.sh $params" } 127 | function nctl-erc20-install($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_install.sh $params" } 128 | function nctl-erc20-fund-users($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_fund_users.sh $params" } 129 | function nctl-erc20-transfer($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_transfer.sh $params" } 130 | function nctl-erc20-view-allowances($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/view_allowances.sh $params" } 131 | function nctl-erc20-view-details($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/view_details.sh $params" } 132 | function nctl-erc20-view-balances($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/view_balances.sh $params" } 133 | 134 | # Contracts #5: KV storage. 135 | function nctl-kv-storage-get-key($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-kv/get_key.sh $params" } 136 | function nctl-kv-storage-install($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-kv/do_install.sh $params" } 137 | function nctl-kv-storage-set-key($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-kv/set_key.sh $params" } 138 | 139 | # Scenarios #1: Execute protocol upgrade. 140 | function nctl-exec-upgrade-scenario-1($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/scenarios-upgrades/upgrade_scenario_01.sh $params" } 141 | function nctl-exec-upgrade-scenario-2($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/scenarios-upgrades/upgrade_scenario_02.sh $params" } 142 | function nctl-exec-upgrade-scenario-3($params) {docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/scenarios-upgrades/upgrade_scenario_03.sh $params" } 143 | 144 | # Secret keys 145 | function nctl-view-faucet-secret-key() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "cat $NCTL_HOME/assets/net-1/faucet/secret_key.pem"; } 146 | function nctl-view-user-secret-key($params) { 147 | $userx=$params.replace('=', '-') 148 | docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "cat $NCTL_HOME/assets/net-1/users/$userx/secret_key.pem"; 149 | } 150 | function nctl-view-node-secret-key($params) { 151 | $nodex=$params.replace('=', '-') 152 | docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "cat $NCTL_HOME/assets/net-1/nodes/$nodex/keys/secret_key.pem"; 153 | } 154 | -------------------------------------------------------------------------------- /nctl-activate.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export NCTL_DOCKER_CONTAINER=${1:-"mynctl"} 4 | export NCTL_HOME=/home/casper/casper-node/utils/nctl 5 | 6 | # ############################################################### 7 | # ALIASES 8 | # ############################################################### 9 | 10 | # Assets. 11 | nctl-assets-dump() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/dump.sh $@"; } 12 | nctl-assets-ls() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/list.sh $@"; } 13 | nctl-assets-setup() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/setup.sh $@"; } 14 | nctl-assets-setup-from-stage() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/setup_from_stage.sh $@"; } 15 | nctl-assets-teardown() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/teardown.sh $@"; } 16 | nctl-assets-upgrade-from-stage() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/upgrade_from_stage.sh $@"; } 17 | 18 | # Binaries. 19 | nctl-compile() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile.sh $@"; } 20 | nctl-compile-client() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile_client.sh $@"; } 21 | nctl-compile-node() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile_node.sh $@"; } 22 | nctl-compile-node-launcher() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/assets/compile_node_launcher.sh $@"; } 23 | 24 | # Staging. 25 | nctl-stage-build() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/build.sh $@"; } 26 | nctl-stage-build-from-settings() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/build_from_settings.sh $@"; } 27 | nctl-stage-init-settings() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/init_settings.sh $@"; } 28 | nctl-stage-set-remote() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/set_remote.sh $@"; } 29 | nctl-stage-set-remotes() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/set_remotes.sh $@"; } 30 | nctl-stage-teardown() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/staging/teardown.sh $@"; } 31 | 32 | # Node control. 33 | nctl-clean() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/clean.sh $@"; } 34 | nctl-clean-logs() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/clean_logs.sh $@"; } 35 | nctl-interactive() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/interactive.sh $@"; } 36 | nctl-join() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/join.sh $@"; } 37 | nctl-leave() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/leave.sh $@"; } 38 | nctl-ports() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "lsof -i tcp | grep casper-no | grep LISTEN | sort"; } 39 | nctl-processes() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c 'ps -aux | grep "$NCTL"'; } 40 | nctl-restart() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/restart.sh $@"; } 41 | nctl-rotate() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/rotate_nodeset.sh $@"; } 42 | nctl-start() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/start.sh $@"; } 43 | nctl-start-after-n-blocks() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/start_after_n_blocks.sh $@"; } 44 | nctl-start-after-n-eras() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/start_after_n_eras.sh $@"; } 45 | nctl-status() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/status.sh $@"; } 46 | nctl-stop() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/stop.sh $@"; } 47 | nctl-upgrade-protocol() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/upgrade.sh $@"; } 48 | nctl-emergency-upgrade() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/node/emergency_upgrade.sh $@"; } 49 | 50 | # Blocking commands. 51 | nctl-await-n-blocks() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_n_blocks.sh $@"; } 52 | nctl-await-n-eras() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_n_eras.sh $@"; } 53 | nctl-await-until-block-n() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_until_block_n.sh $@"; } 54 | nctl-await-until-era-n() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/misc/await_until_era_n.sh $@"; } 55 | 56 | # Views #1: chain. 57 | nctl-view-chain-account() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_account.sh $@"; } 58 | nctl-view-chain-auction-info() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_auction_info.sh $@"; } 59 | nctl-view-chain-balance() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_balance.sh $@"; } 60 | nctl-view-chain-balances() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_balances.sh $@"; } 61 | nctl-view-chain-block() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_block.sh $@"; } 62 | nctl-view-chain-block-transfers() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_block_transfers.sh $@"; } 63 | nctl-view-chain-deploy() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_deploy.sh $@"; } 64 | nctl-view-chain-era() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_era.sh $@"; } 65 | nctl-view-chain-era-info() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_era_info.sh $@"; } 66 | nctl-view-chain-height() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_height.sh $@"; } 67 | nctl-view-chain-state-root-hash() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_state_root_hash.sh $@"; } 68 | nctl-view-chain-lfb() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_lfb.sh $@"; } 69 | nctl-view-chain-spec() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_spec.sh $@"; } 70 | nctl-view-chain-spec-accounts() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_chain_spec_accounts.sh $@"; } 71 | 72 | # Views #2: node. 73 | nctl-view-node-config() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_config.sh $@"; } 74 | nctl-view-node-error-log() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_log_stderr.sh $@"; } 75 | nctl-view-node-log() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_log_stdout.sh $@"; } 76 | nctl-view-node-peers() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_peers.sh $@"; } 77 | nctl-view-node-peer-count() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_peer_count.sh $@"; } 78 | nctl-view-node-ports() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_ports.sh $@"; } 79 | nctl-view-node-rpc-endpoint() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_rpc_endpoint.sh $@"; } 80 | nctl-view-node-rpc-schema() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_rpc_schema.sh $@"; } 81 | nctl-view-node-status() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_status.sh $@"; } 82 | nctl-view-node-storage() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_storage.sh $@"; } 83 | 84 | # Views #3: node metrics. 85 | nctl-view-node-metrics() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh $@"; } 86 | nctl-view-node-pending-deploy-count() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh metric=pending_deploy $@"; } 87 | nctl-view-node-finalised-block-count() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh metric=amount_of_blocks $@"; } 88 | nctl-view-node-finalisation-time() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_node_metrics.sh metric=finalization_time $@"; } 89 | 90 | # Views #4: faucet. 91 | nctl-view-faucet-account() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_faucet_account.sh $@"; } 92 | 93 | # Views #5: user. 94 | nctl-view-user-account() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_user_account.sh $@"; } 95 | 96 | # Views #6: validator. 97 | nctl-view-validator-account() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/views/view_validator_account.sh $@"; } 98 | 99 | # Contracts #1: KV storage. 100 | nctl-contracts-hello-world-install() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-hello-world/do_install.sh $@"; } 101 | 102 | # Contracts #2: Transfers. 103 | nctl-transfer() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_native.sh $@"; } 104 | nctl-transfer-native() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_native.sh $@"; } 105 | nctl-transfer-native-batch-dispatch() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_native_batch.sh $@"; } 106 | nctl-transfer-native-batch-prepare() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_prepare_native_batch.sh $@"; } 107 | nctl-transfer-wasm() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_wasm.sh $@"; } 108 | nctl-transfer-wasm-batch-dispatch() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_dispatch_wasm_batch.sh $@"; } 109 | nctl-transfer-wasm-batch-prepare() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-transfers/do_prepare_wasm_batch.sh $@"; } 110 | 111 | # Contracts #3: Auction. 112 | nctl-auction-activate() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_bid_activate.sh $@"; } 113 | nctl-auction-bid() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_bid.sh $@"; } 114 | nctl-auction-withdraw() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_bid_withdraw.sh $@"; } 115 | nctl-auction-delegate() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_delegate.sh $@"; } 116 | nctl-auction-undelegate() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-auction/do_delegate_withdraw.sh $@"; } 117 | 118 | # Contracts #4: ERC-20. 119 | nctl-erc20-approve() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_approve.sh $@"; } 120 | nctl-erc20-install() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_install.sh $@"; } 121 | nctl-erc20-fund-users() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_fund_users.sh $@"; } 122 | nctl-erc20-transfer() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/do_transfer.sh $@"; } 123 | nctl-erc20-view-allowances() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/view_allowances.sh $@"; } 124 | nctl-erc20-view-details() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/view_details.sh $@"; } 125 | nctl-erc20-view-balances() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-erc20/view_balances.sh $@"; } 126 | 127 | # Contracts #5: KV storage. 128 | nctl-kv-storage-get-key() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-kv/get_key.sh $@"; } 129 | nctl-kv-storage-install() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-kv/do_install.sh $@"; } 130 | nctl-kv-storage-set-key() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/contracts-kv/set_key.sh $@"; } 131 | 132 | # Scenarios #1: Execute protocol upgrade. 133 | nctl-exec-upgrade-scenario-1() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/scenarios-upgrades/upgrade_scenario_01.sh $@"; } 134 | nctl-exec-upgrade-scenario-2() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/scenarios-upgrades/upgrade_scenario_02.sh $@"; } 135 | nctl-exec-upgrade-scenario-3() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "source $NCTL_HOME/sh/scenarios-upgrades/upgrade_scenario_03.sh $@"; } 136 | 137 | # Secret keys 138 | nctl-view-faucet-secret-key() { docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "cat $NCTL_HOME/assets/net-1/faucet/secret_key.pem"; } 139 | nctl-view-user-secret-key() { 140 | userx=`echo $1 | sed 's/=/-/'`; 141 | docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "cat $NCTL_HOME/assets/net-1/users/$userx/secret_key.pem"; 142 | } 143 | nctl-view-node-secret-key() { 144 | nodex=`echo $1 | sed 's/=/-/'`; 145 | docker exec -t $NCTL_DOCKER_CONTAINER /bin/bash -c "cat $NCTL_HOME/assets/net-1/nodes/$nodex/keys/secret_key.pem"; 146 | } -------------------------------------------------------------------------------- /net-1-predefined-accounts.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/make-software/casper-nctl-docker/11fb53e51607a161b3704a308af61a21e9818c68/net-1-predefined-accounts.tar.gz -------------------------------------------------------------------------------- /restart.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Get path to chainspec and config files from ENV variables or use the default ones 4 | ## 5 | PATH_TO_CHAINSPEC=${PATH_TO_CHAINSPEC:-"${NCTL_CASPER_HOME}/resources/local/chainspec.toml.in"} 6 | PATH_TO_CONFIG_TOML=${PATH_TO_CONFIG_TOML:-"${NCTL_CASPER_HOME}/resources/local/config.toml"} 7 | 8 | ## Change minimun/maximum round exponents settings in the chainspec if defined in ENV variables 9 | ## 10 | [[ $MINIMUM_ROUND_EXPONENT != "" ]] && sed -E "s/^(minimum_round_exponent = ).+$/\1 $MINIMUM_ROUND_EXPONENT/" $PATH_TO_CHAINSPEC > $PATH_TO_CHAINSPEC.min && PATH_TO_CHAINSPEC=$PATH_TO_CHAINSPEC.min 11 | [[ $MAXIMUM_ROUND_EXPONENT != "" ]] && sed -E "s/^(maximum_round_exponent = ).+$/\1 $MAXIMUM_ROUND_EXPONENT/" $PATH_TO_CHAINSPEC > $PATH_TO_CHAINSPEC.max && PATH_TO_CHAINSPEC=$PATH_TO_CHAINSPEC.max 12 | 13 | ## Change deploy_delay setting in the nodes config.toml file if defined in ENV variables 14 | ## 15 | [[ $DEPLOY_DELAY != "" ]] && sed -E "s/^#?(deploy_delay = ).+$/\1 '$DEPLOY_DELAY'/" $PATH_TO_CONFIG_TOML > $PATH_TO_CONFIG_TOML.mod && PATH_TO_CONFIG_TOML=$PATH_TO_CONFIG_TOML.mod 16 | 17 | alias casper-client=/home/casper/casper-client-rs/target/release/casper-client 18 | source $NCTL/activate 19 | source $NCTL/sh/assets/teardown.sh 20 | source $NCTL/sh/assets/setup.sh config_path=$PATH_TO_CONFIG_TOML chainspec_path=$PATH_TO_CHAINSPEC 21 | if [ "$PREDEFINED_ACCOUNTS" = "true" ]; then 22 | tar -zxvf net-1-predefined-accounts.tar.gz -C /home/casper/casper-node/utils/nctl/assets/net-1/ 23 | fi 24 | source $NCTL/sh/node/start.sh 25 | tail -f /home/casper/casper-node/utils/nctl/assets/net-1/nodes/node-1/logs/stderr.log 26 | -------------------------------------------------------------------------------- /test/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | def pytest_addoption(parser): 4 | parser.addoption("--image", action="store", default="makesoftware/casper-nctl") 5 | -------------------------------------------------------------------------------- /test/test_nctl.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import subprocess 3 | import testinfra 4 | import time 5 | 6 | # scope='session' uses the same container for all the tests; 7 | # scope='function' uses a new container per test function. 8 | @pytest.fixture(scope="session") 9 | def image(pytestconfig): 10 | return pytestconfig.getoption("image") 11 | 12 | @pytest.fixture(scope='session') 13 | def host(request,pytestconfig): 14 | # run a container 15 | docker_id = subprocess.check_output( 16 | ['docker', 'run', '-d', pytestconfig.getoption('image')]).decode().strip() 17 | # wait until it's running' 18 | output = subprocess.check_output(['docker', 'inspect', '-f "{{.State.Health.Status}}"', docker_id]).decode().strip(' \n\t\"') 19 | retries=12 20 | while "healthy" != output and retries>=0: 21 | time.sleep(5) 22 | retries-=1 23 | output = subprocess.check_output(['docker', 'inspect', '-f "{{.State.Health.Status}}"', docker_id]).decode().strip(' \n\t\"') 24 | # return a testinfra connection to the container 25 | yield testinfra.get_host("docker://" + docker_id) 26 | # at the end of the test suite, destroy the container 27 | subprocess.check_call(['docker', 'rm', '-f', docker_id]) 28 | 29 | def test_user_is_present(host): 30 | user_name = 'casper' 31 | group_name = 'casper' 32 | home_dir = '/home/casper' 33 | shell = '/bin/bash' 34 | 35 | usr = host.user(user_name) 36 | assert user_name in usr.name 37 | assert group_name in usr.group 38 | assert home_dir in usr.home 39 | assert shell in usr.shell 40 | 41 | def test_root_is_present(host): 42 | user_name = 'root' 43 | group_name = 'root' 44 | home_dir = '/root' 45 | shell = '/bin/bash' 46 | 47 | usr = host.user(user_name) 48 | assert user_name in usr.name 49 | assert group_name in usr.group 50 | assert home_dir in usr.home 51 | assert shell in usr.shell 52 | 53 | def test_sudo_is_enabled(host): 54 | 55 | response = host.check_output('sudo whoami') 56 | assert response == 'root' 57 | 58 | def test_assets_are_present(host): 59 | 60 | assert host.file("/home/casper/net-1-predefined-accounts.tar.gz").exists 61 | assert host.file("/home/casper/restart.sh").exists 62 | 63 | def test_casper_client_is_present(host): 64 | 65 | cmd = host.run("/home/casper/casper-client-rs/target/release/casper-client --help") 66 | assert cmd.rc == 0 67 | 68 | def test_rpc_is_responsive(host): 69 | 70 | cmd = host.run('/bin/bash -i -c "source /home/casper/casper-node/utils/nctl/sh/views/view_node_status.sh node=1"') 71 | assert cmd.rc == 0 72 | 73 | def test_five_nodes_are_running(host): 74 | 75 | response = host.check_output('/bin/bash -i -c "nctl-status | grep -c RUNNING" | tail -1') 76 | assert response == '5' 77 | 78 | def test_nctl_commands_are_activated(host): 79 | 80 | cmd = host.run('/bin/bash -i -c "nctl-status"') 81 | assert cmd.rc == 0 82 | 83 | def test_environment_home(host): 84 | assert host.environment().get("NCTL") == "/home/casper/casper-node/utils/nctl" 85 | assert host.environment().get("NCTL_CASPER_HOME") == "/home/casper/casper-node" 86 | assert host.environment().get("NCTL_CASPER_NODE_LAUNCHER_HOME") == "/home/casper/casper-node-launcher" 87 | --------------------------------------------------------------------------------