Skip to content
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
63 changes: 63 additions & 0 deletions .github/workflows/fiber-stable-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: fiber stable action
on:
workflow_dispatch: # Allows the workflow to be manually triggered
inputs:
GitUrl:
description: 'fiber -git url'
default: 'https://github.com/nervosnetwork/fiber.git'
GitBranch:
description: 'fiber -git branch'
default: 'develop'
BuildFIBER:
description: 'build fiber'
default: 'true'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Print Input Values
run: |
echo "**Input Values:**"
echo " GitUrl: ${{ github.event.inputs.GitUrl }}"
echo " GitBranch: ${{ github.event.inputs.GitBranch }}"
echo " BuildCKbCLI: ${{ github.event.inputs.BuildFIBER }}"


- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: Install dependencies
run: make prepare_develop_testnet
env:
GitUrl: '${{ github.event.inputs.GitUrl }}'
GitBranch: '${{ github.event.inputs.GitBranch }}'
BuildFIBER: '${{ github.event.inputs.BuildFIBER }}'

- name: Run tests
run: make fiber_test_demo FIBER_TEST_DEMO="test_cases/fiber/devnet/stable"

# - name: Setup upterm session
# if: always()
# uses: lhotari/action-upterm@v1

- name: Publish reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: jfoa-build-reports-${{ runner.os }}
path: ./report
4 changes: 2 additions & 2 deletions .github/workflows/fiber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
name: jfoa-open_channel-reports-${{ runner.os }}
path: ./report

fiber_test_accept_channel_cancel_invoice_connect_peer_disconnect_peer:
fiber_test_accept_channel_cancel_invoice_connect_peer_disconnect_peer_backup:
needs: prepare
runs-on: ubuntu-22.04

Expand All @@ -106,7 +106,7 @@ jobs:
tar -xzf prepare-backup.tar.gz

- name: Run fiber_test_demo
run: make fiber_test_demo FIBER_TEST_DEMO="test_cases/fiber/devnet/accept_channel test_cases/fiber/devnet/cancel_invoice test_cases/fiber/devnet/connect_peer test_cases/fiber/devnet/disconnect_peer"
run: make fiber_test_demo FIBER_TEST_DEMO="test_cases/fiber/devnet/accept_channel test_cases/fiber/devnet/cancel_invoice test_cases/fiber/devnet/connect_peer test_cases/fiber/devnet/disconnect_peer test_cases/fiber/devnet/backup"

- name: Publish reports
if: failure()
Expand Down
11 changes: 1 addition & 10 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@
from tqdm import tqdm

versions = [
"0.109.0",
"0.110.2",
"0.111.0",
"0.112.1",
"0.113.1",
"0.114.0",
"0.115.0",
"0.116.1",
"0.117.0",
"0.118.0",
"0.119.0-rc1",
"0.117.0" "0.201.0",
] # Replace with your versions

DOWNLOAD_DIR = "download"
Expand Down
6 changes: 0 additions & 6 deletions download_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
from tqdm import tqdm

versions = [
"0.2.0",
"0.2.1",
"0.3.0",
"0.3.1",
"0.4.0",
"0.4.2",
"0.5.0",
"0.5.1",
] # Replace with your versions
Expand Down
23 changes: 15 additions & 8 deletions framework/basic_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FiberTest(CkbTest):
fiber_version = FiberConfigPath.CURRENT_DEV
logger = logging.getLogger(__name__)
start_fiber_config = {}
fnn_log_level = "debug"

@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -130,10 +131,10 @@ def setup_method(cls, method):
update_config.update(cls.start_fiber_config)

cls.fiber1.prepare(update_config=update_config)
cls.fiber1.start()
cls.fiber1.start(fnn_log_level=cls.fnn_log_level)

cls.fiber2.prepare(update_config=update_config)
cls.fiber2.start()
cls.fiber2.start(fnn_log_level=cls.fnn_log_level)
before_balance1 = cls.Ckb_cli.wallet_get_capacity(
cls.account1["address"]["testnet"], api_url=cls.node.getClient().url
)
Expand Down Expand Up @@ -255,7 +256,7 @@ def start_new_fiber(
self.fibers.append(fiber)
self.new_fibers.append(fiber)
fiber.prepare(update_config=update_config)
fiber.start()
fiber.start(fnn_log_level=self.fnn_log_level)
return fiber

def wait_for_channel_state(
Expand Down Expand Up @@ -416,7 +417,9 @@ def send_payment(self, fiber1, fiber2, amount, wait=True, udt=None, try_count=5)
}
)
if wait:
self.wait_payment_state(fiber1, payment["payment_hash"], "Success")
self.wait_payment_state(
fiber1, payment["payment_hash"], "Success", 600, 0.1
)
return payment["payment_hash"]
except Exception as e:
time.sleep(1)
Expand All @@ -431,7 +434,9 @@ def send_payment(self, fiber1, fiber2, amount, wait=True, udt=None, try_count=5)
}
)
if wait:
self.wait_payment_state(fiber1, payment["payment_hash"], "Success")
self.wait_payment_state(
fiber1, payment["payment_hash"], "Success", 600, 0.1
)
return payment["payment_hash"]

