Skip to content

Commit 85de415

Browse files
committed
Rename lock tokens and add randomness to functional test
lock_tokens -> lock_token_supply specify a randomseed argument for the functional tests
1 parent b085273 commit 85de415

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

test/functional/test_runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import datetime
3131
import locale
3232
import os
33+
import random
3334
import time
3435
import shutil
3536
import signal
@@ -443,6 +444,7 @@ def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, u
443444
self.num_running = 0
444445
self.jobs = []
445446
self.use_term_control = use_term_control
447+
self.randomseed = random.randrange(sys.maxsize)
446448

447449
def get_next(self):
448450
while self.num_running < self.num_jobs and self.test_list:
@@ -451,14 +453,15 @@ def get_next(self):
451453
test = self.test_list.pop(0)
452454
portseed = len(self.test_list)
453455
portseed_arg = ["--portseed={}".format(portseed)]
456+
randomseed_arg = [f"--randomseed={self.randomseed}"]
454457
log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16)
455458
log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16)
456459
test_argv = test.split()
457460
testdir = "{}/{}_{}".format(self.tmpdir, re.sub(".py$", "", test_argv[0]), portseed)
458461
tmpdir_arg = ["--tmpdir={}".format(testdir)]
459462
self.jobs.append((test,
460463
time.time(),
461-
subprocess.Popen([sys.executable, self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
464+
subprocess.Popen([sys.executable, self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg + randomseed_arg,
462465
universal_newlines=True,
463466
stdout=log_stdout,
464467
stderr=log_stderr),

test/functional/wallet_tokens_change_supply.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import asyncio
3838
import sys
39+
import random
3940

4041
class WalletTokens(BitcoinTestFramework):
4142

@@ -145,7 +146,7 @@ async def async_test(self):
145146
self.generate_block()
146147
assert_in("Success", await wallet.sync())
147148

148-
tokens_to_mint = 10000
149+
tokens_to_mint = random.randrange(2, 10000)
149150
total_tokens_supply = tokens_to_mint
150151
assert_in("The transaction was submitted successfully", await wallet.mint_tokens(token_id, address, tokens_to_mint))
151152

@@ -157,7 +158,7 @@ async def async_test(self):
157158
# cannot unmint more than minted
158159
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))
159160

160-
tokens_to_unmint = 1000
161+
tokens_to_unmint = random.randrange(1, tokens_to_mint // 2)
161162
total_tokens_supply = total_tokens_supply - tokens_to_unmint
162163
assert_in("The transaction was submitted successfully", await wallet.unmint_tokens(token_id, tokens_to_unmint))
163164

@@ -166,15 +167,15 @@ async def async_test(self):
166167
assert_in(f"{token_id} amount: {total_tokens_supply}", await wallet.get_balance())
167168

168169
# mint some more tokens
169-
tokens_to_mint = 1000
170+
tokens_to_mint = random.randrange(1, 10000)
170171
total_tokens_supply = total_tokens_supply + tokens_to_mint
171172
assert_in("The transaction was submitted successfully", await wallet.mint_tokens(token_id, address, tokens_to_mint))
172173

173174
self.generate_block()
174175
assert_in("Success", await wallet.sync())
175176
assert_in(f"{token_id} amount: {total_tokens_supply}", await wallet.get_balance())
176177

177-
# lock token suply
178+
# lock token supply
178179
assert_in("The transaction was submitted successfully", await wallet.lock_tokens(token_id))
179180
self.generate_block()
180181
assert_in("Success", await wallet.sync())

wallet/src/account/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ impl Account {
775775
)
776776
}
777777

778-
pub fn lock_tokens(
778+
pub fn lock_token_supply(
779779
&mut self,
780780
db_tx: &mut impl WalletStorageWriteUnlocked,
781781
token_id: TokenId,

wallet/src/wallet/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl<B: storage::Backend> Wallet<B> {
851851
})
852852
}
853853

854-
pub fn lock_tokens(
854+
pub fn lock_token_supply(
855855
&mut self,
856856
account_index: U31,
857857
token_id: TokenId,
@@ -860,7 +860,7 @@ impl<B: storage::Backend> Wallet<B> {
860860
) -> WalletResult<SignedTransaction> {
861861
let latest_median_time = self.latest_median_time;
862862
self.for_account_rw_unlocked(account_index, |account, db_tx| {
863-
account.lock_tokens(
863+
account.lock_token_supply(
864864
db_tx,
865865
token_id,
866866
latest_median_time,

wallet/src/wallet/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,7 +2716,7 @@ fn change_token_supply_fixed(#[case] seed: Seed) {
27162716
);
27172717

27182718
let err = wallet
2719-
.lock_tokens(
2719+
.lock_token_supply(
27202720
DEFAULT_ACCOUNT_INDEX,
27212721
issued_token_id,
27222722
FeeRate::new(Amount::ZERO),
@@ -2952,7 +2952,7 @@ fn change_token_supply_unlimited(#[case] seed: Seed) {
29522952
);
29532953

29542954
let err = wallet
2955-
.lock_tokens(
2955+
.lock_token_supply(
29562956
DEFAULT_ACCOUNT_INDEX,
29572957
issued_token_id,
29582958
FeeRate::new(Amount::ZERO),
@@ -3183,7 +3183,7 @@ fn change_and_lock_token_supply_lockable(#[case] seed: Seed) {
31833183
assert!(token_issuance_data.total_supply.check_can_lock().is_ok());
31843184

31853185
let lock_transaction = wallet
3186-
.lock_tokens(
3186+
.lock_token_supply(
31873187
DEFAULT_ACCOUNT_INDEX,
31883188
issued_token_id,
31893189
FeeRate::new(Amount::ZERO),
@@ -3249,7 +3249,7 @@ fn change_and_lock_token_supply_lockable(#[case] seed: Seed) {
32493249
assert_eq!(err, WalletError::CannotChangeLockedTokenSupply);
32503250

32513251
let err = wallet
3252-
.lock_tokens(
3252+
.lock_token_supply(
32533253
DEFAULT_ACCOUNT_INDEX,
32543254
issued_token_id,
32553255
FeeRate::new(Amount::ZERO),

wallet/wallet-cli-lib/src/commands/helper_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn to_per_thousand(
238238
variable_name: &str,
239239
) -> Result<PerThousand, WalletCliError> {
240240
PerThousand::from_decimal_str(value_str).ok_or(WalletCliError::InvalidInput(format!(
241-
"Failed to parse {variable_name} the decimal that must be in the range [0.001,1.000] or [0.1%,100%]",
241+
"Failed to parse {variable_name}. The decimal must be in the range [0.001,1.000] or [0.1%,100%]",
242242
)))
243243
}
244244

wallet/wallet-cli-lib/src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl CommandHandler {
891891

892892
self.get_synced_controller()
893893
.await?
894-
.lock_tokens(token_id)
894+
.lock_token_supply(token_id)
895895
.await
896896
.map_err(WalletCliError::Controller)?;
897897

wallet/wallet-controller/src/synced_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ impl<'a, T: NodeInterface, W: WalletEvents> SyncedController<'a, T, W> {
205205
self.broadcast_to_mempool(tx).await
206206
}
207207

208-
pub async fn lock_tokens(&mut self, token_id: TokenId) -> Result<(), ControllerError<T>> {
208+
pub async fn lock_token_supply(&mut self, token_id: TokenId) -> Result<(), ControllerError<T>> {
209209
let (current_fee_rate, consolidate_fee_rate) =
210210
self.get_current_and_consolidation_fee_rate().await?;
211211

212212
let tx = self
213213
.wallet
214-
.lock_tokens(
214+
.lock_token_supply(
215215
self.account_index,
216216
token_id,
217217
current_fee_rate,

0 commit comments

Comments
 (0)