Skip to content

Commit bba107a

Browse files
Oneway channel (#17)
* send payment failed if oneway * del test_accept_channel.py * formate code * add p0 testcases for trampoline * update test_trampoline_invoice_success cases * wait dev fix * add p0 p1 case * add algo invoice * trampoline_hops Vec<pubkey> * Gp/1102 (#18) * add one way test * remove testnet case * update ci * support one way * fix ci err * fix ci * remove skil test_ckb_with_udt * fix ci * fix test_tlc_fee_proportional_millionths_max * fix ci * fix ci * add wasm test * fix ci err test_max_trampoline_hops * format code * add one way test * format code * Update test_mpp.py * update compatibility ci * update settle invoice * v0.7.0 * update test --------- Co-authored-by: gpBlockchain <32102187+gpBlockchain@users.noreply.github.com> Co-authored-by: gpBlockchain <744158715@qq.com>
1 parent 4684973 commit bba107a

40 files changed

Lines changed: 4532 additions & 246 deletions

.github/workflows/fiber.yml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ jobs:
417417
run: |
418418
git clone https://github.com/gpBlockchain/fiber-wasm-demo.git
419419
cd fiber-wasm-demo
420-
git checkout new_contract
421420
bash prepare.sh
422421
cd ../
423422
env:
@@ -544,3 +543,75 @@ jobs:
544543
name: jfoa-fiber_test_send_payment_debug_mixed-reports-${{ runner.os }}
545544
path: ./report
546545

546+
fiber_test_trampoline_routing_one_way:
547+
needs: prepare
548+
runs-on: ubuntu-22.04
549+
550+
steps:
551+
- uses: actions/checkout@v3
552+
- name: Set up Python 3.12
553+
uses: actions/setup-python@v3
554+
with:
555+
python-version: "3.12"
556+
557+
- name: Install dependencies
558+
run: |
559+
python -m pip install --upgrade pip
560+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
561+
562+
- name: Download prepare backup
563+
uses: actions/download-artifact@v4
564+
with:
565+
name: prepare-backup-${{ runner.os }}
566+
path: ./
567+
568+
- name: Extract tarball and restore permissions
569+
run: |
570+
tar -xzf prepare-backup.tar.gz
571+
572+
- name: Run fiber_test_demo
573+
run: make fiber_test_demo FIBER_TEST_DEMO="test_cases/fiber/devnet/one_way test_cases/fiber/devnet/trampoline_routing"
574+
575+
- name: Publish reports
576+
if: failure()
577+
uses: actions/upload-artifact@v4
578+
with:
579+
name: jfoa-fiber_test_send_payment_debug_mixed-reports-${{ runner.os }}
580+
path: ./report
581+
582+
fiber_test_compatibility:
583+
needs: prepare
584+
runs-on: ubuntu-22.04
585+
586+
steps:
587+
- uses: actions/checkout@v3
588+
- name: Set up Python 3.12
589+
uses: actions/setup-python@v3
590+
with:
591+
python-version: "3.12"
592+
593+
- name: Install dependencies
594+
run: |
595+
python -m pip install --upgrade pip
596+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
597+
598+
- name: Download prepare backup
599+
uses: actions/download-artifact@v4
600+
with:
601+
name: prepare-backup-${{ runner.os }}
602+
path: ./
603+
604+
- name: Extract tarball and restore permissions
605+
run: |
606+
tar -xzf prepare-backup.tar.gz
607+
608+
- name: Run fiber_test_demo
609+
run: make fiber_test_demo FIBER_TEST_DEMO="test_cases/fiber/devnet/compatibility"
610+
611+
- name: Publish reports
612+
if: failure()
613+
uses: actions/upload-artifact@v4
614+
with:
615+
name: jfoa-fiber_test_send_payment_debug_mixed-reports-${{ runner.os }}
616+
path: ./report
617+

download_fiber.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
versions = [
1515
"0.6.0",
1616
"0.6.1",
17+
"0.7.0",
1718
]
1819

1920
DOWNLOAD_DIR = "download/fiber"

framework/basic_fiber.py

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FiberTest(CkbTest):
3535
start_fiber_config = {}
3636
fnn_log_level = "debug"
3737
beginNum = "0x0"
38+
node: CkbTest.CkbNode
3839

3940
@classmethod
4041
def setup_class(cls):
@@ -74,7 +75,7 @@ def setup_class(cls):
7475
cls.node.start()
7576
cls.node.getClient().get_consensus()
7677

77-
def setup_method(cls, method):
78+
def setup_method(self, method):
7879
"""
7980
启动2个fiber
8081
给 fiber1 充值udt 金额
@@ -85,71 +86,72 @@ def setup_method(cls, method):
8586
Returns:
8687
8788
"""
88-
cls.did_pass = None
89-
cls.beginNum = hex(cls.node.getClient().get_tip_block_number())
90-
cls.fibers = []
91-
cls.new_fibers = []
92-
cls.fiber1 = Fiber.init_by_port(
93-
cls.fiber_version,
94-
cls.account1_private_key,
89+
print("setup_method")
90+
self.did_pass = None
91+
self.beginNum = hex(self.node.getClient().get_tip_block_number())
92+
self.fibers = []
93+
self.new_fibers = []
94+
self.fiber1 = Fiber.init_by_port(
95+
self.fiber_version,
96+
self.account1_private_key,
9597
"fiber/node1",
9698
"8228",
9799
"8227",
98100
)
99-
cls.fiber2 = Fiber.init_by_port(
100-
cls.fiber_version,
101-
cls.account2_private_key,
101+
self.fiber2 = Fiber.init_by_port(
102+
self.fiber_version,
103+
self.account2_private_key,
102104
"fiber/node2",
103105
"8229",
104106
"8230",
105107
)
106-
cls.fibers.append(cls.fiber1)
107-
cls.fibers.append(cls.fiber2)
108+
self.fibers.append(self.fiber1)
109+
self.fibers.append(self.fiber2)
108110
#
109-
cls.udtContract = UdtContract(XUDT_TX_HASH, 0)
111+
self.udtContract = UdtContract(XUDT_TX_HASH, 0)
110112
#
111-
deploy_hash, deploy_index = cls.udtContract.get_deploy_hash_and_index()
113+
deploy_hash, deploy_index = self.udtContract.get_deploy_hash_and_index()
112114

113-
if cls.debug:
115+
if self.debug:
114116
return
115117
# # issue
116-
cls.node.getClient().clear_tx_pool()
118+
self.node.getClient().clear_tx_pool()
117119
for i in range(5):
118-
cls.Miner.miner_with_version(cls.node, "0x0")
120+
self.Miner.miner_with_version(self.node, "0x0")
119121
tx_hash = issue_udt_tx(
120-
cls.udtContract,
121-
cls.node.rpcUrl,
122-
cls.fiber1.account_private,
123-
cls.fiber1.account_private,
122+
self.udtContract,
123+
self.node.rpcUrl,
124+
self.fiber1.account_private,
125+
self.fiber1.account_private,
124126
1000 * 100000000,
125127
)
126-
cls.Miner.miner_until_tx_committed(cls.node, tx_hash)
127-
cls.node.start_miner()
128+
self.Miner.miner_until_tx_committed(self.node, tx_hash)
129+
self.node.start_miner()
128130
# deploy fiber
129131
# start 2 fiber with xudt
130132
update_config = {
131-
"ckb_rpc_url": cls.node.rpcUrl,
133+
"ckb_rpc_url": self.node.rpcUrl,
132134
"ckb_udt_whitelist": True,
133-
"xudt_script_code_hash": cls.Contract.get_ckb_contract_codehash(
134-
deploy_hash, deploy_index, True, cls.node.rpcUrl
135+
"xudt_script_code_hash": self.Contract.get_ckb_contract_codehash(
136+
deploy_hash, deploy_index, True, self.node.rpcUrl
135137
),
136138
"xudt_cell_deps_tx_hash": deploy_hash,
137139
"xudt_cell_deps_index": deploy_index,
138140
}
139-
update_config.update(cls.start_fiber_config)
141+
update_config.update(self.start_fiber_config)
140142

141-
cls.fiber1.prepare(update_config=update_config)
142-
cls.fiber1.start(fnn_log_level=cls.fnn_log_level)
143+
self.fiber1.prepare(update_config=update_config)
144+
self.fiber1.start(fnn_log_level=self.fnn_log_level)
143145

144-
cls.fiber2.prepare(update_config=update_config)
145-
cls.fiber2.start(fnn_log_level=cls.fnn_log_level)
146-
before_balance1 = cls.Ckb_cli.wallet_get_capacity(
147-
cls.account1["address"]["testnet"], api_url=cls.node.getClient().url
146+
self.fiber2.prepare(update_config=update_config)
147+
self.fiber2.start(fnn_log_level=self.fnn_log_level)
148+
before_balance1 = self.Ckb_cli.wallet_get_capacity(
149+
self.account1["address"]["testnet"], api_url=self.node.getClient().url
148150
)
149-
cls.logger.debug(f"before_balance1:{before_balance1}")
150-
cls.fiber1.connect_peer(cls.fiber2)
151+
self.logger.debug(f"before_balance1:{before_balance1}")
152+
self.fiber1.connect_peer(self.fiber2)
151153
time.sleep(1)
152-
cls.logger.debug(f"\nSetting up method:{method.__name__}")
154+
self.logger.debug(f"\nSetting up method:{method.__name__}")
153155

154156
def teardown_method(self, method):
155157
if self.debug:
@@ -440,6 +442,7 @@ def send_invoice_payment(
440442
"invoice": invoice["invoice_address"],
441443
"allow_self_payment": True,
442444
"max_parts": hex(12),
445+
"max_fee_rate": hex(1000000000000000),
443446
}
444447
if "allow_atomic_mpp" in invoice_params:
445448
send_payment_params["amp"] = True
@@ -454,6 +457,7 @@ def send_invoice_payment(
454457
"invoice": invoice["invoice_address"],
455458
"allow_self_payment": True,
456459
"max_parts": hex(12),
460+
"max_fee_rate": hex(1000000000000000),
457461
}
458462
if "allow_atomic_mpp" in invoice_params:
459463
send_payment_params["amp"] = True
@@ -472,6 +476,7 @@ def send_payment(self, fiber1, fiber2, amount, wait=True, udt=None, try_count=5)
472476
"keysend": True,
473477
"allow_self_payment": True,
474478
"udt_type_script": udt,
479+
"max_fee_rate": hex(1000000000000000),
475480
# "final_tlc_expiry_delta": hex(120960000),
476481
}
477482
)
@@ -490,6 +495,7 @@ def send_payment(self, fiber1, fiber2, amount, wait=True, udt=None, try_count=5)
490495
"keysend": True,
491496
"allow_self_payment": True,
492497
"udt_type_script": udt,
498+
"max_fee_rate": hex(1000000000000000),
493499
}
494500
)
495501
if wait:
@@ -628,6 +634,29 @@ def get_fiber_graph_balance(self):
628634
self.logger.debug(f"{key}:{datas[key]}")
629635
# self.logger.debug(datas[key])
630636

637+
def get_channel_balance_change(self, before_balance, after_balance, key="ckb"):
638+
result = []
639+
# before_balance [
640+
# {'ckb': {'local_balance': 599397400000, 'offered_tlc_balance': 0, 'received_tlc_balance': 0},
641+
# 'chain': {'ckb': 1999997540599995506, 'udt': 100000000000}},
642+
# {'ckb': {'local_balance': 600002600000, 'offered_tlc_balance': 0, 'received_tlc_balance': 0},
643+
# 'chain': {'ckb': 519873044299997458, 'udt': 0}}]
644+
645+
for i in range(len(before_balance)):
646+
result.append(
647+
{
648+
"local_balance": before_balance[i][key]["local_balance"]
649+
- after_balance[i][key]["local_balance"],
650+
"offered_tlc_balance": before_balance[i][key]["offered_tlc_balance"]
651+
- after_balance[i][key]["offered_tlc_balance"],
652+
"received_tlc_balance": before_balance[i][key][
653+
"received_tlc_balance"
654+
]
655+
- after_balance[i][key]["received_tlc_balance"],
656+
}
657+
)
658+
return result
659+
631660
def get_balance_change(self, before_balance, after_balance):
632661
results = []
633662
for i in range(len(before_balance)):
@@ -1111,11 +1140,11 @@ def get_pending_tlc(self, fiber, payment_hash):
11111140
)
11121141
for inbounds in tlc_message["Inbound"]:
11131142
self.logger.info(
1114-
f"inbound tlc amount:{inbounds['amount']}, expiry:{datetime.fromtimestamp(int(inbounds['tlc']['expiry'],16)/1000)}"
1143+
f"inbound tlc amount:{inbounds['amount']}, expiry:{datetime.fromtimestamp(int(inbounds['tlc']['expiry'], 16) / 1000)}"
11151144
)
11161145
for outbounds in tlc_message["Outbound"]:
11171146
self.logger.info(
1118-
f"outbound tlc amount:{outbounds['amount']}, expiry:{datetime.fromtimestamp(int(outbounds['tlc']['expiry'],16)/1000)}"
1147+
f"outbound tlc amount:{outbounds['amount']}, expiry:{datetime.fromtimestamp(int(outbounds['tlc']['expiry'], 16) / 1000)}"
11191148
)
11201149
return tlc_message
11211150

0 commit comments

Comments
 (0)