Skip to content
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
73 changes: 72 additions & 1 deletion .github/workflows/fiber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ jobs:
run: |
git clone https://github.com/gpBlockchain/fiber-wasm-demo.git
cd fiber-wasm-demo
git checkout new_contract
bash prepare.sh
cd ../
env:
Expand Down Expand Up @@ -544,3 +543,75 @@ jobs:
name: jfoa-fiber_test_send_payment_debug_mixed-reports-${{ runner.os }}
path: ./report

fiber_test_trampoline_routing_one_way:
needs: prepare
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"

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

- name: Download prepare backup
uses: actions/download-artifact@v4
with:
name: prepare-backup-${{ runner.os }}
path: ./

- name: Extract tarball and restore permissions
run: |
tar -xzf prepare-backup.tar.gz

- name: Run fiber_test_demo
run: make fiber_test_demo FIBER_TEST_DEMO="test_cases/fiber/devnet/one_way test_cases/fiber/devnet/trampoline_routing"

- name: Publish reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: jfoa-fiber_test_send_payment_debug_mixed-reports-${{ runner.os }}
path: ./report

fiber_test_compatibility:
needs: prepare
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"

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

- name: Download prepare backup
uses: actions/download-artifact@v4
with:
name: prepare-backup-${{ runner.os }}
path: ./

- name: Extract tarball and restore permissions
run: |
tar -xzf prepare-backup.tar.gz

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

- name: Publish reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: jfoa-fiber_test_send_payment_debug_mixed-reports-${{ runner.os }}
path: ./report

1 change: 1 addition & 0 deletions download_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
versions = [
"0.6.0",
"0.6.1",
"0.7.0",
]

DOWNLOAD_DIR = "download/fiber"
Expand Down
107 changes: 68 additions & 39 deletions framework/basic_fiber.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FiberTest(CkbTest):
start_fiber_config = {}
fnn_log_level = "debug"
beginNum = "0x0"
node: CkbTest.CkbNode

@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -74,7 +75,7 @@ def setup_class(cls):
cls.node.start()
cls.node.getClient().get_consensus()

def setup_method(cls, method):
def setup_method(self, method):
"""
启动2个fiber
给 fiber1 充值udt 金额
Expand All @@ -85,71 +86,72 @@ def setup_method(cls, method):
Returns:

"""
cls.did_pass = None
cls.beginNum = hex(cls.node.getClient().get_tip_block_number())
cls.fibers = []
cls.new_fibers = []
cls.fiber1 = Fiber.init_by_port(
cls.fiber_version,
cls.account1_private_key,
print("setup_method")
self.did_pass = None
self.beginNum = hex(self.node.getClient().get_tip_block_number())
self.fibers = []
self.new_fibers = []
self.fiber1 = Fiber.init_by_port(
self.fiber_version,
self.account1_private_key,
"fiber/node1",
"8228",
"8227",
)
cls.fiber2 = Fiber.init_by_port(
cls.fiber_version,
cls.account2_private_key,
self.fiber2 = Fiber.init_by_port(
self.fiber_version,
self.account2_private_key,
"fiber/node2",
"8229",
"8230",
)
cls.fibers.append(cls.fiber1)
cls.fibers.append(cls.fiber2)
self.fibers.append(self.fiber1)
self.fibers.append(self.fiber2)
#
cls.udtContract = UdtContract(XUDT_TX_HASH, 0)
self.udtContract = UdtContract(XUDT_TX_HASH, 0)
#
deploy_hash, deploy_index = cls.udtContract.get_deploy_hash_and_index()
deploy_hash, deploy_index = self.udtContract.get_deploy_hash_and_index()

if cls.debug:
if self.debug:
return
# # issue
cls.node.getClient().clear_tx_pool()
self.node.getClient().clear_tx_pool()
for i in range(5):
cls.Miner.miner_with_version(cls.node, "0x0")
self.Miner.miner_with_version(self.node, "0x0")
tx_hash = issue_udt_tx(
cls.udtContract,
cls.node.rpcUrl,
cls.fiber1.account_private,
cls.fiber1.account_private,
self.udtContract,
self.node.rpcUrl,
self.fiber1.account_private,
self.fiber1.account_private,
1000 * 100000000,
)
cls.Miner.miner_until_tx_committed(cls.node, tx_hash)
cls.node.start_miner()
self.Miner.miner_until_tx_committed(self.node, tx_hash)
self.node.start_miner()
# deploy fiber
# start 2 fiber with xudt
update_config = {
"ckb_rpc_url": cls.node.rpcUrl,
"ckb_rpc_url": self.node.rpcUrl,
"ckb_udt_whitelist": True,
"xudt_script_code_hash": cls.Contract.get_ckb_contract_codehash(
deploy_hash, deploy_index, True, cls.node.rpcUrl
"xudt_script_code_hash": self.Contract.get_ckb_contract_codehash(
deploy_hash, deploy_index, True, self.node.rpcUrl
),
"xudt_cell_deps_tx_hash": deploy_hash,
"xudt_cell_deps_index": deploy_index,
}
update_config.update(cls.start_fiber_config)
update_config.update(self.start_fiber_config)

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

cls.fiber2.prepare(update_config=update_config)
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
self.fiber2.prepare(update_config=update_config)
self.fiber2.start(fnn_log_level=self.fnn_log_level)
before_balance1 = self.Ckb_cli.wallet_get_capacity(
self.account1["address"]["testnet"], api_url=self.node.getClient().url
)
cls.logger.debug(f"before_balance1:{before_balance1}")
cls.fiber1.connect_peer(cls.fiber2)
self.logger.debug(f"before_balance1:{before_balance1}")
self.fiber1.connect_peer(self.fiber2)
time.sleep(1)
cls.logger.debug(f"\nSetting up method:{method.__name__}")
self.logger.debug(f"\nSetting up method:{method.__name__}")

def teardown_method(self, method):
if self.debug:
Expand Down Expand Up @@ -440,6 +442,7 @@ def send_invoice_payment(
"invoice": invoice["invoice_address"],
"allow_self_payment": True,
"max_parts": hex(12),
"max_fee_rate": hex(1000000000000000),
}
if "allow_atomic_mpp" in invoice_params:
send_payment_params["amp"] = True
Expand All @@ -454,6 +457,7 @@ def send_invoice_payment(
"invoice": invoice["invoice_address"],
"allow_self_payment": True,
"max_parts": hex(12),
"max_fee_rate": hex(1000000000000000),
}
if "allow_atomic_mpp" in invoice_params:
send_payment_params["amp"] = True
Expand All @@ -472,6 +476,7 @@ def send_payment(self, fiber1, fiber2, amount, wait=True, udt=None, try_count=5)
"keysend": True,
"allow_self_payment": True,
"udt_type_script": udt,
"max_fee_rate": hex(1000000000000000),
# "final_tlc_expiry_delta": hex(120960000),
}
)
Expand All @@ -490,6 +495,7 @@ def send_payment(self, fiber1, fiber2, amount, wait=True, udt=None, try_count=5)
"keysend": True,
"allow_self_payment": True,
"udt_type_script": udt,
"max_fee_rate": hex(1000000000000000),
}
)
if wait:
Expand Down Expand Up @@ -628,6 +634,29 @@ def get_fiber_graph_balance(self):
self.logger.debug(f"{key}:{datas[key]}")
# self.logger.debug(datas[key])

def get_channel_balance_change(self, before_balance, after_balance, key="ckb"):
result = []
# before_balance [
# {'ckb': {'local_balance': 599397400000, 'offered_tlc_balance': 0, 'received_tlc_balance': 0},
# 'chain': {'ckb': 1999997540599995506, 'udt': 100000000000}},
# {'ckb': {'local_balance': 600002600000, 'offered_tlc_balance': 0, 'received_tlc_balance': 0},
# 'chain': {'ckb': 519873044299997458, 'udt': 0}}]

for i in range(len(before_balance)):
result.append(
{
"local_balance": before_balance[i][key]["local_balance"]
- after_balance[i][key]["local_balance"],
"offered_tlc_balance": before_balance[i][key]["offered_tlc_balance"]
- after_balance[i][key]["offered_tlc_balance"],
"received_tlc_balance": before_balance[i][key][
"received_tlc_balance"
]
- after_balance[i][key]["received_tlc_balance"],
}
)
return result

def get_balance_change(self, before_balance, after_balance):
results = []
for i in range(len(before_balance)):
Expand Down Expand Up @@ -1111,11 +1140,11 @@ def get_pending_tlc(self, fiber, payment_hash):
)
for inbounds in tlc_message["Inbound"]:
self.logger.info(
f"inbound tlc amount:{inbounds['amount']}, expiry:{datetime.fromtimestamp(int(inbounds['tlc']['expiry'],16)/1000)}"
f"inbound tlc amount:{inbounds['amount']}, expiry:{datetime.fromtimestamp(int(inbounds['tlc']['expiry'], 16) / 1000)}"
)
for outbounds in tlc_message["Outbound"]:
self.logger.info(
f"outbound tlc amount:{outbounds['amount']}, expiry:{datetime.fromtimestamp(int(outbounds['tlc']['expiry'],16)/1000)}"
f"outbound tlc amount:{outbounds['amount']}, expiry:{datetime.fromtimestamp(int(outbounds['tlc']['expiry'], 16) / 1000)}"
)
return tlc_message

Expand Down
Loading