Skip to content

Commit

Permalink
synchronous makeVstorageKit (#10670)
Browse files Browse the repository at this point in the history
_incidental_

refs: agoric-labs/vstorage-viewer#2

## Description
In the course of working on agoric-labs/vstorage-viewer#3 it was hard to work with an async `makeVstorageKit`. It was async because construction of the kit required fetching a bunch of data from vstorage to populate `agoricNames`.

That concern is a higher level than vstorage so this pulls it out. That allows `makeVstorageKit` to be synchronous.

I added a test of `makeAgoricNames` both before and after.

Eventually I think something should make it easy to make an AgoricNamesKit that wraps `VstorageKit` the way `VstorageKit` wraps `Vstorage`. `makeWalletUtils` does that but needs more work. At least renaming to `SmartWallet` but it would help to have a rethink of the layering and vstorage decoding in client-utils.

### Security Considerations
none

### Scaling Considerations
none

### Documentation Considerations
not documented but this will make it less complex

### Testing Considerations
new test

While refactoring, tsc really let me down by not detecting destuctured properies that were no longer on the source object. I suppose our settings aren't strict enough. I enabled `noImplicitAny` to detect those (by then filtering for makeVstorageKit)

### Upgrade Considerations
n/a
  • Loading branch information
mergify[bot] authored Dec 11, 2024
2 parents fbae24c + 501be3a commit 8f9f075
Show file tree
Hide file tree
Showing 37 changed files with 783 additions and 742 deletions.
3 changes: 2 additions & 1 deletion a3p-integration/proposals/s:stake-bld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@types/node": "^22.0.0"
"@types/node": "^22.0.0",
"typescript": "^5.7.2"
},
"resolutions": {
"@agoric/cosmos": "portal:../../agoric-sdk/golang/cosmos",
Expand Down
11 changes: 6 additions & 5 deletions a3p-integration/proposals/s:stake-bld/stakeBld.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GOV1ADDR } from '@agoric/synthetic-chain';
import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
import assert from 'node:assert';
import process from 'node:process';
import { networkConfig, walletUtils } from './test-lib/index.js';
import { networkConfig, agdWalletUtils } from './test-lib/index.js';

