Skip to content

Commit

Permalink
test: verify purse balances are updated after smartWallet upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Feb 9, 2024
1 parent e052586 commit 929c333
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 35 deletions.
12 changes: 12 additions & 0 deletions a3p-integration/proposals/a:upgrade-14/invite-submission/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This core-eval installs upgrades for the wallet and Zoe. This test verifies 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 included in ./invite-submission.
The wallet in which we want to deposit the invitation is gov1, whose address
isn't known until run-time. When submitting a proposal using agd.tx(), the
proposal is required to be in a file, so we have to edit a template file
(sendInvite.tpl) to produce the .js file that will be submitted.

The core-eval is invoked from the test, which then verifies that the details
were written to vstore.
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,29 @@
// to be replaced before execution
const addr = 'XX_ADDRESS_XX';

// verify that a pre-existing wallet has an invitation purse that is still monitored
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;
4 changes: 4 additions & 0 deletions a3p-integration/proposals/a:upgrade-14/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
source /usr/src/upgrade-test-scripts/env_setup.sh

yarn ava

npm install --global tsx

./testRepairs.ts
99 changes: 99 additions & 0 deletions a3p-integration/proposals/a:upgrade-14/testRepairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env tsx

import { execFileSync } from 'child_process';
import { readFile, writeFile } from 'fs/promises';

import { makeAgd } from '@agoric/synthetic-chain/src/lib/agd-lib.js';
import {
getUser,
voteLatestProposalAndWait,
} from '@agoric/synthetic-chain/src/lib/commonUpgradeHelpers.js';
import assert from 'assert';

const SUBMISSION_DIR = 'invite-submission';

const staticConfig = {
deposit: '10000000ubld', // 10 BLD
installer: 'gov1', // as in: agd keys show gov1
proposer: 'validator',
collateralPrice: 6, // conservatively low price. TODO: look up
swingstorePath: '~/.agoric/data/agoric/swingstore.sqlite',
};

/** Provide access to the outside world via context. */
const makeContext = async () => {
const config = {
chainId: 'agoriclocal',
...staticConfig,
};

const agd = makeAgd({ execFileSync }).withOpts({
keyringBackend: 'test',
});

return { agd, config };
};

// XXX vestige of Ava
const step = async (name: string, fn: Function) => {
console.log(name);
await fn();
};

const replaceAddressInFile = async (string, fileName, replacement) => {
const scriptBuffer = await readFile(`${SUBMISSION_DIR}/${fileName}.tpl`);

const newScript = scriptBuffer.toString().replace(string, replacement);
await writeFile(`${SUBMISSION_DIR}/${fileName}.js`, newScript);
};

await step('verify smartWallet repairs', async () => {
const { agd, config } = await makeContext();
const { chainId, deposit, proposer } = config;
const from = agd.lookup(proposer);

const gov1Address = await getUser('gov1');
await replaceAddressInFile('XX_ADDRESS_XX', 'sendInvite', gov1Address);

// agd tx gov submit-proposal swingset-core-eval bar.json foo.js
await agd.tx(
[
'gov',
'submit-proposal',
'swingset-core-eval',
`${SUBMISSION_DIR}/sendInvite-permit.json`,
`${SUBMISSION_DIR}/sendInvite.js`,
'--title=sendInvite',
'--description="send an invitation to verify the purse accepts deposits"',
`--deposit=${deposit}`,
'--gas=auto',
'--gas-adjustment=1.2',
'--keyring-backend=test',
],
{ from, chainId, yes: true },
);
await voteLatestProposalAndWait();

// 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;
assert(invitePurseBalance.value[0], 'expecting a non-empty purse');
const description = invitePurseBalance.value[0].description;

assert.equal(
description,
'Add Collateral',
'invitation purse should not be empty',
);

console.log('✅ invitation purse is not empty');
});
2 changes: 1 addition & 1 deletion a3p-integration/proposals/a:upgrade-14/use.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

# UNTIl this is upstream https://github.com/Agoric/agoric-3-proposals/issues/40
# UNTIL this is upstream https://github.com/Agoric/agoric-3-proposals/issues/40
# Set to zero so tests don't have to pay gas (we're not testing that)
sed --in-place=.bak s/'minimum-gas-prices = ""'/'minimum-gas-prices = "0ubld,0uist"'/ ~/.agoric/config/app.toml
42 changes: 21 additions & 21 deletions a3p-integration/proposals/a:upgrade-14/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,18 @@ __metadata:
linkType: hard

