---
# System prepended metadata

title: Withdraw Queue Tests
tags: [Tests]

---

---
tags: Tests
---

# Withdraw Queue Tests

<h2>Scenario 1: Only Withdraw Queue</h2></br><p>The following scenario shows a test case where there are no free funds leads to a creation of a withdraw queue object only.</p></br></br><p>The action is that the first delegator calls the behavioral action to withdraw all 10 of their tokens. This ends up creating a 10 token withdraw queue item because none of it can be paid out.</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: []]<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: 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><h2>Scenario 2: Half Withdraw Queue Half Immediate Withdraw</h2></br><p>The following scenario shows a test case where there are some free funds but no enough to cover the entire withdrawal so a withdraw queue item is still created.</p></br></br><p>1. The first delegator withdraws 10 tokens.</p><p>2. The amount of DATA needed to pay off the entire 10 tokens is 10, but the free funds is only 5.</p><p>3. The 5 DATA is paid out to the internal balance for delegator 1. The pool value and free funds both decrease by 5. The delegator 1 token balance goes to 5.</p><p>4. A withdraw queue item is added for the remaining 5.</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: 5, Pool Value: 20, Owner: Broker 1, Stake: {Stream 1: 5, Stream 2: 10}, Withdraw Queue: []]<br/><br/><b>Streams</b><br/>[Stream 1 - Stake: {Broker Pool 1: 5}]<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: 15, Owner: Broker 1, Stake: {Stream 1: 5, 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: 5}]<br/>[Stream 2 - Stake: {Broker Pool 1: 10}]<br/><br/><b>Vault</b><br/>[Vault - Internal Balances: {Delegator 1: 5, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 5.0}, Delegator 2: {Broker Pool 1: 10}}]</details><h2>Scenario 3: Full Immediate Payout</h2></br><p>The following scenario shows a test case where there are enough free funds to completely pay off a delegator withdraw.</p></br></br><p>1. The first delegator withdraws 10 tokens.</p><p>2. The amount of DATA needed to pay off the entire 10 tokens is 10, and free funds is 10.</p><p>3. The 10 DATA is paid out to the internal balance for delegator 1. The pool value and free funds both decrease by 10. The delegator 1 token balance goes to 0. </p><p>4. A withdraw queue item is added for the remaining 5.</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: 10, Pool Value: 20, 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: 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: 10, 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: 10, Delegator 2: 0}, Token Balances: {Delegator 1: {Broker Pool 1: 0.0}, Delegator 2: {Broker Pool 1: 10}}]</details>