Skip to content

Commit 76f3f45

Browse files
committed
add firber test
1 parent af653a4 commit 76f3f45

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import time
2+
3+
import pytest
4+
5+
from framework.basic_fiber import FiberTest
6+
7+
8+
class TestAcceptMutilChannelsSameTime(FiberTest):
9+
# FiberTest.debug = True
10+
11+
def test_accept_chanel_same_channel_same_time(self):
12+
"""
13+
accept_channel: Accept the same channel multiple times at the same time
14+
15+
1. Open a new channel with fiber1 as the client and fiber2 as the peer
16+
2. Accept the channel with fiber2 as the client
17+
3. Attempt to accept the same channel again, expecting an exception
18+
4. Verify that the expected error message is in the exception
19+
5. Wait for the channel state to be "CHANNEL_READY"
20+
21+
Returns:
22+
"""
23+
# 1. Open a new channel with fiber1 as the client and fiber2 as the peer
24+
temporary_channel = self.fiber1.get_client().open_channel(
25+
{
26+
"peer_id": self.fiber2.get_peer_id(),
27+
"funding_amount": hex(62 * 100000000),
28+
"public": True,
29+
}
30+
)
31+
time.sleep(1)
32+
33+
# 2. Accept the channel with fiber2 as the client
34+
self.fiber2.get_client().accept_channel(
35+
{
36+
"temporary_channel_id": temporary_channel["temporary_channel_id"],
37+
"funding_amount": hex(200000 * 100000000),
38+
}
39+
)
40+
41+
# 3. Attempt to accept the same channel again, expecting an exception
42+
with pytest.raises(Exception) as exc_info:
43+
self.fiber2.get_client().accept_channel(
44+
{
45+
"temporary_channel_id": temporary_channel["temporary_channel_id"],
46+
"funding_amount": hex(200000 * 100000000),
47+
}
48+
)
49+
50+
# 4. Verify that the expected error message is in the exception
51+
expected_error_message = "No channel with temp id"
52+
assert expected_error_message in exc_info.value.args[0], (
53+
f"Expected substring '{expected_error_message}' "
54+
f"not found in actual string '{exc_info.value.args[0]}'"
55+
)
56+
57+
# 5. Wait for the channel state to be "CHANNEL_READY"
58+
self.wait_for_channel_state(
59+
self.fiber2.get_client(), self.fiber1.get_peer_id(), "CHANNEL_READY"
60+
)
61+
62+
def test_accept_channel_diff_channel_same_time(self):
63+
"""
64+
accept channel: Accept multiple different channels at the same time
65+
Steps:
66+
1. Generate a new account with 1000 units of balance
67+
2. Start a new fiber with the generated account
68+
3. Connect fiber3 to fiber2
69+
4. Open a new channel with fiber1 as the client and fiber2 as the peer
70+
5. Open another new channel with fiber3 as the client and fiber2 as the peer
71+
6. Accept the first channel with fiber2 as the client
72+
7. Accept the second channel with fiber2 as the client
73+
8. Wait for the first channel state to be "CHANNEL_READY"
74+
9. Wait for the second channel state to be "AWAITING_TX_SIGNATURES"
75+
10. Open another new channel with fiber3 as the client and fiber2 as the peer
76+
11. Accept the new channel with fiber2 as the client
77+
12. Wait for the new channel state to be "CHANNEL_READY"
78+
79+
Returns:
80+
"""
81+
# Step 1: Generate a new account with 1000 units of balance
82+
account3 = self.generate_account(1000)
83+
84+
# Step 2: Start a new fiber with the generated account
85+
fiber3 = self.start_new_fiber(account3)
86+
87+
# Step 3: Connect fiber3 to fiber2
88+
fiber3.connect_peer(self.fiber2)
89+
time.sleep(1)
90+
91+
# Step 4: Open a new channel with fiber1 as the client and fiber2 as the peer
92+
temporary_channel1 = self.fiber1.get_client().open_channel(
93+
{
94+
"peer_id": self.fiber2.get_peer_id(),
95+
"funding_amount": hex(63 * 100000000),
96+
"public": True,
97+
}
98+
)
99+
100+
# Step 5: Open another new channel with fiber3 as the client and fiber2 as the peer
101+
temporary_channel2 = fiber3.get_client().open_channel(
102+
{
103+
"peer_id": self.fiber2.get_peer_id(),
104+
"funding_amount": hex(63 * 100000000),
105+
"public": True,
106+
}
107+
)
108+
time.sleep(1)
109+
110+
# Step 6: Accept the first channel with fiber2 as the client
111+
self.fiber2.get_client().accept_channel(
112+
{
113+
"temporary_channel_id": temporary_channel1["temporary_channel_id"],
114+
"funding_amount": hex(62 * 100000000),
115+
}
116+
)
117+
time.sleep(0.1)
118+
119+
# Step 7: Accept the second channel with fiber2 as the client
120+
self.fiber2.get_client().accept_channel(
121+
{
122+
"temporary_channel_id": temporary_channel2["temporary_channel_id"],
123+
"funding_amount": hex(62 * 100000000),
124+
}
125+
)
126+
127+
# Step 8: Wait for the first channel state to be "CHANNEL_READY"
128+
self.wait_for_channel_state(
129+
self.fiber1.get_client(), self.fiber2.get_peer_id(), "CHANNEL_READY"
130+
)
131+
132+
# Step 9: Wait for the second channel state to be "AWAITING_TX_SIGNATURES"
133+
self.wait_for_channel_state(
134+
self.fiber2.get_client(), fiber3.get_peer_id(), "AWAITING_TX_SIGNATURES"
135+
)
136+
137+
time.sleep(5)
138+
139+
# Step 10: Open another new channel with fiber3 as the client and fiber2 as the peer
140+
temporary_channel2 = fiber3.get_client().open_channel(
141+
{
142+
"peer_id": self.fiber2.get_peer_id(),
143+
"funding_amount": hex(63 * 100000000),
144+
"public": True,
145+
}
146+
)
147+
time.sleep(1)
148+
149+
# Step 11: Accept the new channel with fiber2 as the client
150+
self.fiber2.get_client().accept_channel(
151+
{
152+
"temporary_channel_id": temporary_channel2["temporary_channel_id"],
153+
"funding_amount": hex(62 * 100000000),
154+
}
155+
)
156+
157+
# Step 12: Wait for the new channel state to be "CHANNEL_READY"
158+
self.wait_for_channel_state(
159+
self.fiber2.get_client(), fiber3.get_peer_id(), "CHANNEL_READY"
160+
)

0 commit comments

Comments
 (0)