From 4d924b0084937afbedc5a3c8aef7d8fe59feced4 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Tue, 29 Aug 2023 13:59:19 +0200 Subject: [PATCH] fix(get_transaction_address_test): add new params to getUpdatedAccountInfo --- test/account_preferences_test.dart | 91 ---------------- test/util/account_preferences_test.dart | 131 ++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 91 deletions(-) delete mode 100644 test/account_preferences_test.dart create mode 100644 test/util/account_preferences_test.dart diff --git a/test/account_preferences_test.dart b/test/account_preferences_test.dart deleted file mode 100644 index 3c2f8b14f..000000000 --- a/test/account_preferences_test.dart +++ /dev/null @@ -1,91 +0,0 @@ -import 'package:my_wit_wallet/shared/api_database.dart'; -import 'package:my_wit_wallet/util/account_preferences.dart'; -import 'package:my_wit_wallet/util/storage/database/account.dart'; -import 'package:test/test.dart'; - -void main() { - Map accountPreferences = - getUpdatedAccountInfo(AccountPreferencesParams('8a7cf20f', { - WalletPreferences.addressIndex: '0/0', - WalletPreferences.addressList: { - '8a7cf20f': '0/0', - } - }, { - 0: Account( - walletName: '8a7cf20f', - address: 'wit000000000000000000000000000000000000000', - path: 'M/3h/4919h/0h/0/1') - })); - // With not existent index saved - Map accountPreferences2 = - getUpdatedAccountInfo(AccountPreferencesParams('8a7cf20f', { - WalletPreferences.addressIndex: '0/2', - WalletPreferences.addressList: { - '8a7cf20f': '0/2', - } - }, { - 0: Account( - walletName: '8a7cf20f', - address: 'wit000000000000000000000000000000000000000', - path: 'M/3h/4919h/0h/0/1') - })); - // With db deleted - Map accountPreferences3 = - getUpdatedAccountInfo(AccountPreferencesParams('8a7cf20f', { - WalletPreferences.addressIndex: '0/2', - WalletPreferences.addressList: { - '8a7cf20f': '0/2', - } - }, {})); - // With deleted prefs - Map accountPreferences4 = - getUpdatedAccountInfo(AccountPreferencesParams('8a7cf20f', null, { - 0: Account( - walletName: '8a7cf20f', - address: 'wit000000000000000000000000000000000000000', - path: 'M/3h/4919h/0h/0/1') - })); - group( - 'getAccountPreferences', - () => { - test( - 'with correctly saved preferences', - () => { - expect(accountPreferences, { - AccountPreferences.address: - 'wit000000000000000000000000000000000000000', - AccountPreferences.addressIndex: '0', - AccountPreferences.addressList: {'8a7cf20f': '0/0'} - }), - }), - test( - 'with not found address index in saved preferences', - () => { - expect(accountPreferences2, { - AccountPreferences.address: - 'wit000000000000000000000000000000000000000', - AccountPreferences.addressIndex: '0', - AccountPreferences.addressList: {'8a7cf20f': '0/0'} - }), - }), - test( - 'with deleted db and saved preferences', - () => { - expect(accountPreferences3, { - AccountPreferences.address: null, - AccountPreferences.addressIndex: '0', - AccountPreferences.addressList: {'8a7cf20f': '0/0'}, - }), - }), - test( - 'with deleted preferences and saved db', - () => { - expect(accountPreferences4, { - AccountPreferences.address: - 'wit000000000000000000000000000000000000000', - AccountPreferences.addressIndex: '0', - AccountPreferences.addressList: {'8a7cf20f': '0/0'}, - }), - }), - }); -} diff --git a/test/util/account_preferences_test.dart b/test/util/account_preferences_test.dart new file mode 100644 index 000000000..71b6be44a --- /dev/null +++ b/test/util/account_preferences_test.dart @@ -0,0 +1,131 @@ +import 'package:my_wit_wallet/shared/api_database.dart'; +import 'package:my_wit_wallet/util/account_preferences.dart'; +import 'package:my_wit_wallet/util/storage/database/account.dart'; +import 'package:test/test.dart'; + +void main() { + Map accountPreferences = getUpdatedAccountInfo( + AccountPreferencesParams( + currentWalletId: '8a7cf20f', + preferences: { + WalletPreferences.addressIndex: '0/0', + WalletPreferences.addressList: { + '8a7cf20f': '0/0', + } + }, + accountList: { + 0: Account( + walletName: '8a7cf20f', + address: 'wit000000000000000000000000000000000000000', + path: 'M/3h/4919h/0h/0/1') + }, + isHdWallet: true), + ); + // With not existent index saved + Map accountPreferences2 = + getUpdatedAccountInfo(AccountPreferencesParams( + currentWalletId: '8a7cf20f', + preferences: { + WalletPreferences.addressIndex: '0/2', + WalletPreferences.addressList: { + '8a7cf20f': '0/2', + } + }, + accountList: { + 0: Account( + walletName: '8a7cf20f', + address: 'wit000000000000000000000000000000000000000', + path: 'M/3h/4919h/0h/0/1') + }, + isHdWallet: true)); + // With db deleted + Map accountPreferences3 = + getUpdatedAccountInfo(AccountPreferencesParams( + currentWalletId: '8a7cf20f', + preferences: { + WalletPreferences.addressIndex: '0/2', + WalletPreferences.addressList: { + '8a7cf20f': '0/2', + } + }, + accountList: {}, + isHdWallet: true)); + // With deleted prefs + Map accountPreferences4 = + getUpdatedAccountInfo(AccountPreferencesParams( + currentWalletId: '8a7cf20f', + preferences: null, + accountList: { + 0: Account( + walletName: '8a7cf20f', + address: 'wit000000000000000000000000000000000000000', + path: 'M/3h/4919h/0h/0/1') + }, + isHdWallet: true)); + Map accountPreferences5 = + getUpdatedAccountInfo(AccountPreferencesParams( + currentWalletId: '8a7cf20f', + preferences: null, + accountList: { + 0: Account( + walletName: '8a7cf20f', + address: 'wit000000000000000000000000000000000000000', + path: 'M/3h/4919h/0h/0/1') + }, + isHdWallet: false)); + group( + 'getAccountPreferences', + () => { + test( + 'with correctly saved preferences', + () => { + expect(accountPreferences, { + AccountPreferences.address: + 'wit000000000000000000000000000000000000000', + AccountPreferences.addressIndex: '0', + AccountPreferences.addressList: {'8a7cf20f': '0/0'} + }), + }), + test( + 'with not found address index in saved preferences', + () => { + expect(accountPreferences2, { + AccountPreferences.address: + 'wit000000000000000000000000000000000000000', + AccountPreferences.addressIndex: '0', + AccountPreferences.addressList: {'8a7cf20f': '0/0'} + }), + }), + test( + 'with deleted db and saved preferences', + () => { + expect(accountPreferences3, { + AccountPreferences.address: null, + AccountPreferences.addressIndex: '0', + AccountPreferences.addressList: { + '8a7cf20f': '0/0', + }, + }), + }), + test( + 'with deleted preferences and saved db', + () => { + expect(accountPreferences4, { + AccountPreferences.address: + 'wit000000000000000000000000000000000000000', + AccountPreferences.addressIndex: '0', + AccountPreferences.addressList: {'8a7cf20f': '0/0'}, + }), + }), + test( + 'with deleted preferences and saved db with node address', + () => { + expect(accountPreferences5, { + AccountPreferences.address: + 'wit000000000000000000000000000000000000000', + AccountPreferences.addressIndex: '0', + AccountPreferences.addressList: {'8a7cf20f': 'm'}, + }), + }), + }); +}