def get_account_script(self, account_private_key):
Expand All @@ -442,14 +447,16 @@ def get_account_script(self, account_private_key):
"args": account1["lock_arg"],
}

def wait_payment_state(self, client, payment_hash, status="Success", timeout=360):
def wait_payment_state(
self, client, payment_hash, status="Success", timeout=360, interval=1
):
for i in range(timeout):
result = client.get_client().get_payment({"payment_hash": payment_hash})
if result["status"] == status:
return
time.sleep(1)
time.sleep(interval)
raise TimeoutError(
f"status did not reach state: {status} within timeout period."
f"payment:{payment_hash} status did not reach state: {result['status']}, expected:{status} , within timeout period."
)

def wait_payment_finished(self, client, payment_hash, timeout=120):
Expand Down
26 changes: 10 additions & 16 deletions framework/test_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,10 @@ class FiberConfigPath(Enum):
"download/fiber/0.5.1/fnn",
)

V042_TESTNET = ("/source/template/fiber/config.yml.j2", "download/fiber/0.4.2/fnn")
V040_TESTNET = ("/source/template/fiber/config.yml.j2", "download/fiber/0.4.0/fnn")
V031_TESTNET = ("/source/template/fiber/config.yml.j2", "download/fiber/0.3.1/fnn")
V030_TESTNET = ("/source/template/fiber/config.yml.j2", "download/fiber/0.3.0/fnn")
V020_TESTNET = ("/source/template/fiber/config.yml.j2", "download/fiber/0.2.0/fnn")
V010_TESTNET = ("/source/template/fiber/config.yml.j2", "download/fiber/0.1.0/fnn")

V040_DEV = ("/source/template/fiber/dev_config.yml.j2", "download/fiber/0.4.0/fnn")
V031_DEV = ("/source/template/fiber/dev_config.yml.j2", "download/fiber/0.3.1/fnn")
V030_DEV = ("/source/template/fiber/dev_config.yml.j2", "download/fiber/0.3.0/fnn")
V021_DEV = ("/source/template/fiber/dev_config.yml.j2", "download/fiber/0.2.1/fnn")
V020_DEV = ("/source/template/fiber/dev_config.yml.j2", "download/fiber/0.2.0/fnn")
V010_DEV = ("/source/template/fiber/dev_config.yml.j2", "download/fiber/0.1.0/fnn")
V050_DEV = (
"/source/template/fiber/dev_config_2.yml.j2",
"download/fiber/0.5.0/fnn",
)

def __init__(self, fiber_config_path, fiber_bin_path):
self.fiber_config_path = fiber_config_path
Expand Down Expand Up @@ -182,23 +173,26 @@ def migration(self):
f"echo YES | RUST_LOG=info,fnn=debug {get_project_root()}/{self.fiber_config_enum.fiber_bin_path}-migrate -p {self.tmp_path}/fiber/store"
)

def start(self, password="password0"):
def start(self, password="password0", fnn_log_level="debug"):
# env_map = dict(os.environ) # Make a copy of the current environment
# if node:
# contract_map = self.get_contract_env_map(node)
# env_map.update(contract_map)
# for key in env_map:
# print(f"{key}={env_map[key]}")
run_command(
f"FIBER_SECRET_KEY_PASSWORD='{password}' RUST_LOG=info,fnn=debug {get_project_root()}/{self.fiber_config_enum.fiber_bin_path} -c {self.tmp_path}/config.yml -d {self.tmp_path} > {self.tmp_path}/node.log 2>&1 &"
f"FIBER_SECRET_KEY_PASSWORD='{password}' RUST_LOG=info,fnn={fnn_log_level} {get_project_root()}/{self.fiber_config_enum.fiber_bin_path} -c {self.tmp_path}/config.yml -d {self.tmp_path} > {self.tmp_path}/node.log 2>&1 &"
# env=env_map,
)
# wait rpc start
time.sleep(1)
print("start fiber client ")

