-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c30c8be
commit 153caff
Showing
4 changed files
with
78 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { assert, details, q } from '@agoric/assert'; | ||
|
||
/** | ||
* Assert all values from `part` appear in `whole`. | ||
* | ||
* @param {string[]} whole | ||
* @param {string[]} part | ||
*/ | ||
export const assertSubset = (whole, part) => { | ||
part.forEach(key => { | ||
assert.typeof(key, 'string'); | ||
assert( | ||
whole.includes(key), | ||
details`key ${q(key)} was not one of the expected keys ${q(whole)}`, | ||
); | ||
}); | ||
}; | ||
|
||
// Assert that the keys of `record` are all in `allowedKeys`. If a key | ||
// of `record` is not in `allowedKeys`, throw an error. If a key in | ||
// `allowedKeys` is not a key of record, we do not throw an error. | ||
export const assertKeysAllowed = (allowedKeys, record) => { | ||
const keys = Object.getOwnPropertyNames(record); | ||
assertSubset(allowedKeys, keys); | ||
// assert that there are no symbol properties. | ||
assert( | ||
Object.getOwnPropertySymbols(record).length === 0, | ||
details`no symbol properties allowed`, | ||
); | ||
}; | ||
|
||
export const assertDisplayInfo = allegedDisplayInfo => { | ||
if (allegedDisplayInfo === undefined) { | ||
return; | ||
} | ||
const displayInfoKeys = harden(['decimalPlaces']); | ||
assertKeysAllowed(displayInfoKeys, allegedDisplayInfo); | ||
}; |
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