-
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.
test: verify purse balances are updated after smartWallet upgrade (#8909
) * test: verify purse balances are updated after smartWallet upgrade * chore: helpful suggestions from review * refactor: testRepairs to Ava test * chore: make test work on master * chore: rearrange files, repair merge conflict * chore: rename * chore: adapt wallet a3p test to new core-eval style * fixup --------- Co-authored-by: Turadg Aleahmad <turadg@agoric.com> Co-authored-by: Mathieu Hofman <mathieu@agoric.com>
- Loading branch information
1 parent
174e37d
commit a929734
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
a3p-integration/proposals/a:upgrade-next/invite-submission/README.md
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,8 @@ | ||
These files enable a test of the walletFactory changes, by | ||
verifying that upgraded wallets that aren't backed by vbanks can still add | ||
assets, in this case an invitation. | ||
|
||
sendInvite is a secondary submission, which is transmitted in ../wallet-repair.test.js. | ||
Some template values in the `.tjs` file are replaced before submitting the | ||
core-eval. The test then verifies that the invitation details were written to | ||
the wallet in vstorage. |
1 change: 1 addition & 0 deletions
1
a3p-integration/proposals/a:upgrade-next/invite-submission/sendInvite-permit.json
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 @@ | ||
true |
39 changes: 39 additions & 0 deletions
39
a3p-integration/proposals/a:upgrade-next/invite-submission/sendInvite.tjs
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,39 @@ | ||
#! false node --ignore-this-line | ||
/* global E */ | ||
|
||
/// <reference types="@agoric/vats/src/core/core-eval-env"/> | ||
/// <reference types="@agoric/vats/src/core/types-ambient"/> | ||
|
||
// to be replaced before execution | ||
const addr = '{{ADDRESS}}'; | ||
|
||
/** | ||
* verify that a pre-existing wallet has an invitation purse that is still monitored | ||
* | ||
* @param {BootstrapPowers} powers | ||
*/ | ||
const sendInvitation = async powers => { | ||
console.log('sendInvitation start'); | ||
// namesByAddress is broken #8113 | ||
const { | ||
consume: { namesByAddressAdmin, zoe }, | ||
instance: { | ||
consume: { reserve }, | ||
}, | ||
} = powers; | ||
const pf = E(zoe).getPublicFacet(reserve); | ||
const anInvitation = await E(pf).makeAddCollateralInvitation(); | ||
|
||
await E(namesByAddressAdmin).reserve(addr); | ||
// don't trigger the namesByAddressAdmin.readonly() bug | ||
const addressAdmin = E(namesByAddressAdmin).lookupAdmin(addr); | ||
|
||
await E(addressAdmin).reserve('depositFacet'); | ||
const addressHub = E(addressAdmin).readonly(); | ||
const addressDepositFacet = E(addressHub).lookup('depositFacet'); | ||
|
||
await E(addressDepositFacet).receive(anInvitation); | ||
console.log('ADDED an invitation to a purse!'); | ||
}; | ||
|
||
sendInvitation; |
46 changes: 46 additions & 0 deletions
46
a3p-integration/proposals/a:upgrade-next/wallet-repairs.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,46 @@ | ||
import { readFile, writeFile } from 'node:fs/promises'; | ||
|
||
import test from 'ava'; | ||
|
||
import { agd, getUser, evalBundles } from '@agoric/synthetic-chain'; | ||
|
||
const SUBMISSION_DIR = 'invite-submission'; | ||
|
||
/** | ||
* @param {string} fileName base file name without .tjs extension | ||
* @param {Record<string, string>} replacements | ||
*/ | ||
const replaceTemplateValuesInFile = async (fileName, replacements) => { | ||
let script = await readFile(`${fileName}.tjs`, 'utf-8'); | ||
for (const [template, value] of Object.entries(replacements)) { | ||
script = script.replaceAll(`{{${template}}}`, value); | ||
} | ||
await writeFile(`${fileName}.js`, script); | ||
}; | ||
|
||
test('smartWallet repairs', async t => { | ||
const gov1Address = await getUser('gov1'); | ||
|
||
await replaceTemplateValuesInFile(`${SUBMISSION_DIR}/sendInvite`, { | ||
ADDRESS: gov1Address, | ||
}); | ||
|
||
await evalBundles(SUBMISSION_DIR); | ||
|
||
// agd query vstorage data published.wallet.$GOV1ADDR.current -o json \ | ||
// |& jq '.value | fromjson | .values[0] | fromjson | .body[1:] \ | ||
// | fromjson | .purses ' | ||
const walletCurrent = await agd.query( | ||
'vstorage', | ||
'data', | ||
`published.wallet.${gov1Address}.current`, | ||
); | ||
|
||
const body = JSON.parse(JSON.parse(walletCurrent.value).values[0]); | ||
const bodyTruncated = JSON.parse(body.body.substring(1)); | ||
const invitePurseBalance = bodyTruncated.purses[0].balance; | ||
t.truthy(invitePurseBalance.value[0], 'expecting a non-empty purse'); | ||
const description = invitePurseBalance.value[0].description; | ||
|
||
t.is(description, 'Add Collateral', 'invitation purse should not be empty'); | ||
}); |