def stop(self):
run_command(f"kill $(lsof -t -i:{self.rpc_port})", False)
run_command(
"kill $(lsof -i:" + self.rpc_port + " | grep LISTEN | awk '{print $2}')",
False,
)
time.sleep(1)

def force_stop(self):
Expand Down
4 changes: 2 additions & 2 deletions framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class CkbNodeConfigPath(Enum):
"source/template/ckb/v118/ckb.toml.j2",
"source/template/ckb/v118/ckb-miner.toml.j2",
"source/template/ckb/v118/specs/dev.toml",
"download/0.120.0",
"download/0.201.0",
)

CURRENT_FIBER = (
"source/template/ckb/v118/ckb.toml.j2",
"source/template/ckb/v118/ckb-miner.toml.j2",
"source/template/ckb/fiber/dev.toml",
"download/0.119.0",
"download/0.201.0",
)
TESTNET = (
"source/template/ckb/v118/ckb.toml.j2",
Expand Down
4 changes: 2 additions & 2 deletions prepare.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set -ex

DEFAULT_FIBER_BRANCH="develop"
DEFAULT_FIBER_URL="https://github.com/nervosnetwork/fiber.git"
DEFAULT_FIBER_BRANCH="yukang-trivial-fix-on-funding"
DEFAULT_FIBER_URL="https://github.com/chenyukang/fiber.git"

GitFIBERBranch="${GitBranch:-$DEFAULT_FIBER_BRANCH}"
GitFIBERUrl="${GitUrl:-$DEFAULT_FIBER_URL}"
Expand Down
61 changes: 61 additions & 0 deletions test_cases/fiber/devnet/backup/test_backup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import shutil
import time

from framework.basic_fiber import FiberTest


class TestBackup(FiberTest):

def test_backup(self):
"""
1. 关闭节点
2. 替换节点
3. 重启,send payment
Returns:
"""
self.open_channel(self.fiber1, self.fiber2, 1000 * 100000000, 1)
before_graph_nodes = self.fiber2.get_client().graph_nodes()
self.fiber1.stop()
self.fiber1.prepare({"fiber_listening_addr": "/ip4/127.0.0.1/tcp/8238"})
self.fiber1.start()
time.sleep(5)
after_graph_nodes = self.fiber2.get_client().graph_nodes()
self.send_payment(self.fiber1, self.fiber2, 1)
print(before_graph_nodes)
print(after_graph_nodes)
assert (
after_graph_nodes["nodes"][1]["addresses"]
== self.fiber1.get_client().node_info()["addresses"]
)

def test_backup2(self):
"""
1. 不关闭节点
2. 直接备份数据
3. 重启,send payment
Returns:
"""
self.open_channel(self.fiber1, self.fiber2, 1000 * 100000000, 1)
shutil.copytree(
f"{self.fiber1.tmp_path}/fiber", f"{self.fiber1.tmp_path}/fiber.bak"
)
self.fiber1.stop()
shutil.rmtree(f"{self.fiber1.tmp_path}/fiber")
shutil.copytree(
f"{self.fiber1.tmp_path}/fiber.bak", f"{self.fiber1.tmp_path}/fiber"
)
self.fiber1.start()
time.sleep(5)
self.send_payment(self.fiber1, self.fiber2, 1)

def test_backup3(self):
self.open_channel(self.fiber1, self.fiber2, 1000 * 100000000, 1)
self.fiber1.stop()
self.fiber1.prepare({"fiber_listening_addr": "/ip4/127.0.0.1/tcp/8238"})
self.fiber1.start("newPassword2")
time.sleep(5)
self.send_payment(self.fiber1, self.fiber2, 1)
self.fiber1.stop()
self.fiber1.start("newPassword2")
time.sleep(5)
self.send_payment(self.fiber1, self.fiber2, 1)
6 changes: 6 additions & 0 deletions test_cases/fiber/devnet/list_peers/test_list_peers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pytest

from framework.basic_fiber import FiberTest


class TestListPeers(FiberTest):

@pytest.mark.skip("https://github.com/nervosnetwork/fiber/issues/718")
def test_01(self):
peer = self.fiber1.get_client().list_peers()
assert (
Expand All @@ -17,3 +20,6 @@ def test_01(self):
peer["peers"][0]["peer_id"]
== self.fiber2.get_client().node_info()["addresses"][0].split("/")[-1]
)
# https://github.com/nervosnetwork/fiber/issues/718
peers = self.fiber2.get_client().list_peers()
assert len(peers["peers"][0]["addresses"]) == 1
Loading
Loading