-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Move DisconnectionObject generation/testing into "internal"
- Loading branch information
Showing
5 changed files
with
72 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @ts-check | ||
// @jessie-check | ||
import { isObject } from '@endo/marshal'; | ||
|
||
/** | ||
* @typedef {{ name: string, upgradeMessage: string, incarnationNumber: number }} DisconnectionObject | ||
*/ | ||
|
||
/** | ||
* Makes an Error-like object for use as the rejection value of promises | ||
* abandoned by upgrade. | ||
* | ||
* @param {string} upgradeMessage | ||
* @param {number} toIncarnationNumber | ||
* @returns {DisconnectionObject} | ||
*/ | ||
export const makeUpgradeDisconnection = (upgradeMessage, toIncarnationNumber) => | ||
harden({ | ||
name: 'vatUpgraded', | ||
upgradeMessage, | ||
incarnationNumber: toIncarnationNumber, | ||
}); | ||
harden(makeUpgradeDisconnection); | ||
|
||
// TODO: Simplify once we have @endo/patterns (or just export the shape). | ||
// const upgradeDisconnectionShape = harden({ | ||
// name: 'vatUpgraded', | ||
// upgradeMessage: M.string(), | ||
// incarnationNumber: M.number(), | ||
// }); | ||
// const isUpgradeDisconnection = err => matches(err, upgradeDisconnectionShape); | ||
/** | ||
* @param {any} err | ||
* @returns {err is DisconnectionObject} | ||
*/ | ||
export const isUpgradeDisconnection = err => | ||
isObject(err) && | ||
err.name === 'vatUpgraded' && | ||
typeof err.upgradeMessage === 'string' && | ||
typeof err.incarnationNumber === 'number'; | ||
harden(isUpgradeDisconnection); |
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,21 @@ | ||
// @ts-check | ||
import '@endo/init'; | ||
import test from 'ava'; | ||
import { | ||
makeUpgradeDisconnection, | ||
isUpgradeDisconnection, | ||
} from '../src/upgrade-api.js'; | ||
|
||
test('isUpgradeDisconnection must recognize disconnection objects', t => { | ||
const disconnection = makeUpgradeDisconnection('vat upgraded', 2); | ||
t.true(isUpgradeDisconnection(disconnection)); | ||
}); | ||
|
||
test('isUpgradeDisconnection must recognize original-format disconnection objects', t => { | ||
const disconnection = harden({ | ||
name: 'vatUpgraded', | ||
upgradeMessage: 'vat upgraded', | ||
incarnationNumber: 2, | ||
}); | ||
t.true(isUpgradeDisconnection(disconnection)); | ||
}); |
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