Skip to content

Commit

Permalink
test: verify purse balances are updated after smartWallet upgrade (#8909
Browse files Browse the repository at this point in the history
)

* 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
3 people committed Feb 17, 2024
1 parent 174e37d commit a929734
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
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 a3p-integration/proposals/a:upgrade-next/wallet-repairs.test.js
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');
});

0 comments on commit a929734

Please sign in to comment.