-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add strict liveslots test env with upgrade tools (#10126)
closes: #9126 Best reviewed commit-by-commit ## Description This PR add a new `prepare-strict-test-env.js` which enforces durable requirements on the baggage and provide helpers to simulate upgrades based on the helper from the `async-flow` and `zone` package tests. In particular it adds a new `startLife` helper which enforces kind redefinition rules for a `build` step, and rejects previously watched promises (assuming they were all decided by the previous incarnation). ### Security Considerations None, test infra only ### Scaling Considerations None ### Documentation Considerations Some types added and clarified. Internal tooling ### Testing Considerations Adds tests of the new strict env and `startLife` helper. Add liveslots based test in `vow` using the new `startLife` helper. Updated the test environments in the `zone` and `async-flow` package to use the new liveslots env, but does not update the `async-flow` tests to use the stricter `startLife` (will be done in #9933 or #9383) ### Upgrade Considerations Better upgrade testing without needing a full swingset kernel
- Loading branch information
Showing
17 changed files
with
429 additions
and
133 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,19 @@ | ||
/** | ||
* Like prepare-strict-test-env but also sets up ses-ava and provides | ||
* the ses-ava `test` function to be used as if it is the ava | ||
* `test` function. | ||
*/ | ||
|
||
import '@agoric/swingset-liveslots/tools/prepare-strict-test-env.js'; | ||
|
||
import { wrapTest } from '@endo/ses-ava'; | ||
import rawTest from 'ava'; | ||
|
||
export * from '@agoric/swingset-liveslots/tools/prepare-strict-test-env.js'; | ||
|
||
export const test = wrapTest(rawTest); | ||
|
||
// Does not import from a module because we're testing the global env | ||
/* global globalThis */ | ||
export const VatData = globalThis.VatData; | ||
assert(VatData); |
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,70 @@ | ||
import { provideLazy as provide } from '@agoric/store'; | ||
|
||
// Partially duplicates @agoric/vat-data to avoid circular dependencies. | ||
export const makeExoUtils = VatData => { | ||
const { defineDurableKind, makeKindHandle, watchPromise } = VatData; | ||
|
||
const provideKindHandle = (baggage, kindName) => | ||
provide(baggage, `${kindName}_kindHandle`, () => makeKindHandle(kindName)); | ||
|
||
const emptyRecord = harden({}); | ||
const initEmpty = () => emptyRecord; | ||
|
||
const defineDurableExoClass = ( | ||
kindHandle, | ||
interfaceGuard, | ||
init, | ||
methods, | ||
options, | ||
) => | ||
defineDurableKind(kindHandle, init, methods, { | ||
...options, | ||
thisfulMethods: true, | ||
interfaceGuard, | ||
}); | ||
|
||
const prepareExoClass = ( | ||
baggage, | ||
kindName, | ||
interfaceGuard, | ||
init, | ||
methods, | ||
options = undefined, | ||
) => | ||
defineDurableExoClass( | ||
provideKindHandle(baggage, kindName), | ||
interfaceGuard, | ||
init, | ||
methods, | ||
options, | ||
); | ||
|
||
const prepareExo = ( | ||
baggage, | ||
kindName, | ||
interfaceGuard, | ||
methods, | ||
options = undefined, | ||
) => { | ||
const makeSingleton = prepareExoClass( | ||
baggage, | ||
kindName, | ||
interfaceGuard, | ||
initEmpty, | ||
methods, | ||
options, | ||
); | ||
return provide(baggage, `the_${kindName}`, () => makeSingleton()); | ||
}; | ||
|
||
return { | ||
defineDurableKind, | ||
makeKindHandle, | ||
watchPromise, | ||
|
||
provideKindHandle, | ||
defineDurableExoClass, | ||
prepareExoClass, | ||
prepareExo, | ||
}; | ||
}; |
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
94 changes: 94 additions & 0 deletions
94
packages/swingset-liveslots/test/strict-test-env-upgrade.test.js
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,94 @@ | ||
/* global globalThis */ | ||
// eslint-disable-next-line import/order | ||
import { annihilate, startLife } from '../tools/prepare-strict-test-env.js'; | ||
|
||
import test from 'ava'; | ||
|
||
import { makeUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js'; | ||
import { makeExoUtils } from './exo-utils.js'; | ||
|
||
test.serial('kind redefinition enforced', async t => { | ||
annihilate(); | ||
|
||
const { prepareExoClass } = makeExoUtils(globalThis.VatData); | ||
|
||
await startLife(async baggage => { | ||
const makeTestExo = prepareExoClass( | ||
baggage, | ||
'TestExo', | ||
undefined, | ||
() => ({}), | ||
{ | ||
foo() { | ||
return 'bar'; | ||
}, | ||
}, | ||
); | ||
|
||
baggage.init('testExo', makeTestExo()); | ||
}); | ||
|
||
await t.throwsAsync( | ||
async () => | ||
startLife(async () => { | ||
// Not redefining the kind here | ||
}), | ||
{ message: 'defineDurableKind not called for tags: [TestExo]' }, | ||
); | ||
|
||
await startLife(async baggage => { | ||
prepareExoClass(baggage, 'TestExo', undefined, () => ({}), { | ||
foo() { | ||
return 'baz'; | ||
}, | ||
}); | ||
|
||
t.is(baggage.get('testExo').foo(), 'baz'); | ||
}); | ||
}); | ||
|
||
test.serial('decided promise rejected', async t => { | ||
annihilate(); | ||
|
||
const { prepareExo } = makeExoUtils(globalThis.VatData); | ||
const { watchPromise } = globalThis.VatData; | ||
|
||
t.plan(1); | ||
|
||
await startLife(async baggage => { | ||
const watcher = prepareExo( | ||
baggage, | ||
'DurablePromiseTestWatcher', | ||
undefined, | ||
{ | ||
onFulfilled(value) { | ||
t.fail( | ||
`First incarnation watcher onFulfilled triggered with value ${value}`, | ||
); | ||
}, | ||
onRejected(reason) { | ||
t.fail( | ||
`First incarnation watcher onRejected triggered with reason ${reason}`, | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
const never = harden(new Promise(() => {})); | ||
|
||
watchPromise(never, watcher); | ||
}); | ||
|
||
await startLife(async baggage => { | ||
prepareExo(baggage, 'DurablePromiseTestWatcher', undefined, { | ||
onFulfilled(value) { | ||
t.fail( | ||
`Second incarnation watcher onFulfilled triggered with value ${value}`, | ||
); | ||
}, | ||
onRejected(reason) { | ||
t.deepEqual(reason, makeUpgradeDisconnection('vat upgraded', 1)); | ||
}, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.