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

Run rosetta tests against local kava network #69

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
18 changes: 18 additions & 0 deletions .github/scripts/kava-localnet-ci/cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

end_idx=($(curl -s --location --request POST 'http://localhost:8000/network/status' \
--header 'Content-Type: application/json' \
--data-raw '{
"network_identifier": {
"blockchain": "Kava",
"network": "kava-localnet"
}
}' | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["current_block_identifier"]["index"])'))

latest_X_blocks=10
start_idx=$(($end_idx - $latest_X_blocks))

echo "start check:data"
echo "start_idx: $start_idx"
echo "end_idx : $end_idx"
./bin/rosetta-cli --configuration-file rosetta-cli-conf/kava-localnet-ci/config.json check:data --start-block $start_idx --end-block $end_idx
4 changes: 4 additions & 0 deletions .github/scripts/kava-localnet-ci/construction.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "start check:construction"
./bin/rosetta-cli --configuration-file rosetta-cli-conf/kava-localnet-ci/config.json check:construction
18 changes: 18 additions & 0 deletions .github/scripts/kava-localnet-ci/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

make run-local &
make run-local-offline &

sleep 5

block_tip=($(curl -s --location --request POST 'http://localhost:8000/network/status' \
--header 'Content-Type: application/json' \
--data-raw '{
"network_identifier": {
"blockchain": "Kava",
"network": "kava-localnet"
}
}' | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["current_block_identifier"]["index"])'))

echo "latest block index is", $block_tip

