Creating a scenario for multiple Users (instead of just single User, multiple accounts)#33
Creating a scenario for multiple Users (instead of just single User, multiple accounts)#33vivek-arte wants to merge 1 commit into
Conversation
vivek-arte
left a comment
There was a problem hiding this comment.
Added some comments where suggestions would be welcome.
Also, there is a User::address_for_account method to generate a new address -- if we want to support multiple Users and multiple accounts, I can see it being useful to have a way of querying how many accounts have been generated by a User. Is there a reason against having such a function?
| TestBalances(balances) | ||
| } | ||
|
|
||
| pub(crate) fn get_asset_balances_multi_user( |
There was a problem hiding this comment.
I could make this function work without num_users, since I can get it from wallets.length().
| asset: AssetBase, | ||
| expected_balances: &TestBalances, | ||
| wallets: &mut [&mut User], | ||
| num_users: usize, |
There was a problem hiding this comment.
Again here, could get rid of num_users as above.
| let from_addr = wallets[self.acc_idx_from].address_for_account(0, External); | ||
| let to_addr = wallets[self.acc_idx_to].address_for_account(0, External); |
There was a problem hiding this comment.
Note that I have multiple Users, but I am using "account" 0 for them all. I don't support multiple accounts per User at the moment.
| let mut manufacturer = User::random(&config.wallet.miner_seed_phrase); | ||
| let mut purchaser = User::random(&config.wallet.miner_seed_phrase); | ||
| let mut supplier = User::random(&config.wallet.miner_seed_phrase); | ||
| let mut miner = User::random(&config.wallet.miner_seed_phrase); | ||
|
|
||
| manufacturer.reset(); | ||
| purchaser.reset(); | ||
| supplier.reset(); | ||
| miner.reset(); | ||
|
|
||
| let manufacturer_addr = manufacturer.address_for_account(0, External); | ||
|
|
||
| let mut wallets = [&mut manufacturer, &mut purchaser, &mut supplier, &mut miner]; | ||
| let manufacturer_idx = 0; | ||
| let purchaser_idx = 1; | ||
| let supplier_idx = 2; | ||
| let miner_idx = 3; |
There was a problem hiding this comment.
There is a lot of repetition here, could be improved, but as an initial proof-of-concept that it works I didn't get into it yet.
This PR prepares the same three party scenario present in
test_three_party, but does it by using multiple Users, rather than a single User with multiple accounts.This is done in a backward-compatible manner, via the addition of extra supporting structure that does not break any of the existing code.