-
Notifications
You must be signed in to change notification settings - Fork 208
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
1 parent
7f58a76
commit b4128c2
Showing
18 changed files
with
986 additions
and
412 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 }, | ||
}); | ||
}); |
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
Oops, something went wrong.