"acorn-walk@npm:^8.2.0":
version: 8.3.1
resolution: "acorn-walk@npm:8.3.1"
checksum: a23d2f7c6b6cad617f4c77f14dfeb062a239208d61753e9ba808d916c550add92b39535467d2e6028280761ac4f5a904cc9df21530b84d3f834e3edef74ddde5
version: 8.3.2
resolution: "acorn-walk@npm:8.3.2"
checksum: 7e2a8dad5480df7f872569b9dccff2f3da7e65f5353686b1d6032ab9f4ddf6e3a2cb83a9b52cf50b1497fd522154dda92f0abf7153290cc79cd14721ff121e52
languageName: node
linkType: hard

"acorn@npm:^8.8.2":
version: 8.11.2
resolution: "acorn@npm:8.11.2"
version: 8.11.3
resolution: "acorn@npm:8.11.3"
bin:
acorn: bin/acorn
checksum: a3ed76c761b75ec54b1ec3068fb7f113a182e95aea7f322f65098c2958d232e3d211cb6dac35ff9c647024b63714bc528a26d54a925d1fef2c25585b4c8e4017
checksum: 3ff155f8812e4a746fee8ecff1f227d527c4c45655bb1fad6347c3cb58e46190598217551b1500f18542d2bbe5c87120cb6927f5a074a59166fbdd9468f0a299
languageName: node
linkType: hard

Expand Down Expand Up @@ -446,13 +446,13 @@ __metadata:
linkType: hard

"better-sqlite3@npm:^9.2.2":
version: 9.2.2
resolution: "better-sqlite3@npm:9.2.2"
version: 9.3.0
resolution: "better-sqlite3@npm:9.3.0"
dependencies:
bindings: "npm:^1.5.0"
node-gyp: "npm:latest"
prebuild-install: "npm:^7.1.1"
checksum: b4bfe142ba4544a0cc76b2ca03d89bce1acf3fe8a86a1ba317a4049b26bf8fed70fb413f6317d2e5abeb97e31b177accb6d09619fdc0531e891cee112e2aade1
checksum: 08943620079dd3f7de7e12a7cb63b9a6ca5b399ca3e06363f120b2589c86cadef2eca56558243bfaf930fb28b4d956ab0b3910bc8b09a35276670efe7b7c516c
languageName: node
linkType: hard

Expand Down Expand Up @@ -526,8 +526,8 @@ __metadata:
linkType: hard

"cacache@npm:^18.0.0":
version: 18.0.1
resolution: "cacache@npm:18.0.1"
version: 18.0.2
resolution: "cacache@npm:18.0.2"
dependencies:
"@npmcli/fs": "npm:^3.1.0"
fs-minipass: "npm:^3.0.0"
Expand All @@ -541,7 +541,7 @@ __metadata:
ssri: "npm:^10.0.0"
tar: "npm:^6.1.11"
unique-filename: "npm:^3.0.0"
checksum: a31666805a80a8b16ad3f85faf66750275a9175a3480896f4f6d31b5d53ef190484fabd71bdb6d2ea5603c717fbef09f4af03d6a65b525c8ef0afaa44c361866
checksum: 7992665305cc251a984f4fdbab1449d50e88c635bc43bf2785530c61d239c61b349e5734461baa461caaee65f040ab14e2d58e694f479c0810cffd181ba5eabc
languageName: node
linkType: hard

Expand Down Expand Up @@ -802,9 +802,9 @@ __metadata:
linkType: hard

"emittery@npm:^1.0.1":
version: 1.0.1
resolution: "emittery@npm:1.0.1"
checksum: 2587f2f42bb5e004ba1cde61352d2151f4dd4f29eb79ad36f82e200da2faec9742d7bfca1492a024d60396e001e4b07d9b2b9c43be33547ff751ba8ff87c42ce
version: 1.0.2
resolution: "emittery@npm:1.0.2"
checksum: 7f26cdb3044dc25689b44e81d4486b404dcec93faaec71f09b8ead8bd0e089a58a26e4605bac2894c8985d5cc48c0f359f943da098944e9fdc3a04bb6bec6299
languageName: node
linkType: hard

Expand Down Expand Up @@ -1021,11 +1021,11 @@ __metadata:
linkType: hard

"fastq@npm:^1.6.0":
version: 1.15.0
resolution: "fastq@npm:1.15.0"
version: 1.17.0
resolution: "fastq@npm:1.17.0"
dependencies:
reusify: "npm:^1.0.4"
checksum: 5ce4f83afa5f88c9379e67906b4d31bc7694a30826d6cc8d0f0473c966929017fda65c2174b0ec89f064ede6ace6c67f8a4fe04cef42119b6a55b0d465554c24
checksum: 0a90ed46ccd6a858a32e297bd35f4249ba6544899b905d08f33a6ba36459041639161fa15bc85a38afa98dd44fb2fa2969419a879721a1395d3e24668a7732c7
languageName: node
linkType: hard

Expand Down Expand Up @@ -1772,11 +1772,11 @@ __metadata:
linkType: hard

