-
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.
* config schema - initial tests, json schema * isValidConfig: tests + passing * plug isValidConfig into assertConfig * plug assertConfig into config.init * fix tests: config.set * split config tests into files * config migration 5 - fix selectedAccount * rm test.only * fix config.set test post-migration * add globstar to support recurssive test search * fix migration 5 (code + tests) * new account setting selected account incorrectly, now fixed --------- Co-authored-by: Nayyir Jutha <[email protected]>
- Loading branch information
Showing
12 changed files
with
808 additions
and
156 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
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
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,39 @@ | ||
// The purpose of this migration is to: | ||
// 1. change encoding of empty selectedAccount from "" => null | ||
// 2. ensure selectedAccount present is an account.name | ||
|
||
export const version = 5 | ||
|
||
export function migrate (data) { | ||
try { | ||
const newData = { ...data } | ||
|
||
if (newData.selectedAccount === null) { | ||
// nothing to do | ||
} | ||
else if (newData.selectedAccount === "") { | ||
newData.selectedAccount = null | ||
} | ||
else { | ||
const target = newData.selectedAccount | ||
const accountMatchingName = newData.accounts.find(a => a.name === target) | ||
const accountMatchingAddress = newData.accounts.find(a => a.address === target) | ||
|
||
if (accountMatchingName) { | ||
// nothing to do | ||
} | ||
else if (accountMatchingAddress) { | ||
// change the refference to be the account.name | ||
newData.selectedAccount = accountMatchingAddress.name | ||
} | ||
else { | ||
throw Error(`unable to correct selectedAccount - no account found which matches "${target}"`) | ||
} | ||
} | ||
return newData | ||
} catch (err) { | ||
// @ts-expect-error : ts stupid | ||
throw Error('Migration 5 failed', { cause: err }) | ||
} | ||
|
||
} |
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,69 @@ | ||
import migrations from './migrations' | ||
|
||
const currentVersion = migrations.at(-1).version | ||
|
||
const accountSchema = { | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: "string" | ||
}, | ||
address: { | ||
type: "string", | ||
pattern: [ | ||
"^[", | ||
"a-k", /* l, */ "m-z", | ||
"A-H", /* I, */ "J-N", /* O, */ "P-Z", | ||
/* 0 */ "1-9", | ||
"]{48,48}$" | ||
].join("") | ||
// base58: https://en.wikipedia.org/wiki/Binary-to-text_encoding#Encoding_standards | ||
// | ||
// Similar to Base64, but modified to avoid both non-alphanumeric characters (+ and /) and letters | ||
// that might look ambiguous when printed (0 – zero, I – capital i, O – capital o and l – lower-case L). | ||
}, | ||
data: { | ||
type: "object", | ||
properties: { | ||
admin: { type: "object" }, | ||
registration: { type: "object" } | ||
}, | ||
required: ["admin", "registration"] | ||
} | ||
}, | ||
required: ["name", "address", "data"] | ||
} | ||
|
||
export const configSchema = { | ||
type: "object", | ||
properties: { | ||
accounts: { | ||
type: "array", | ||
items: accountSchema, | ||
uniqueItems: true | ||
}, | ||
selectedAccount: { | ||
oneOf: [ | ||
{ type: "null" }, | ||
{ type: "string" } | ||
] | ||
}, | ||
endpoints: { | ||
type: "object", | ||
patternProperties: { | ||
"^\\w+$": { | ||
type: "string", | ||
pattern: "^wss?://" | ||
}, | ||
}, | ||
required: ["test-net"] | ||
}, | ||
"migration-version": { | ||
type: "integer", | ||
minimum: currentVersion, | ||
maximum: currentVersion | ||
} | ||
}, | ||
required: ["accounts", "selectedAccount", "endpoints", "migration-version"] | ||
} | ||
|
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
Oops, something went wrong.