-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: smartWallet verstion 2 with watchedPromises
pulled offers.js and payments.js into smartWallet.js as they shared plenty of state that needs to be durable in order to be callable from the watchedPromise. build an upgrade proposal; tested in Agoric/agoric-3-proposals#34
- Loading branch information
Showing
17 changed files
with
1,025 additions
and
408 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
packages/boot/test/bootstrapTests/test-walletSurvivesZoeRestart.ts
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,115 @@ | ||
/** @file Bootstrap test of liquidation across multiple collaterals */ | ||
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import process from 'process'; | ||
import type { TestFn } from 'ava'; | ||
|
||
import { BridgeHandler } from '@agoric/vats'; | ||
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js'; | ||
import { | ||
LiquidationTestContext, | ||
makeLiquidationTestContext, | ||
LiquidationSetup, | ||
} from '../../tools/liquidation.ts'; | ||
|
||
const test = anyTest as TestFn<LiquidationTestContext>; | ||
|
||
const setup: LiquidationSetup = { | ||
vaults: [ | ||
{ | ||
atom: 15, | ||
ist: 100, | ||
debt: 100.5, | ||
}, | ||
], | ||
bids: [ | ||
{ | ||
give: '80IST', | ||
discount: 0.1, | ||
}, | ||
], | ||
price: { | ||
starting: 12.34, | ||
trigger: 9.99, | ||
}, | ||
auction: { | ||
start: { | ||
collateral: 45, | ||
debt: 309.54, | ||
}, | ||
end: { | ||
collateral: 9.659301, | ||
debt: 0, | ||
}, | ||
}, | ||
}; | ||
|
||
test.before(async t => { | ||
t.context = await makeLiquidationTestContext(t); | ||
}); | ||
|
||
test.after.always(t => { | ||
return t.context.shutdown && t.context.shutdown(); | ||
}); | ||
|
||
test.serial('wallet survives zoe null upgrade', async t => { | ||
// fail if there are any unhandled rejections | ||
process.on('unhandledRejection', (error: Error) => { | ||
t.fail(error.message); | ||
}); | ||
const collateralBrandKey = 'ATOM'; | ||
const managerIndex = 0; | ||
|
||
const { walletFactoryDriver, setupVaults, controller, buildProposal } = | ||
t.context; | ||
|
||
const { EV } = t.context.runUtils; | ||
|
||
const buyer = await walletFactoryDriver.provideSmartWallet('agoric1buyer'); | ||
|
||
const buildAndExecuteProposal = async (packageSpec: string) => { | ||
const proposal = await buildProposal(packageSpec); | ||
|
||
for await (const bundle of proposal.bundles) { | ||
await controller.validateAndInstallBundle(bundle); | ||
} | ||
|
||
const bridgeMessage = { | ||
type: 'CORE_EVAL', | ||
evals: proposal.evals, | ||
}; | ||
|
||
const coreEvalBridgeHandler: ERef<BridgeHandler> = await EV.vat( | ||
'bootstrap', | ||
).consumeItem('coreEvalBridgeHandler'); | ||
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage); | ||
}; | ||
|
||
await setupVaults(collateralBrandKey, managerIndex, setup); | ||
|
||
// restart Zoe | ||
|
||
// /////// Upgrading //////////////////////////////// | ||
await buildAndExecuteProposal('@agoric/builders/scripts/vats/upgrade-zoe.js'); | ||
|
||
t.like(await buyer.getLatestUpdateRecord(), { | ||
currentAmount: { | ||
// brand from EV() doesn't compare correctly | ||
// brand: invitationBrand, | ||
value: [], | ||
}, | ||
updated: 'balance', | ||
}); | ||
|
||
await buyer.executeOfferMaker(Offers.vaults.OpenVault, { | ||
offerId: 'open1', | ||
collateralBrandKey: 'ATOM', | ||
wantMinted: 5.0, | ||
giveCollateral: 9.0, | ||
}); | ||
|
||
t.like(buyer.getLatestUpdateRecord(), { | ||
updated: 'offerStatus', | ||
status: { id: 'open1', numWantsSatisfied: 1 }, | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/builders/scripts/smart-wallet/build-wallet-factory2-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,29 @@ | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
|
||
/** | ||
* @file | ||
* `agoric run scripts/smart-wallet/build-wallet-factory2-upgrade.js` | ||
* produces a proposal and permit file, as well as the necessary bundles. It | ||
* also prints helpful instructions for copying the files and installing them. | ||
*/ | ||
|
||
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ | ||
export const defaultProposalBuilder = async ({ publishRef, install }) => | ||
harden({ | ||
sourceSpec: | ||
'@agoric/smart-wallet/src/proposals/upgrade-wallet-factory2-proposal.js', | ||
getManifestCall: [ | ||
'getManifestForUpgradeWallet', | ||
{ | ||
walletRef: publishRef( | ||
// @ts-expect-error eslint is confused. The call is correct. | ||
install('@agoric/smart-wallet/src/walletFactory.js'), | ||
), | ||
}, | ||
], | ||
}); | ||
|
||
export default async (homeP, endowments) => { | ||
const { writeCoreProposal } = await makeHelpers(homeP, endowments); | ||
await writeCoreProposal('upgrade-wallet-factory', defaultProposalBuilder); | ||
}; |
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
Oops, something went wrong.