Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable check:construction in Github actions for private network #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/scripts/cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Downloading cli
curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s

echo "start check:construction"
./bin/rosetta-cli check:construction --configuration-file rosetta-cli-conf/devnet/config.json
26 changes: 26 additions & 0 deletions .github/scripts/populate_txns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from web3 import Web3
from web3.middleware import geth_poa_middleware
from eth_account import Account

web3 = Web3(Web3.HTTPProvider("http://localhost:9650/ext/bc/C/rpc"))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)

privateKey = "0x56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"
acct = Account.from_key(privateKey)
web3.eth.defaultAccount = acct
print(acct.address, "has balance", web3.eth.get_balance(acct.address))

if len(web3.eth.accounts) == 0:
web3.geth.personal.import_raw_key(privateKey, "")
web3.geth.personal.unlock_account(acct.address, '')

print("latest block", web3.eth.block_number, web3.eth.accounts)

for _ in range(2):
tx = web3.eth.send_transaction({
'to': "0x26Cb836E81bFc47c2530aDBF63968c9830a44C8d",
'from': acct.address,
'value': 12345
})

print("tx hash:", tx.hex())
71 changes: 71 additions & 0 deletions .github/scripts/runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
set -e

VERSION=1.9.0
MODE="test"

echo "Running with:"
echo VERSION: ${VERSION}
echo MODE: ${MODE}

###########################
# download avalanchego
# https://github.com/ava-labs/avalanchego/releases
GOARCH=$(go env GOARCH)
GOOS=$(go env GOOS)
DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/v${VERSION}/avalanchego-linux-${GOARCH}-v${VERSION}.tar.gz
DOWNLOAD_PATH=/tmp/avalanchego.tar.gz
if [[ ${GOOS} == "darwin" ]]; then
DOWNLOAD_URL=https://github.com/ava-labs/avalanchego/releases/download/v${VERSION}/avalanchego-macos-v${VERSION}.zip
DOWNLOAD_PATH=/tmp/avalanchego.zip
fi

rm -rf /tmp/avalanchego-v${VERSION}
rm -f ${DOWNLOAD_PATH}

echo "downloading avalanchego ${VERSION} at ${DOWNLOAD_URL}"
curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded avalanchego"
if [[ ${GOOS} == "linux" ]]; then
tar xzvf ${DOWNLOAD_PATH} -C /tmp
elif [[ ${GOOS} == "darwin" ]]; then
unzip ${DOWNLOAD_PATH} -d /tmp/avalanchego-build
mv /tmp/avalanchego-build/build /tmp/avalanchego-v${VERSION}
fi
find /tmp/avalanchego-v${VERSION}

AVALANCHEGO_PATH=/tmp/avalanchego-v${VERSION}/avalanchego
AVALANCHEGO_PLUGIN_DIR=/tmp/avalanchego-v${VERSION}/plugins


#################################
# download avalanche-network-runner
# https://github.com/ava-labs/avalanche-network-runner
#curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s

# Install latest
git clone https://github.com/ava-labs/avalanche-network-runner.git
cd avalanche-network-runner
go install
cd ..

#################################
# run "avalanche-network-runner" server
echo "launch avalanche-network-runner in the background"
~/go/bin/avalanche-network-runner \
server \
--log-level debug \
--port=":8080" \
--grpc-gateway-port=":8081" &

sleep 5

~/go/bin/avalanche-network-runner control start \
--log-level debug \
--endpoint="0.0.0.0:8080" \
--number-of-nodes=5 \
--avalanchego-path ${AVALANCHEGO_PATH} \
--global-node-config '{"chain-config-dir": "rosetta-cli-conf/cchain"}'

sleep 20
12 changes: 12 additions & 0 deletions .github/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

make build
nohup ./rosetta-server -config=./scripts/config.json > /dev/null 2>&1 &

sleep 15

curl -s --location --request POST 'http://localhost:8085/network/list' \
--header 'Content-Type: application/json' \
--data-raw '{
"metadata" : {}
}'
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,44 @@ env:
go_version: 1.19

jobs:
Rosetta-Validation:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Start Avalanche node
run: .github/scripts/runner.sh
shell: bash

- name: Test node stability
run: |
curl -X POST -k http://localhost:8081/v1/ping -d ''
shell: bash

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install web3

- name: Populate transactions
run: python .github/scripts/populate_txns.py
shell: bash

- name: Start Rosetta server
run: .github/scripts/setup.sh
shell: bash

- name: Run rosetta-cli check:construction
run: .github/scripts/cli.sh
shell: bash

Build:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.so
*.dylib
*.test
*.json
*.log
*.out
avalanche-rosetta
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ run-mainnet-offline:
-it \
${DOCKER_TAG}

# Start the Devnet in ONLINE mode
run-devnet:
docker run \
--rm \
-d \
-v ${WORKDIR}/data:/data \
-e AVALANCHE_NETWORK=network-1337 \
-e AVALANCHE_CHAIN=43112 \
-e AVALANCHE_MODE=online \
--name avalanche-devnet \
-p 8085:8085 \
-p 9650:9650 \
-p 9651:9651 \
-it \
${DOCKER_TAG}

