Skip to content

Instantly share code, notes, and snippets.

@PokotyloMaryna
Last active September 1, 2023 09:56
Show Gist options
  • Save PokotyloMaryna/911203cf7cdd6085752c6df356b6fc38 to your computer and use it in GitHub Desktop.
Save PokotyloMaryna/911203cf7cdd6085752c6df356b6fc38 to your computer and use it in GitHub Desktop.
State channel test scenarios
# Test 1. Verify Positive Multi-Channel Interaction and Settlement Between Alice and Bob
# Participants: Alice and Bob
# Conditions:
## Alice opens 1 channel with 1 participant;
## Consider Identical trade parameters between 2 participants;
## All settlements execute;
## All participants close their channel succesfully.
participants:
- name: Alice
address: "0xAliceAddress"
privkey: "a11ce00000000000000000000000000000000000000000000000000000000000"
rpc: "https://alice.com"
- name: Bob
address: "0xBobAddress"
privkey: "b0b0000000000000000000000000000000000000000000000000000000000000"
rpc: "https://bob.com"
actions:
t0:
- type: Connect
subsystem: core
participant: Alice
data:
endpoint: "wss://bob.com"
- type: Connect
subsystem: core
participant: Bob
data:
endpoint: "wss://Alice.com"
t1:
- type: OpenChannel
participants:
- Alice
- Bob
deposit: 5000
is_accepted: true
channel_id: alice_bob_1
t2:
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Buy
amount: 0.14
price: 29000.00
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Sell
amount: 0.04
price: 33000.00
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: WETHUSDT
side: Buy
amount: 0.20
price: 1200.00
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: SHIBUSDT
side: Buy
amount: 20000
price: 0.0085
channel_id: alice_bob_1
t3:
- type: PriceUpdate
market: BTCUSDT
price: 31000.00
- type: PriceUpdate
market: ETHUSDT
price: 1001.002
- type: PriceUpdate
market: SHIBUSDT
price: 0.0090
- type: PriceUpdate
market: WETHUSDT
price: 1255.030
t4:
- type: MarginCall
is_accepted: true
channel_id: alice_bob_1
t5:
- type: RequestSettlement
participant: Alice
positions:
- WETHUSDT
- BTCUSDT
- SHIBUSDT
is_accepted: true
channel_id: alice_bob_1
t6:
- type: ExecuteSettlement
channel_id: alice_bob_1
t7:
- type: CloseChannel
channel_id: alice_bob_1
# Test 2. Verify Positive Multi-Channel Interaction and Settlement Between Alice, Bob and Charlie
# Participants: Alice, Bob, Charlie
# Conditions:
## Alice opens 2 channels with 2 participants;
## Consider Identical trade parameters between 2 participants;
## All settlements execute;
## All participants close their channel succesfully.
participants:
- name: Alice
address: "0xAliceAddress"
privkey: "a11ce00000000000000000000000000000000000000000000000000000000000"
rpc: "https://alice.com"
- name: Bob
address: "0xBobAddress"
privkey: "b0b0000000000000000000000000000000000000000000000000000000000000"
rpc: "https://bob.com"
- name: Charlie
address: "0xCharlieAddress"
privkey: "charlie0000000000000000000000000000000000000000000000000000000000000"
rpc: "https://charlie.com"
actions:
t0:
- type: Connect
subsystem: core
participant: Alice
data:
endpoint: "wss://bob.com"
- type: Connect
subsystem: core
participant: Alice
data:
endpoint: "wss://charlie.com"
- type: Connect
subsystem: core
participant: Bob
data:
endpoint: "wss://Alice.com"
- type: Connect
subsystem: core
participant: Charlie
data:
endpoint: "wss://Alice.com"
t1:
- type: OpenChannel
participants:
- Alice
- Bob
deposit: 5000
is_accepted: true
channel_id: alice_bob_1
- type: OpenChannel
subsystem: core
participants:
- Alice
- Charlie
deposit: 5000
is_accepted: true
channel_id: alice_charlie_2
t2:
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Buy
amount: 0.14
price: 29000.00
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Buy
amount: 0.10
price: 29000.00
channel_id: alice_charlie_2
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Sell
amount: 0.04
price: 33000.00
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: WETHUSDT
side: Buy
amount: 0.20
price: 1200.00
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: WETHUSDT
side: Buy
amount: 0.30
price: 1250.020
channel_id: alice_charlie_2
- type: RecordTrade
participant: Alice
market: SHIBUSDT
side: Buy
amount: 20000
price: 0.0085
channel_id: alice_bob_1
- type: RecordTrade
participant: Alice
market: ETHUSDT
side: Buy
amount: 0.20
price: 1000.001
channel_id: alice_charlie_2
t3:
- type: PriceUpdate
market: BTCUSDT
price: 31000.00
- type: PriceUpdate
market: ETHUSDT
price: 1001.002
- type: PriceUpdate
market: SHIBUSDT
price: 0.0090
- type: PriceUpdate
market: WETHUSDT
price: 1255.030
t4:
- type: MarginCall
is_accepted: true
channel_id: alice_charlie_2
- type: MarginCall
is_accepted: true
channel_id: alice_bob_1
t5:
- type: RequestSettlement
participant: Charlie
positions:
- WETHUSDT
- BTCUSDT
- ETHUSDT
is_accepted: true
channel_id: alice_charlie_2
- type: RequestSettlement
participant: Alice
positions:
- WETHUSDT
- BTCUSDT
- SHIBUSDT
is_accepted: true
channel_id: alice_bob_1
t6:
- type: ExecuteSettlement
channel_id: alice_charlie_2
- type: ExecuteSettlement
channel_id: alice_bob_1
t7:
- type: CloseChannel
subsystem: core
channel_id: alice_charlie_2
- type: CloseChannel
subsystem: core
channel_id: alice_bob_1
#Test 4. Verify Unhappy Common Case: Alice's Server Crash, Bob's Channel Challenge and Settlement is not finalized.
#Participants: Alice and Bob
#Condition:
##Alice's server crash;
##Alice's server is answering on margin_calls;
##Bob challenges Alice to retrieve money from the channel as collateral;
##Settlement is started, but never finalized.
participants:
- name: Alice
address: "0xAliceAddress"
privkey: "a11ce00000000000000000000000000000000000000000000000000000000000"
rpc: "https://alice.com"
- name: Bob
address: "0xBobAddress"
privkey: "b0b0000000000000000000000000000000000000000000000000000000000000"
rpc: "https://bob.com"
actions:
t0:
- type: Connect
subsystem: core
participant: Alice
data:
endpoint: "wss://bob.com"
- type: Connect
subsystem: core
participant: Bob
data:
endpoint: "wss://Alice.com"
t1:
- type: OpenChannel
subsystem: core
participants:
- Alice
- Bob
deposit: 5000
is_accepted: true
t2:
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Buy
amount: 0.14
price: 29000.00
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Buy
amount: 0.10
price: 29000.00
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Sell
amount: 0.04
price: 33000.00
- type: RecordTrade
participant: Alice
market: WETHUSDT
side: Buy
amount: 0.20
price: 1200.00
- type: RecordTrade
participant: Alice
market: WETHUSDT
side: Buy
amount: 0.30
price: 1250.00
- type: RecordTrade
participant: Alice
market: SHIBUSDT
side: Buy
amount: 20000
price: 0.0085
t3:
- type: PriceUpdate
market: WETHUSDT
price: 1250.00
t4:
- type: MarginCall
participant: Alice
is_accepted: true
t5:
- type: RequestSettlement
participant: Alice
positions:
- WETHUSDT
- BTCUSDT
- SHIBUSDT
is_accepted: true
t6:
- type: ExecuteSettlement
participant: Alice
is_finalized: false
t7:
- type: Challenge
participant: Bob
is_ignored: true
t8:
- type: CloseChannel
subsystem: core
participant: Bob #Bob closes the channel as Alice lost her connection
# Test 3. Verify Unhappy Common Case: Alice's Server Crash and Bob's Channel Challenge
# Participants: Alice and Bob
# Conditions:
## Alice's server crash;
## Alice's server is not answering on margin_call;
## Bob challenges Alice to retrieve money from the channel as collateral
participants:
- name: Alice
address: "0xAliceAddress"
privkey: "a11ce00000000000000000000000000000000000000000000000000000000000"
rpc: "https://alice.com"
- name: Bob
address: "0xBobAddress"
privkey: "b0b0000000000000000000000000000000000000000000000000000000000000"
rpc: "https://bob.com"
actions:
t0:
- type: Connect
subsystem: core
participant: Alice
data:
endpoint: "wss://bob.com"
- type: Connect
subsystem: core
participant: Bob
data:
endpoint: "wss://Alice.com"
t1:
- type: OpenChannel
subsystem: core
participants:
- Alice
- Bob
deposit: 5000
is_accepted: true
t2:
- type: RecordTrade
participant: Alice
market: BTCUSDT
side: Buy
amount: 0.14
price: 29000.00
t3:
- type: PriceUpdate
market: BTCUSDT
price: 31000.00
t4:
- type: MarginCall
participant: Alice
is_accepted: false
t5:
- type: Challenge
participant: Bob
is_ignored: true
t6:
- type: TransferAllAssets
participant: Bob
t7:
- type: CloseChannel
subsystem: core
participant: Bob #Bob closes the channel as Alice lost her connection
@philanton
Copy link

Also take a look into file format, for example action type should be snake cased and action params should be inside data field.
Here is an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment