The Python scripts in this package are used to simulate RainTree (in Python) to understand, visualize and validate the Golang implementation in the primary V1 implementation.
It uses a Breadth First Search approach to mimic the actual network-based implementation of RainTree (implemented in Go). It can be considered an alternative "validation client" to verify the P2P implementation.
The primary goal is to use this library to generate unit tests that can be copy-pasted into the main repo.
rain-tree-sim/python
├── README.md # This file
├── requirements.txt # Python requirements to run file
├── simulator.py # Utility functions used to simulate RainTree
└── test_generator.py # The entrypoint used by `make p2p_test_generator` to generate RainTree unit tests
- Basic RainTree implementation
- Unit Test generation
- Redundancy Layer
- Cleanup Layer
- Dead / partially visible nodes
- Fuzz testing
- Multi-simulation evaluation + plotting
Make sure you install the corresponding dependencies.
pip3 install -r python/requirements.txt
- Python:
v3.10.8
or greater - pip3
To run the simulator, do the following:
git clone https://github.com/pokt-network/rain-tree-sim.git
cd python
pip3 install -r requirements.txt
Run the following command:
rainTreeTestOutputFilename=/tmp/answer.go numRainTreeNodes=12 make p2p_test_generator
If you wish to run different scenarios, you can modify two parameters to the p2p_test_generator
make target:
rainTreeTestOutputFilename
: the file where the unit test should be written tonumRainTreeNodes
: the number of nodes to run in the RainTree simulation
By default, the test stores the results at: /tmp/answer.go
.
Through termainal, you can view it with: cat /tmp/answer.go
If you're using VS-Code, you can open it using: code /tmp/answer.go
Note: if you are going to be running the Pocket Unit test with the results, leave this file open and read the section below.
You can run the p2p unit test in the Pocket repo, which will break down the messages that is being sent from one node to another from the pre-defined RainTree test as well as the unique test generated from the Python simulator.
Before you can run the unit test, you will first need to clone the Pocket repo and follow the local env setup steps outlined here.
- Open up the output file located:
/tmp/answer.go
- Add comments to the tree visualization(see below)
// val_1
// ┌──────────────────────┴────────────┬────────────────────────────────┐
// val_4 val_1 val_7
// ┌───────┴────┬─────────┐ ┌───────┴────┬─────────┐ ┌───────┴────┬─────────┐
// val_6 val_4 val_8 val_3 val_1 val_5 val_9 val_7 val_2
- Inside of the pocket repo - Navigate to the
module_raintree_test.go
file located in the/p2p/
folder. - Copy and paste the modified
answer.go
file below one of the existingTestRainTreeNetworkComplete"X"
functions inmodule_raintree_test.go
to add a new unit test. - In the main Pocket dir you can run two commands:
make test_p2p
: runs the entiremodule_raintree_test.go
filego test -v -count=1 -v ./p2p/... -run <function-name-inside-answers.go file>
: which will run the function specified in themodule_raintree_test.go
file