|
36 | 36 |
|
37 | 37 | import asyncio
|
38 | 38 | import sys
|
| 39 | +import random |
39 | 40 |
|
40 | 41 | class WalletTokens(BitcoinTestFramework):
|
41 | 42 |
|
@@ -145,36 +146,39 @@ async def async_test(self):
|
145 | 146 | self.generate_block()
|
146 | 147 | assert_in("Success", await wallet.sync())
|
147 | 148 |
|
148 |
| - tokens_to_mint = 10000 |
| 149 | + tokens_to_mint = random.randrange(2, 10000) |
149 | 150 | total_tokens_supply = tokens_to_mint
|
150 | 151 | assert_in("The transaction was submitted successfully", await wallet.mint_tokens(token_id, address, tokens_to_mint))
|
151 | 152 |
|
152 | 153 | self.generate_block()
|
153 | 154 | assert_in("Success", await wallet.sync())
|
154 | 155 |
|
155 |
| - assert_in(f"{token_id} amount: {total_tokens_supply}", await wallet.get_balance()) |
156 |
| - |
157 |
| - # cannot unmint more than minted |
158 |
| - assert_in(f"Trying to unmint Amount {{ val: {tokens_to_mint+1}00 }} but the current supply is Amount {{ val: {tokens_to_mint}00 }}", await wallet.unmint_tokens(token_id, tokens_to_mint + 1)) |
159 |
| - |
160 |
| - tokens_to_unmint = 1000 |
161 |
| - total_tokens_supply = total_tokens_supply - tokens_to_unmint |
162 |
| - assert_in("The transaction was submitted successfully", await wallet.unmint_tokens(token_id, tokens_to_unmint)) |
163 |
| - |
164 |
| - self.generate_block() |
165 |
| - assert_in("Success", await wallet.sync()) |
166 |
| - assert_in(f"{token_id} amount: {total_tokens_supply}", await wallet.get_balance()) |
167 |
| - |
168 |
| - # mint some more tokens |
169 |
| - tokens_to_mint = 1000 |
170 |
| - total_tokens_supply = total_tokens_supply + tokens_to_mint |
171 |
| - assert_in("The transaction was submitted successfully", await wallet.mint_tokens(token_id, address, tokens_to_mint)) |
172 |
| - |
173 |
| - self.generate_block() |
174 |
| - assert_in("Success", await wallet.sync()) |
175 |
| - assert_in(f"{token_id} amount: {total_tokens_supply}", await wallet.get_balance()) |
176 |
| - |
177 |
| - # lock token suply |
| 156 | + # randomize minting and unminting |
| 157 | + for _ in range(10): |
| 158 | + if random.choice([True, False]): |
| 159 | + # mint some more tokens |
| 160 | + tokens_to_mint = random.randrange(1, 10000) |
| 161 | + total_tokens_supply = total_tokens_supply + tokens_to_mint |
| 162 | + assert_in("The transaction was submitted successfully", await wallet.mint_tokens(token_id, address, tokens_to_mint)) |
| 163 | + else: |
| 164 | + # unmint some tokens |
| 165 | + tokens_to_unmint = random.randrange(1, 20000) |
| 166 | + if tokens_to_unmint <= total_tokens_supply: |
| 167 | + total_tokens_supply = total_tokens_supply - tokens_to_unmint |
| 168 | + assert_in("The transaction was submitted successfully", await wallet.unmint_tokens(token_id, tokens_to_unmint)) |
| 169 | + else: |
| 170 | + assert_in(f"Trying to unmint Amount {{ val: {tokens_to_unmint}00 }} but the current supply is Amount {{ val: {total_tokens_supply}00 }}", await wallet.unmint_tokens(token_id, tokens_to_unmint)) |
| 171 | + continue |
| 172 | + |
| 173 | + # either generate a new block or leave the transaction as in-memory state |
| 174 | + if random.choice([True, False]): |
| 175 | + self.generate_block() |
| 176 | + assert_in("Success", await wallet.sync()) |
| 177 | + |
| 178 | + # check total supply is correct |
| 179 | + assert_in(f"{token_id} amount: {total_tokens_supply}", await wallet.get_balance(utxo_states=['confirmed', 'inactive'])) |
| 180 | + |
| 181 | + # lock token supply |
178 | 182 | assert_in("The transaction was submitted successfully", await wallet.lock_tokens(token_id))
|
179 | 183 | self.generate_block()
|
180 | 184 | assert_in("Success", await wallet.sync())
|
|
0 commit comments