// XXX not the same as VALIDATOR_ADDRESS, which is actually the delegator
const VALIDATOR_ADDRESS = process.env.VALIDATOR_ADDRESS;
Expand All @@ -26,14 +26,15 @@ const currentDelegation = async () => {
test('basic', async t => {
assert(GOV1ADDR);

const { brand } = walletUtils.agoricNames;
const { brand } = agdWalletUtils.agoricNames;

t.is((await currentDelegation()).length, 1, 'just the initial delegation');

/** @type {import('@agoric/ertp').Brand} */
// @ts-expect-error actually a BoardRemote
const BLDBrand = brand.BLD;

await walletUtils.broadcastBridgeAction(GOV1ADDR, {
await agdWalletUtils.broadcastBridgeAction(GOV1ADDR, {
method: 'executeOffer',
offer: {
id: 'request-stake',
Expand All @@ -50,7 +51,7 @@ test('basic', async t => {
},
});

await walletUtils.broadcastBridgeAction(GOV1ADDR, {
await agdWalletUtils.broadcastBridgeAction(GOV1ADDR, {
method: 'executeOffer',
offer: {
id: 'request-delegate-6',
Expand All @@ -75,7 +76,7 @@ test('basic', async t => {
// omit 'delegation' because it has 'delegatorAddress' which is different every test run
});

await walletUtils.broadcastBridgeAction(GOV1ADDR, {
await agdWalletUtils.broadcastBridgeAction(GOV1ADDR, {
method: 'executeOffer',
offer: {
id: 'request-undelegate',
Expand Down
15 changes: 10 additions & 5 deletions a3p-integration/proposals/s:stake-bld/test-lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-env node */
import { makeSmartWalletKit, LOCAL_CONFIG } from '@agoric/client-utils';
import { execFileSync } from 'child_process';
import { LOCAL_CONFIG as networkConfig } from '@agoric/client-utils';
import { makeWalletUtils } from './wallet.js';
import { makeAgdWalletKit } from './wallet.js';

export { networkConfig };
export const networkConfig = LOCAL_CONFIG;

/**
* Resolve after a delay in milliseconds.
Expand All @@ -13,7 +13,12 @@ export { networkConfig };
*/
const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms));

export const walletUtils = await makeWalletUtils(
{ execFileSync, delay, fetch },
export const smartWalletKit = await makeSmartWalletKit(
{ delay, fetch },
networkConfig,
);

export const agdWalletUtils = await makeAgdWalletKit(
{ execFileSync, smartWalletKit, delay },
networkConfig,
);
24 changes: 12 additions & 12 deletions a3p-integration/proposals/s:stake-bld/test-lib/wallet.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// @ts-check

import { makeVstorageKit } from '@agoric/client-utils';
import { sendAction } from 'agoric/src/lib/index.js';
import { inspect } from 'util';

export const makeWalletUtils = async (
{ delay, execFileSync, fetch },
/**
* Stop-gap using execFileSync until we have a pure JS signing client.
*
* @param {object} root0
* @param {import('child_process')['execFileSync']} root0.execFileSync
* @param {import('@agoric/client-utils').SmartWalletKit} root0.smartWalletKit
* @param {any} root0.delay
* @param {import('@agoric/client-utils').MinimalNetworkConfig} networkConfig
*/
export const makeAgdWalletKit = async (
{ execFileSync, smartWalletKit, delay },
networkConfig,
) => {
const { agoricNames, fromBoard, marshaller, readLatestHead, vstorage } =
await makeVstorageKit({ fetch }, networkConfig);

/**
*
* @param {string} from
Expand All @@ -23,17 +28,12 @@ export const makeWalletUtils = async (
delay,
execFileSync,
from,
marshaller,
keyring: { backend: 'test' },
});
};

return {
agoricNames,
...smartWalletKit,
broadcastBridgeAction,
fromBoard,
networkConfig,
readLatestHead,
vstorage,
};
};
21 changes: 21 additions & 0 deletions a3p-integration/proposals/s:stake-bld/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4617,6 +4617,7 @@ __metadata:
agoric: "npm:dev"
ava: "npm:^5.3.1"
execa: "npm:^8.0.1"
typescript: "npm:^5.7.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -5189,6 +5190,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.7.2":
version: 5.7.2
resolution: "typescript@npm:5.7.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/a873118b5201b2ef332127ef5c63fb9d9c155e6fdbe211cbd9d8e65877283797cca76546bad742eea36ed7efbe3424a30376818f79c7318512064e8625d61622
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.1.6 - 5.6.x#optional!builtin<compat/typescript>":
version: 5.6.3
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=8c6c40"
Expand All @@ -5199,6 +5210,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.7.2#optional!builtin<compat/typescript>":
version: 5.7.2
resolution: "typescript@patch:typescript@npm%3A5.7.2#optional!builtin<compat/typescript>::version=5.7.2&hash=5786d5"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/f3b8082c9d1d1629a215245c9087df56cb784f9fb6f27b5d55577a20e68afe2a889c040aacff6d27e35be165ecf9dca66e694c42eb9a50b3b2c451b36b5675cb
languageName: node
linkType: hard

"undici-types@npm:~5.26.4":
version: 5.26.5
resolution: "undici-types@npm:5.26.5"
Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/z:acceptance/psm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@agoric/synthetic-chain';
import { waitUntilAccountFunded } from '@agoric/client-utils';
import test from 'ava';
import { NonNullish } from './test-lib/errors.js';
import { NonNullish } from '@agoric/internal/src/errors.js';
import {
adjustBalancesIfNotProvisioned,
bankSend,
Expand Down
140 changes: 0 additions & 140 deletions a3p-integration/proposals/z:acceptance/test-lib/chain.js

This file was deleted.

20 changes: 0 additions & 20 deletions a3p-integration/proposals/z:acceptance/test-lib/errors.js

This file was deleted.

15 changes: 6 additions & 9 deletions a3p-integration/proposals/z:acceptance/test-lib/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* eslint-env node */
import { makeWalletUtils } from '@agoric/client-utils';
import { makeSmartWalletKit, LOCAL_CONFIG } from '@agoric/client-utils';
import { execFileSync } from 'child_process';
import { makeAgdWalletUtils } from './wallet.js';
import { makeAgdWalletKit } from './wallet.js';

export const networkConfig = {
rpcAddrs: ['http://0.0.0.0:26657'],
chainName: 'agoriclocal',
};
export const networkConfig = LOCAL_CONFIG;

/**
* Resolve after a delay in milliseconds.
Expand All @@ -16,12 +13,12 @@ export const networkConfig = {
*/
const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms));

export const walletUtils = await makeWalletUtils(
export const smartWalletKit = await makeSmartWalletKit(
{ delay, fetch },
networkConfig,
);

export const agdWalletUtils = await makeAgdWalletUtils(
{ execFileSync, setTimeout, walletUtils },
export const agdWalletUtils = await makeAgdWalletKit(
{ execFileSync, smartWalletKit, delay },
networkConfig,
);
1 change: 1 addition & 0 deletions a3p-integration/proposals/z:acceptance/test-lib/kread.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-nocheck FIXME
// XXX uses agoric.follow to read data through spawned processes; replace with VstorageKit
import assert from 'node:assert';

import {
Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/z:acceptance/test-lib/psm-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
VALIDATORADDR,
} from '@agoric/synthetic-chain';
import fsp from 'node:fs/promises';
import { NonNullish } from './errors.js';
import { NonNullish } from '@agoric/internal/src/errors.js';
import { getBalances } from './utils.js';

/** @import {Result as ExecaResult, ExecaError} from 'execa'; */
Expand Down
Loading

0 comments on commit 8f9f075

Please sign in to comment.