Skip to content

Commit

Permalink
tests/truffle: adapt changes in bsc-genesis-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Dec 7, 2023
1 parent a30beeb commit 6c788d7
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/**/*tx_database*
*/**/*dapps*
build/_vendor/pkg
/tests/truffle/storage

#*
.#*
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apk add --no-cache ca-certificates npm nodejs bash alpine-sdk expect

RUN git clone https://github.com/bnb-chain/bsc-genesis-contract.git /root/genesis \
&& cd /root/genesis && npm install
#RUN curl -L https://foundry.paradigm.xyz | bash

COPY --from=bsc /usr/local/bin/geth /usr/local/bin/geth

Expand Down
2 changes: 1 addition & 1 deletion tests/truffle/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BSC_CHAIN_ID=99
BSC_CHAIN_ID=714
CLUSTER_CIDR=99.1.0.0/16
BOOTSTRAP_PUB_KEY=177ae5db445a2f70db781b019aedd928f5b1528a7a43448840b022408f9a21509adcce0b37c87d59da68d47a16879cc1e95a62bbac9723f7b22f4365b2afabbe
BOOTSTRAP_TCP_PORT=30311
Expand Down
25 changes: 14 additions & 11 deletions tests/truffle/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ function prepare() {
echo "geth do not exist!"
exit 1
fi
rm -rf ${workspace}/storage/*
cd ${workspace}/genesis
rm -rf validators.conf
cp ${workspace}/storage/genesis.json ${workspace}/genesis/genesis.json
}

function init_validator() {
node_id=$1
rm -rf ${workspace}/storage/${node_id}
mkdir -p ${workspace}/storage/${node_id}
geth --datadir ${workspace}/storage/${node_id} account new --password /dev/null > ${workspace}/storage/${node_id}Info
validatorAddr=`cat ${workspace}/storage/${node_id}Info|grep 'Public address of the key'|awk '{print $6}'`
echo "${validatorAddr},${validatorAddr},${validatorAddr},0x0000000010000000" >> ${workspace}/genesis/validators.conf
echo ${validatorAddr} > ${workspace}/storage/${node_id}/address
cp -r ${workspace}/storage/keystore ${workspace}/storage/${node_id}/
cp ${workspace}/storage/address ${workspace}/storage/${node_id}/address
}

function generate_genesis() {
cd ${workspace}/genesis/scripts/
node generate-validator.js
INIT_HOLDER_ADDRESSES=$(ls ${workspace}/init-holders | tr '\n' ',')
INIT_HOLDER_ADDRESSES=${INIT_HOLDER_ADDRESSES/%,/}
node generate-initHolders.js --initHolders ${INIT_HOLDER_ADDRESSES}
node generate-genesis.js --chainid ${BSC_CHAIN_ID}

cd ${workspace}/genesis
#source /root/.profile && foundryup
#forge install --no-git --no-commit foundry-rs/[email protected]
bash ${workspace}/genesis/scripts/generate.sh local
}

function init_genesis_data() {
Expand All @@ -43,8 +46,8 @@ function init_genesis_data() {

function prepareBLSWallet(){
node_id=$1
echo "123456" > ${workspace}/storage/${node_id}/blspassword.txt
expect ${workspace}/scripts/create_bls_key.sh ${workspace}/storage/${node_id}
echo "1234567890" > ${workspace}/storage/${node_id}/blspassword.txt
geth bls account new --datadir ${workspace}/storage/${node_id} --blspassword ${workspace}/storage/${node_id}/blspassword.txt

sed -i -e 's/DataDir/BLSPasswordFile = \"{{BLSPasswordFile}}\"\nBLSWalletDir = \"{{BLSWalletDir}}\"\nDataDir/g' ${workspace}/storage/${node_id}/config.toml
PassWordPath="/root/.ethereum/blspassword.txt"
Expand All @@ -54,14 +57,14 @@ function prepareBLSWallet(){
}

prepare

NUMS_OF_VALIDATOR=1
# Step 1, generate config for each validator
for((i=1;i<=${NUMS_OF_VALIDATOR};i++)); do
init_validator "bsc-validator${i}"
done

# Step 2, use validator configs to generate genesis file
generate_genesis
#generate_genesis

# Step 3, use genesis file to init cluster data
init_genesis_data bsc-rpc bsc-rpc
Expand Down
2 changes: 1 addition & 1 deletion tests/truffle/scripts/bsc-rpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ done
geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUSTER_CIDR} \
--verbosity ${VERBOSE} --nousb \
--rpc.allow-unprotected-txs --history.transactions 15768000 \
-unlock ${unlock_sequences} --password /dev/null
-unlock ${unlock_sequences} --password /dev/null >${DATA_DIR}/bscnode-rpc.log
2 changes: 1 addition & 1 deletion tests/truffle/scripts/bsc-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ geth --config ${DATA_DIR}/config.toml --datadir ${DATA_DIR} --netrestrict ${CLUS
--bootnodes enode://${BOOTSTRAP_PUB_KEY}@${BOOTSTRAP_IP}:${BOOTSTRAP_TCP_PORT} \
--mine -unlock ${VALIDATOR_ADDR} --miner.etherbase ${VALIDATOR_ADDR} --password /dev/null \
--light.serve 50 \
--rpc.allow-unprotected-txs --history.transactions 15768000
--rpc.allow-unprotected-txs --history.transactions 15768000 >${DATA_DIR}/bscnode-validator.log
17 changes: 0 additions & 17 deletions tests/truffle/scripts/create_bls_key.sh

This file was deleted.

1 change: 1 addition & 0 deletions tests/truffle/storage/address
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x03735c2ED70a56CD221e0024eB4bF90243C9d6E9
130 changes: 130 additions & 0 deletions tests/truffle/storage/genesis.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"03735c2ed70a56cd221e0024eb4bf90243c9d6e9","crypto":{"cipher":"aes-128-ctr","ciphertext":"b66550ef67345005ead82c9e2835d311fb0e8787191af3696119977064f6120e","cipherparams":{"iv":"5b8f4ed6026ab6c733857e3bed90a869"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"68fc3d0829122badcf8c6efd40c6f2e086a5167db489bed099e3d2b97c1be496"},"mac":"71fd9f23862f7252ca88a6ea2c29fd0ab3527c5b9f5d1f827856263247c92f46"},"id":"7f75b57a-a4ba-4877-a42b-652f966d8aa6","version":3}

1 comment on commit 6c788d7

@weillercarvalho
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible sensitive data exposed in this commit:
1.tests/truffle/storage/keystore/UTC--2023-12-07T03-21-00.035782000Z--03735c2ed70a56cd221e0024eb4bf90243c9d6e9
2.tests/truffle/.env

Please sign in to comment.