-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7096 from Agoric/6878-walletFactory-upgrade
6878 wallet factory upgrade
- Loading branch information
Showing
20 changed files
with
492 additions
and
52 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
151 changes: 151 additions & 0 deletions
151
...wallet/test/swingsetTests/upgradeWalletFactory/bootstrap-walletFactory-service-upgrade.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,151 @@ | ||
// @ts-check | ||
import { Fail } from '@agoric/assert'; | ||
import { makeTracer } from '@agoric/internal'; | ||
import { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js'; | ||
import { makeSubscriptionKit } from '@agoric/notifier'; | ||
import { makeNameHubKit } from '@agoric/vats'; | ||
import { makeAgoricNamesAccess } from '@agoric/vats/src/core/utils.js'; | ||
import { makeBoard } from '@agoric/vats/src/lib-board.js'; | ||
import { makeFakeBankKit } from '@agoric/vats/tools/bank-utils.js'; | ||
import { E } from '@endo/eventual-send'; | ||
import { Far } from '@endo/marshal'; | ||
|
||
const trace = makeTracer('BootWFUpg', false); | ||
|
||
export const wfV1BundleName = 'walletFactoryV1'; | ||
export const wfV2BundleName = 'walletFactoryV2'; | ||
|
||
export const buildRootObject = () => { | ||
const storageKit = makeFakeStorageKit('walletFactoryUpgradeTest'); | ||
const walletPath = 'walletFactoryUpgradeTest.agoric1whatever.current'; | ||
const board = makeBoard(); | ||
const { agoricNames } = makeAgoricNamesAccess(); | ||
const assetPublisher = Far('mockAssetPublisher', { | ||
getAssetSubscription: () => makeSubscriptionKit().subscription, | ||
}); | ||
const { nameAdmin: namesByAddressAdmin } = makeNameHubKit(); | ||
|
||
let vatAdmin; | ||
/** @type {ZoeService} */ | ||
let zoe; | ||
/** @type {AdminFacet} */ | ||
let adminFacet; | ||
let creatorFacet; | ||
let bank; | ||
/** @type {import('../../../src/smartWallet.js').SmartWallet} */ | ||
let wallet; | ||
|
||
// for startInstance | ||
/** @type {Installation<import('../../../src/walletFactory.js').prepare>} */ | ||
let installation; | ||
const terms = { agoricNames, board, assetPublisher }; | ||
const privateArgs = { | ||
storageNode: storageKit.rootNode, | ||
// omit walletBridgeManager | ||
}; | ||
|
||
return Far('root', { | ||
bootstrap: async (vats, devices) => { | ||
vatAdmin = await E(vats.vatAdmin).createVatAdminService(devices.vatAdmin); | ||
({ zoeService: zoe } = await E(vats.zoe).buildZoe( | ||
vatAdmin, | ||
undefined, | ||
'zcf', | ||
)); | ||
|
||
({ bank } = makeFakeBankKit([])); | ||
|
||
const v1BundleId = await E(vatAdmin).getBundleIDByName(wfV1BundleName); | ||
assert(v1BundleId, 'bundleId must not be empty'); | ||
installation = await E(zoe).installBundleID(v1BundleId); | ||
}, | ||
|
||
buildV1: async () => { | ||
trace(`BOOT buildV1 start`); | ||
// build the contract vat from ZCF and the contract bundlecap | ||
|
||
// Complete round-trip without upgrade | ||
trace(`BOOT buildV1 startInstance`); | ||
const facets = await E(zoe).startInstance( | ||
installation, | ||
{}, | ||
terms, | ||
privateArgs, | ||
); | ||
({ adminFacet, creatorFacet } = facets); | ||
const [newWallet, isNew] = await E(creatorFacet).provideSmartWallet( | ||
'agoric1whatever', | ||
bank, | ||
namesByAddressAdmin, | ||
); | ||
isNew || Fail`wallet in buildV1 should be new`; | ||
wallet = newWallet; | ||
|
||
const currentStoragePath = await E.get( | ||
E.get(E(wallet).getPublicTopics()).current, | ||
).storagePath; | ||
currentStoragePath === walletPath || Fail`bad storage path`; | ||
|
||
return true; | ||
}, | ||
|
||
nullUpgradeV1: async () => { | ||
trace(`BOOT nullUpgradeV1 start`); | ||
|
||
trace(`BOOT nullUpgradeV1 upgradeContract`); | ||
const bundleId = await E(vatAdmin).getBundleIDByName(wfV1BundleName); | ||
const upgradeResult = await E(adminFacet).upgradeContract( | ||
bundleId, | ||
privateArgs, | ||
); | ||
assert.equal(upgradeResult.incarnationNumber, 2); | ||
|
||
const [wallet2, isNew] = await E(creatorFacet).provideSmartWallet( | ||
'agoric1whatever', | ||
bank, | ||
namesByAddressAdmin, | ||
); | ||
!isNew || Fail`wallet in nullUpgradeV1 should not be new`; | ||
wallet2 === wallet || Fail`must be same wallet obj`; | ||
|
||
const currentStoragePath = await E.get( | ||
E.get(E(wallet).getPublicTopics()).current, | ||
).storagePath; | ||
currentStoragePath === walletPath || Fail`bad storage path`; | ||
|
||
return true; | ||
}, | ||
|
||
upgradeV2: async () => { | ||
trace(`BOOT upgradeV2 start`); | ||
const bundleId = await E(vatAdmin).getBundleIDByName(wfV2BundleName); | ||
|
||
const upgradeResult = await E(adminFacet).upgradeContract( | ||
bundleId, | ||
privateArgs, | ||
); | ||
assert.equal(upgradeResult.incarnationNumber, 3); | ||
trace(`BOOT upgradeV2 startInstance`); | ||
|
||
const [wallet2, isNew] = await E(creatorFacet).provideSmartWallet( | ||
'agoric1whatever', | ||
bank, | ||
namesByAddressAdmin, | ||
); | ||
!isNew || Fail`wallet in nullUpgradeV1 should not be new`; | ||
wallet2 === wallet || Fail`must be same wallet obj`; | ||
|
||
const currentStoragePath = await E.get( | ||
E.get(E(wallet).getPublicTopics()).current, | ||
).storagePath; | ||
currentStoragePath === walletPath || Fail`bad storage path`; | ||
|
||
// verify new method is present | ||
const result = await E(creatorFacet).sayHelloUpgrade(); | ||
result === 'hello, upgrade' || Fail`bad upgrade`; | ||
|
||
trace('Boot finished test'); | ||
return true; | ||
}, | ||
}); | ||
}; |
63 changes: 63 additions & 0 deletions
63
...mart-wallet/test/swingsetTests/upgradeWalletFactory/test-walletFactory-service-upgrade.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,63 @@ | ||
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; | ||
|
||
import { assert } from '@agoric/assert'; | ||
import { buildVatController } from '@agoric/swingset-vat'; | ||
import { | ||
wfV1BundleName, | ||
wfV2BundleName, | ||
} from './bootstrap-walletFactory-service-upgrade.js'; | ||
|
||
// so paths can be expresssed relative to this file and made absolute | ||
const bfile = name => new URL(name, import.meta.url).pathname; | ||
|
||
test('walletFactory service upgrade', async t => { | ||
/** @type {SwingSetConfig} */ | ||
const config = { | ||
defaultManagerType: 'local', | ||
bundleCachePath: 'bundles/', | ||
bootstrap: 'bootstrap', | ||
vats: { | ||
bootstrap: { | ||
// TODO refactor to use bootstrap-relay.js | ||
sourceSpec: bfile('bootstrap-walletFactory-service-upgrade.js'), | ||
}, | ||
zoe: { sourceSpec: bfile('../../../../vats/src/vat-zoe.js') }, | ||
}, | ||
bundles: { | ||
zcf: { | ||
sourceSpec: bfile('../../../../zoe/src/contractFacet/vatRoot.js'), | ||
}, | ||
[wfV1BundleName]: { | ||
sourceSpec: bfile('../../../src/walletFactory.js'), | ||
}, | ||
[wfV2BundleName]: { sourceSpec: bfile('walletFactory-V2.js') }, | ||
}, | ||
}; | ||
|
||
t.log('buildVatController'); | ||
const c = await buildVatController(config); | ||
c.pinVatRoot('bootstrap'); | ||
t.log('run controller'); | ||
await c.run(); | ||
|
||
const run = async (name, args = []) => { | ||
assert(Array.isArray(args)); | ||
const kpid = c.queueToVatRoot('bootstrap', name, args); | ||
await c.run(); | ||
const status = c.kpStatus(kpid); | ||
const capdata = c.kpResolution(kpid); | ||
return [status, capdata]; | ||
}; | ||
|
||
t.log('create initial version'); | ||
const [v1status] = await run('buildV1', []); | ||
t.is(v1status, 'fulfilled'); | ||
|
||
t.log('perform null upgrade'); | ||
const [null1status] = await run('nullUpgradeV1', []); | ||
t.is(null1status, 'fulfilled'); | ||
|
||
t.log('now perform the V2 upgrade'); | ||
const [v2status] = await run('upgradeV2', []); | ||
t.is(v2status, 'fulfilled'); | ||
}); |
Oops, something went wrong.