---
# System prepended metadata

title: Force Withdraw Tests
tags: [Tests]

---

---
tags: Tests
---

# Force Withdraw Tests

<h2>Scenario 1: Too Early Force Withdraw</h2></br><p>The following scenario shows a test case where the force withdraw is too early</p></br></br><p>1. The action is that the first delegator calls the behavioral action to force withdraw on the stake for stream 1 at time 4.</p><p>2. Because the current time minus the oldest queue item called at time is less than the grace period, the function terminates with no further actions.</p></br><details><summary><b>Starting State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 5.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details></br><details><summary><b>Ending State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 5.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details><h2>Scenario 2: No Withdraw Queue</h2></br><p>The following scenario shows a test case where there is no withdraw queue so it should not trigger</p></br></br><p>1. The action is that the first delegator calls the behavioral action to force withdraw on the stake for stream 1 at time 4.</p><p>2. Because there are no withdraw queue items, the function terminates.</p></br><details><summary><b>Starting State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 5.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details></br><details><summary><b>Ending State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 5.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details><h2>Scenario 3: Full Payout</h2></br><p>The following scenario shows a test case where the withdraw queue has an overdue payment and it is paid out exactly by the steam.</p></br></br><p>1. The action is that the first delegator calls the behavioral action to force withdraw on the stake for stream 1 at time 10.</p><p>2. Because 10-0 > 7 (grace period), the unstaking takes place.</p><p>3. Stream 1 is completely unstaked from and the withdraw queue is paid off.</p></br><details><summary><b>Starting State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 10.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details></br><details><summary><b>Ending State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 10.0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 10.0, Owner: Broker 1, Stake: {Stream 1: 0, Stream 2: 10}, Withdraw Queue: []]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 0}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 0.0}, Delegator 2: {Broker Pool 1: 10}}]</details><h2>Scenario 4: Full Payout + Early Payout</h2></br><p>The following scenario shows a test case where the withdraw queue has an overdue payment and also one that is not overdue but still gets paid off.</p></br></br><p>1. The action is that the first delegator calls the behavioral action to force withdraw on the stake for stream 1 at time 10.</p><p>2. Because 10-0 > 7 (grace period), the unstaking takes place.</p><p>3. Stream 1 is completely unstaked from and the first withdraw queue item is paid off with 5 DATA.</p><p>4. The second withdraw queue item is also paid off because there is leftover funds.</p></br><details><summary><b>Starting State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 5.0, CALLED_AT: 0), (ID: Delegator 2, AMOUNT: 5.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details></br><details><summary><b>Ending State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 5.0]<br/>[Delegator 2 - Funds: 5.0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 10.0, Owner: Broker 1, Stake: {Stream 1: 0, Stream 2: 10}, Withdraw Queue: []]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 0}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 5.0}, Delegator 2: {Broker Pool 1: 5.0}}]</details><h2>Scenario 5: Full Payout + Extra Leftover</h2></br><p>The following scenario shows a test case where the withdraw queue has an overdue payment and the unstaked funds is greater than needed.</p></br></br><p>1. The action is that the first delegator calls the behavioral action to force withdraw on the stake for stream 1 at time 10.</p><p>2. Because 10-0 > 7 (grace period), the unstaking takes place.</p><p>3. Stream 1 is completely unstaked from and the first withdraw queue item is paid off with 5 DATA.</p><p>4. The leftover 5 funds is released to free funds.</p></br><details><summary><b>Starting State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 0, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 10, Stream 2: 10}, Withdraw Queue: [(ID: Delegator 1, AMOUNT: 5.0, CALLED_AT: 0)]]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 10}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 10}, Delegator 2: {Broker Pool 1: 10}}]</details></br><details><summary><b>Ending State</b></summary><b>Delegators</b><br/>[Delegator 1 - Funds: 5.0]<br/>[Delegator 2 - Funds: 0]<br/><br/><b>Brokers</b><br/>[Broker 1 - Funds: 0]<br/><br/><b>Broker Pools</b><br/>[Broker Pool 1 - Free Funds: 5.0, Pool Value: 15.0, Owner: Broker 1, Stake: {Stream 1: 0, Stream 2: 10}, Withdraw Queue: []]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 0}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 0, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 5.0}, Delegator 2: {Broker Pool 1: 10}}]</details>