15 changes: 15 additions & 0 deletions .github/scripts/wait-for-node-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
get_block_number() {
local BLOCK_NUMBER=$(curl -sS -X POST \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
-H "Content-Type: application/json" \
http://localhost:8545 | jq .result)
echo $BLOCK_NUMBER
}

BLOCK_NUMBER=$(get_block_number)

while [ "$BLOCK_NUMBER" == "" ]
do
BLOCK_NUMBER=$(get_block_number)
sleep 0.5
done
79 changes: 79 additions & 0 deletions .github/workflows/ci-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Run Tests Against Local Kava Network

on:
push:
branches: [ master, process_kava_dispatch ]
# repository_dispatch event will be sent by kava on every kava commit
repository_dispatch:

jobs:
setup-and-run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout rosetta-kava
uses: actions/checkout@v4
with:
path: rosetta-kava

# TODO(yevhenii): consider reusing already built kava docker image instead of rebuilding it
- name: Checkout kava
uses: actions/checkout@v4
with:
repository: Kava-Labs/kava
path: kava

- name: Checkout kvtool
uses: actions/checkout@v4
with:
repository: Kava-Labs/kvtool
path: kvtool

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: rosetta-kava/go.mod

- name: Cache Go Modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('./rosetta-kava/**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build kava docker image
run: make docker-build
working-directory: ./kava

- name: Install kvtool
run: make install
working-directory: ./kvtool

- name: Run kava docker container
run: KAVA_TAG=local kvtool t bootstrap

- name: Wait until kava node is ready to serve traffic
run: bash ${GITHUB_WORKSPACE}/rosetta-kava/.github/scripts/wait-for-node-init.sh

- name: Run integration tests
run: KAVA_RPC_URL=http://localhost:26657 NETWORK=kava-local PORT=4000 SKIP_LIVE_NODE_TESTS=true make test-integration
working-directory: ./rosetta-kava

- name: Download coinbase rosetta-cli
run: "curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s"
working-directory: ./rosetta-kava

- name: Start rosetta server
run: .github/scripts/kava-localnet-ci/setup.sh
shell: bash
working-directory: ./rosetta-kava

- name: Run check:construction test
run: .github/scripts/kava-localnet-ci/construction.sh
shell: bash
working-directory: ./rosetta-kava

- name: Run check:data test
run: .github/scripts/kava-localnet-ci/cli.sh
shell: bash
working-directory: ./rosetta-kava
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ run-testnet:
run-local:
MODE=online NETWORK=kava-localnet PORT=8000 KAVA_RPC_URL=http://localhost:26657 go run . run

.PHONY: run-local-offline
run-local-offline:
MODE=offline NETWORK=kava-localnet PORT=8001 KAVA_RPC_URL=http://localhost:26657 go run . run

.PHONY: test
test:
go test -v ./...
Expand Down
1 change: 1 addition & 0 deletions rosetta-cli-conf/kava-localnet-ci/bootstrap_balances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
73 changes: 73 additions & 0 deletions rosetta-cli-conf/kava-localnet-ci/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"network": {
"blockchain": "Kava",
"network": "kava-localnet"
},
"online_url": "http://localhost:8000",
"data_directory": "",
"http_timeout": 30,
"max_retries": 25,
"retry_elapsed_time": 0,
"max_online_connections": 120,
"max_sync_concurrency": 5,
"tip_delay": 30,
"max_reorg_depth": 100,
"log_configuration": false,
"compression_disabled": false,
"construction": {
"offline_url": "http://localhost:8001",
"max_offline_connections": 100,
"force_retry": true,
"stale_depth": 5,
"broadcast_limit": 5,
"ignore_broadcast_failures": false,
"clear_broadcasts": false,
"constructor_dsl_file": "kava.ros",
"end_conditions": {
"create_account": 1,
"transfer": 1
},
"quiet": false,
"initial_balance_fetch_disabled": false,
"prefunded_accounts": [
{
"privkey": "6034eb3856dd7cca4b5d9bfc5f262ab155d967dc2f8b78485eae6a7cbb5e7c51",
"account_identifier": {
"address": "kava173w2zz287s36ewnnkf4mjansnthnnsz7rtrxqc"
},
"curve_type": "secp256k1",
"currency":{
"symbol": "KAVA",
"decimals": 6
}
}
]
},
"data": {
"active_reconciliation_concurrency": 16,
"inactive_reconciliation_concurrency": 4,
"inactive_reconciliation_frequency": 250,
"log_blocks": false,
"log_transactions": false,
"log_balance_changes": false,
"log_reconciliations": false,
"ignore_reconciliation_error": false,
"exempt_accounts": "exempt_accounts.json",
"bootstrap_balances": "bootstrap_balances.json",
"interesting_accounts": "",
"reconciliation_disabled": false,
"reconciliation_drain_disabled": false,
"balance_tracking_disabled": false,
"coin_tracking_disabled": false,
"status_port": 9090,
"results_output_file": "",
"initial_balance_fetch_disabled": false,
"end_conditions": {
"reconciliation_coverage": {
"coverage": 0.95,
"from_tip": true,
"tip": true
}
}
}
}
1 change: 1 addition & 0 deletions rosetta-cli-conf/kava-localnet-ci/exempt_accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
66 changes: 66 additions & 0 deletions rosetta-cli-conf/kava-localnet-ci/kava.ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
create_account(1){
create{
network = set_variable({"network":"kava-localnet", "blockchain":"Kava"});
key = generate_key({"curve_type": "secp256k1"});
account = derive({
"network_identifier": {{network}},
"public_key": {{key.public_key}}
});
save_account({
"account_identifier": {{account.account_identifier}},
"keypair": {{key}}
});
}
}

transfer(1){
transfer{
transfer.network = set_variable({"network":"kava-localnet", "blockchain":"Kava"});
currency = {"symbol":"KAVA", "decimals":6};
sender = find_balance({
"minimum_balance":{
"value": "100000",
"currency": {{currency}}
}
});

// Set the recipient_amount as some value <= sender.balance-max_fee
max_fee = "1000";
recipient_amount = "1001";
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": {{currency}}
},
"create_limit": 100,
"create_probability": 50
});
transfer.confirmation_depth = "1";
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"transfer",
"account":{{sender.account_identifier}},
"amount":{
"value":{{sender_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"related_operations":[{"index":0}],
"type":"transfer",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{{currency}}
}
}
];
}
}
5 changes: 5 additions & 0 deletions testing/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package testing
import (
"context"
"math/rand"
"os"
"regexp"
"testing"
"time"
Expand All @@ -34,6 +35,10 @@ func TestBlockRetry(t *testing.T) {
t.Skip("offline: skipping block retry test")
}

if os.Getenv("SKIP_LIVE_NODE_TESTS") == "true" {
t.Skip("skipping block retry test: it's designed to be run against a live (mainnet) node")
}

numJobs := 10
jobCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
Expand Down
Loading