generated from multiversx/mx-chain-ws-connector-template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-testnet.sh
119 lines (100 loc) · 3.28 KB
/
local-testnet.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
CURRENT_DIR=$(pwd)
WORKING_DIR="$CURRENT_DIR"
TESTNET_DIR=$WORKING_DIR/testnet
TESTNET_OUTPUT_DIR=$TESTNET_DIR/testnet-local
SCRIPTS_DIR=mx-chain-go/scripts/testnet
VARIABLES_PATH=$SCRIPTS_DIR/variables.sh
OBSERVERS_PATH=$SCRIPTS_DIR/include/observers.sh
VALIDATORS_PATH=$SCRIPTS_DIR/include/validators.sh
ENABLE_EPOCH_DIR=$TESTNET_DIR/mx-chain-go/cmd/node/config/enableEpochs.toml
SANDBOX_NAME=sandbox
cloneDependencies(){
if [ -d "$TESTNET_DIR" ]; then
rm -rf $TESTNET_DIR
fi
mkdir "$TESTNET_DIR"
git clone https://github.com/multiversx/mx-chain-go "$TESTNET_DIR/mx-chain-go"
checkoutStableVersion mx-chain-go cc39c2460f69e9db3e7970519f8474c8abbc294f
git clone https://github.com/multiversx/mx-chain-deploy-go "$TESTNET_DIR/mx-chain-deploy-go"
git clone https://github.com/multiversx/mx-chain-proxy-go "$TESTNET_DIR/mx-chain-proxy-go"
checkoutStableVersion mx-chain-proxy-go rc/v1.6.0
}
checkoutStableVersion(){
cd $TESTNET_DIR/$1
git checkout $2
cd ../..
}
testnetRemove(){
rm -rf "$TESTNET_OUTPUT_DIR"
}
testnetSetup(){
sed -i 's/BuiltInFunctionsEnableEpoch =.*/BuiltInFunctionsEnableEpoch = 0/' "$ENABLE_EPOCH_DIR"
mkdir "$TESTNET_OUTPUT_DIR"
cd "$TESTNET_OUTPUT_DIR"
ln -s "$TESTNET_DIR"/mx-chain-go mx-chain-go
ln -s "$TESTNET_DIR"/mx-chain-deploy-go mx-chain-deploy-go
ln -s "$TESTNET_DIR"/mx-chain-proxy-go mx-chain-proxy-go
}
testnetPrereq(){
cd "$TESTNET_OUTPUT_DIR" && \
bash $SCRIPTS_DIR/prerequisites.sh && \
echo -e "export TESTNETDIR=$TESTNET_OUTPUT_DIR/$SANDBOX_NAME" > $SCRIPTS_DIR/local.sh && \
bash $SCRIPTS_DIR/config.sh
}
testnetUpdateVariables(){
sed -i 's/export SHARDCOUNT=.*/export SHARDCOUNT=1/' $VARIABLES_PATH
sed -i 's/SHARD_VALIDATORCOUNT=.*/SHARD_VALIDATORCOUNT=1/' $VARIABLES_PATH
sed -i 's/SHARD_OBSERVERCOUNT=.*/SHARD_OBSERVERCOUNT=1/' $VARIABLES_PATH
sed -i 's/SHARD_CONSENSUS_SIZE=.*/SHARD_CONSENSUS_SIZE=$SHARD_VALIDATORCOUNT/' $VARIABLES_PATH
sed -i 's/META_VALIDATORCOUNT=.*/META_VALIDATORCOUNT=1/' $VARIABLES_PATH
sed -i 's/META_OBSERVERCOUNT=.*/META_OBSERVERCOUNT=1/' $VARIABLES_PATH
sed -i 's/META_CONSENSUS_SIZE=.*/META_CONSENSUS_SIZE=$META_VALIDATORCOUNT/' $VARIABLES_PATH
sed -i 's/export NODE_DELAY=.*/export NODE_DELAY=30/' $VARIABLES_PATH
sed -i 's/EXTRA_OBSERVERS_FLAGS.*/EXTRA_OBSERVERS_FLAGS --operation-mode db-lookup-extension"/' $OBSERVERS_PATH
sed -i 's/config_validator.toml/config_validator.toml --operation-mode db-lookup-extension/' $VALIDATORS_PATH
}
testnetNew(){
cloneDependencies
testnetRemove
testnetSetup
testnetUpdateVariables
testnetPrereq
}
testnetStart(){
cd "$TESTNET_DIR" && \
./mx-chain-go/scripts/testnet/start.sh
}
testnetReset(){
cd "$TESTNET_DIR" && \
./mx-chain-go/scripts/testnet/reset.sh
}
testnetStop(){
cd "$TESTNET_DIR" && \
./mx-chain-go/scripts/testnet/stop.sh
}
echoOptions(){
echo "ERROR!!! Please choose one of the following parameters:
- new to create a new testnet
- start to start the testnet
- reset to reset the testnet
- stop to stop the testnet"
}
main(){
if [ $# -eq 1 ]; then
case "$1" in
new)
testnetNew ;;
start)
testnetStart ;;
reset)
testnetReset ;;
stop)
testnetStop ;;
*)
echoOptions ;;
esac
else
echoOptions
fi
}
main "$@"