-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NayNay] Account List Update + Testing (#139)
- created new method to handle listing accounts as a pure function - added unit tests for new method - confirmed manage accounts still works as expected with new method closes #122 Co-authored-by: Nayyir Jutha <nayyir@entropy.xyz>
- Loading branch information
Showing
8 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/flows/manage-accounts/import-key.ts → ...ows/manage-accounts/helpers/import-key.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function listAccounts (config) { | ||
const accountsArray = Array.isArray(config.accounts) ? config.accounts : [config.accounts] | ||
if (!accountsArray.length) | ||
throw new Error( | ||
'There are currently no accounts available, please create or import your new account using the Manage Accounts feature' | ||
) | ||
return accountsArray.map((account) => ({ | ||
name: account.name, | ||
address: account.address, | ||
verifyingKeys: account?.data?.admin?.verifyingKeys | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { EntropyAccountConfig, EntropyConfig } from 'src/types' | ||
import test from 'tape' | ||
import { charlieStashAddress, charlieStashSeed } from './testing-utils/constants' | ||
import { listAccounts } from 'src/flows/manage-accounts/list' | ||
|
||
test('List Accounts', async t => { | ||
const account: EntropyAccountConfig = { | ||
name: 'Test Config', | ||
address: charlieStashAddress, | ||
data: { | ||
seed: charlieStashSeed, | ||
admin: { | ||
verifyingKeys: ['this-is-a-verifying-key'], | ||
seed: charlieStashSeed, | ||
address: charlieStashAddress, | ||
path: '//Charlie' | ||
} | ||
} | ||
} | ||
const config: EntropyConfig = { | ||
accounts: [account], | ||
endpoints: { | ||
dev: 'ws://127.0.0.1:9944', | ||
'test-net': 'wss://testnet.entropy.xyz', | ||
}, | ||
'migration-version': '0' | ||
} | ||
|
||
const accountsArray = listAccounts(config) | ||
|
||
t.deepEqual(accountsArray, [{ | ||
name: account.name, | ||
address: account.address, | ||
verifyingKeys: account.data.admin.verifyingKeys | ||
}]) | ||
|
||
// Resetting accounts on config to test for empty list | ||
config.accounts = [] | ||
try { | ||
listAccounts(config) | ||
} catch (error) { | ||
const msg = error.message | ||
t.equal(msg, 'There are currently no accounts available, please create or import your new account using the Manage Accounts feature') | ||
} | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const charlieStashAddress = | ||
'5Ck5SLSHYac6WFt5UZRSsdJjwmpSZq85fd5TRNAdZQVzEAPT' | ||
|
||
export const charlieStashSeed = | ||
'0x66256c4e2f90e273bf387923a9a7860f2e9f47a1848d6263de512f7fb110fc08' |