"npm-run-path@npm:^5.1.0":
version: 5.1.0
resolution: "npm-run-path@npm:5.1.0"
version: 5.2.0
resolution: "npm-run-path@npm:5.2.0"
dependencies:
path-key: "npm:^4.0.0"
checksum: ff6d77514489f47fa1c3b1311d09cd4b6d09a874cc1866260f9dea12cbaabda0436ed7f8c2ee44d147bf99a3af29307c6f63b0f83d242b0b6b0ab25dff2629e3
checksum: 7963c1f98e42afebe9524a08b0881477ec145aab34f6018842a315422b25ad40e015bdee709b697571e5efda2ecfa2640ee917d92674e4de1166fa3532a211b1
languageName: node
linkType: hard

Expand Down
24 changes: 12 additions & 12 deletions a3p-integration/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,15 @@ __metadata:
linkType: hard

"@npmcli/agent@npm:^2.0.0":
version: 2.2.0
resolution: "@npmcli/agent@npm:2.2.0"
version: 2.2.1
resolution: "@npmcli/agent@npm:2.2.1"
dependencies:
agent-base: "npm:^7.1.0"
http-proxy-agent: "npm:^7.0.0"
https-proxy-agent: "npm:^7.0.1"
lru-cache: "npm:^10.0.1"
socks-proxy-agent: "npm:^8.0.1"
checksum: 7b89590598476dda88e79c473766b67c682aae6e0ab0213491daa6083dcc0c171f86b3868f5506f22c09aa5ea69ad7dfb78f4bf39a8dca375d89a42f408645b3
checksum: 38ee5cbe8f3cde13be916e717bfc54fd1a7605c07af056369ff894e244c221e0b56b08ca5213457477f9bc15bca9e729d51a4788829b5c3cf296b3c996147f76
languageName: node
linkType: hard

Expand Down Expand Up @@ -456,13 +456,13 @@ __metadata:
linkType: hard

"better-sqlite3@npm:^9.2.2":
version: 9.3.0
resolution: "better-sqlite3@npm:9.3.0"
version: 9.4.0
resolution: "better-sqlite3@npm:9.4.0"
dependencies:
bindings: "npm:^1.5.0"
node-gyp: "npm:latest"
prebuild-install: "npm:^7.1.1"
checksum: 08943620079dd3f7de7e12a7cb63b9a6ca5b399ca3e06363f120b2589c86cadef2eca56558243bfaf930fb28b4d956ab0b3910bc8b09a35276670efe7b7c516c
checksum: 42b2edfa46d62763514b87122245a3513a5ff20f05fef4fb49fec33f3de0a51a29025596178f57c634b8013f16bbdf8169a308fb3e3b8d126d715788d72d1e74
languageName: node
linkType: hard

Expand Down Expand Up @@ -1096,9 +1096,9 @@ __metadata:
linkType: hard

"lru-cache@npm:^10.0.1, lru-cache@npm:^9.1.1 || ^10.0.0":
version: 10.1.0
resolution: "lru-cache@npm:10.1.0"
checksum: 778bc8b2626daccd75f24c4b4d10632496e21ba064b126f526c626fbdbc5b28c472013fccd45d7646b9e1ef052444824854aed617b59cd570d01a8b7d651fc1e
version: 10.2.0
resolution: "lru-cache@npm:10.2.0"
checksum: c9847612aa2daaef102d30542a8d6d9b2c2bb36581c1bf0dc3ebf5e5f3352c772a749e604afae2e46873b930a9e9523743faac4e5b937c576ab29196774712ee
languageName: node
linkType: hard

Expand Down Expand Up @@ -1500,13 +1500,13 @@ __metadata:
linkType: hard

"semver@npm:^7.3.5":
version: 7.5.4
resolution: "semver@npm:7.5.4"
version: 7.6.0
resolution: "semver@npm:7.6.0"
dependencies:
lru-cache: "npm:^6.0.0"
bin:
semver: bin/semver.js
checksum: 5160b06975a38b11c1ab55950cb5b8a23db78df88275d3d8a42ccf1f29e55112ac995b3a26a522c36e3b5f76b0445f1eef70d696b8c7862a2b4303d7b0e7609e
checksum: fbfe717094ace0aa8d6332d7ef5ce727259815bd8d8815700853f4faf23aacbd7192522f0dc5af6df52ef4fa85a355ebd2f5d39f554bd028200d6cf481ab9b53
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export const prepareSmartWallet = (baggage, shared) => {
const { invitationPurse, address } = state;

const brandToPurses = getBrandToPurses(walletPurses, self);
trace(`Found ${brandToPurses.values()} purse(s) for ${address}`);
trace(`Found purse(s) for ${address}`);
for (const purses of brandToPurses.values()) {
for (const record of purses) {
void helper.watchPurse(record.purse);
Expand Down

0 comments on commit 929c333

Please sign in to comment.