# Perform the Testnet data check
check-testnet-data:
rosetta-cli check:data --configuration-file=rosetta-cli-conf/testnet/config.json
Expand Down
3 changes: 3 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func main() {
case mapper.FujiChainID:
assetID = mapper.FujiAssetID
AP5Activation = mapper.FujiAP5Activation.Uint64()
case mapper.LocalChainID:
assetID = mapper.LocalAssetID
AP5Activation = mapper.FujiAP5Activation.Uint64()
default:
log.Fatal("invalid ChainID:", cfg.ChainID)
}
Expand Down
3 changes: 3 additions & 0 deletions mapper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const (
FujiChainID = 43113
FujiAssetID = "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"

LocalChainID = 43112
LocalAssetID = "BR28ypgLATNS6PbtHMiJ7NQ61vfpT27Hj8tAcZ1AHsfU5cz88"

ContractAddressMetadata = "contractAddress"
IndexTransferredMetadata = "indexTransferred"

Expand Down
31 changes: 31 additions & 0 deletions rosetta-cli-conf/cchain/C/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"snowman-api-enabled": false,
"coreth-admin-api-enabled": false,
"coreth-admin-api-dir": "",
"eth-apis": ["eth", "eth-filter", "net", "web3", "internal-eth", "internal-blockchain", "internal-transaction", "internal-account", "debug", "internal-personal", "debug-tracer"],
"continuous-profiler-dir": "",
"continuous-profiler-frequency": 900000000000,
"continuous-profiler-max-files": 5,
"rpc-gas-cap": 50000000,
"rpc-tx-fee-cap": 100,
"preimages-enabled": false,
"pruning-enabled": true,
"snapshot-async": true,
"snapshot-verification-enabled": false,
"metrics-enabled": false,
"metrics-expensive-enabled": false,
"local-txs-enabled": false,
"api-max-duration": 0,
"ws-cpu-refill-rate": 0,
"ws-cpu-max-stored": 0,
"api-max-blocks-per-request": 0,
"allow-unfinalized-queries": false,
"allow-unprotected-txs": false,
"keystore-directory": "",
"keystore-external-signer": "",
"keystore-insecure-unlock-allowed": false,
"remote-tx-gossip-only-enabled": false,
"tx-regossip-frequency": 60000000000,
"tx-regossip-max-size": 15,
"log-level": "debug"
}
69 changes: 69 additions & 0 deletions rosetta-cli-conf/devnet/avalanche.ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
create_account(1){
create{
network = set_variable({"network":"network-1337", "blockchain":"Avalanche"});
key = generate_key({"curve_type": "secp256k1"});
account = derive({
"network_identifier": {{network}},
"public_key": {{key.public_key}}
});

// If the account is not saved, the key will be lost!
save_account({
"account_identifier": {{account.account_identifier}},
"keypair": {{key}}
});
}
}

simple_transfer(1){
transfer{
transfer.network = {"network":"network-1337", "blockchain":"Avalanche"};
currency = {"symbol":"AVAX", "decimals":18};
sender = find_balance({
"minimum_balance":{
"value": "10000000000000000", // 0.01 AVAX
"currency": {"symbol":"AVAX", "decimals":18}
}
});

// Set the recipient_amount as some value <= sender.balance-max_fee
max_fee = "4725000000000000"; // 0.004725 AVAX
available_amount = {{sender.balance.value}} - {{max_fee}};
recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}});
print_message({"recipient_amount":{{recipient_amount}}});

// Find recipient and construct operations
sender_amount = 0 - {{recipient_amount}};
recipient = find_balance({
"not_account_identifier":[{{sender.account_identifier}}],
"minimum_balance":{
"value": "0",
"currency": {"symbol":"AVAX", "decimals":18}
},
"create_limit": 100,
"create_probability": 50
});
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"CALL",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{"symbol":"AVAX", "decimals":18}
}
},
{
"operation_identifier":{"index":1},
"type":"CALL",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{"symbol":"AVAX", "decimals":18}
}
}
];
}
}

39 changes: 39 additions & 0 deletions rosetta-cli-conf/devnet/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"network": {
"blockchain": "Avalanche",
"network": "network-1337"
},
"online_url": "http://localhost:8085",
"http_timeout": 500,
"max_retries": 50,
"retry_elapsed_time": 0,
"max_online_connections": 500,
"max_sync_concurrency": 50,
"tip_delay": 3600,
"log_configuration": false,
"compression_disabled": false,
"data_directory": "rosetta-data",
"construction": {
"offline_url": "http://localhost:8085",
"stale_depth": 5,
"broadcast_limit": 15,
"constructor_dsl_file": "./avalanche.ros",
"end_conditions": {
"create_account": 1,
"simple_transfer": 1
},
"prefunded_accounts": [
{
"privkey": "56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027",
"account_identifier": {
"address": "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
},
"curve_type": "secp256k1",
"currency": {
"symbol": "AVAX",
"decimals": 18
}
}
]
}
}
7 changes: 7 additions & 0 deletions scripts/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rpc_endpoint": "http://localhost:9650",
"mode": "online",
"listen_addr": "0.0.0.0:8085",
"genesis_block_hash" :"0x31ced5b9beb7f8782b014660da0cb18cc409f121f408186886e1ca3e8eeca96b"
}