diff --git a/a3p-integration/proposals/s:stake-bld/stakeBld.test.js b/a3p-integration/proposals/s:stake-bld/stakeBld.test.js index 549e4562545..13836f6cf3d 100644 --- a/a3p-integration/proposals/s:stake-bld/stakeBld.test.js +++ b/a3p-integration/proposals/s:stake-bld/stakeBld.test.js @@ -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; @@ -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', @@ -50,7 +51,7 @@ test('basic', async t => { }, }); - await walletUtils.broadcastBridgeAction(GOV1ADDR, { + await agdWalletUtils.broadcastBridgeAction(GOV1ADDR, { method: 'executeOffer', offer: { id: 'request-delegate-6', @@ -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', diff --git a/a3p-integration/proposals/s:stake-bld/test-lib/index.js b/a3p-integration/proposals/s:stake-bld/test-lib/index.js index 9c22b218e19..17fa62f6f75 100644 --- a/a3p-integration/proposals/s:stake-bld/test-lib/index.js +++ b/a3p-integration/proposals/s:stake-bld/test-lib/index.js @@ -1,9 +1,9 @@ /* eslint-env node */ +import { makeWalletUtils, 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 { makeAgdWalletUtils } from './wallet.js'; -export { networkConfig }; +export const networkConfig = LOCAL_CONFIG; /** * Resolve after a delay in milliseconds. @@ -14,6 +14,11 @@ export { networkConfig }; const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms)); export const walletUtils = await makeWalletUtils( - { execFileSync, delay, fetch }, + { delay, fetch }, + networkConfig, +); + +export const agdWalletUtils = await makeAgdWalletUtils( + { execFileSync, walletUtils, delay }, networkConfig, ); diff --git a/a3p-integration/proposals/s:stake-bld/test-lib/wallet.js b/a3p-integration/proposals/s:stake-bld/test-lib/wallet.js index e3ef23af929..4329b269ab6 100644 --- a/a3p-integration/proposals/s:stake-bld/test-lib/wallet.js +++ b/a3p-integration/proposals/s:stake-bld/test-lib/wallet.js @@ -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').WalletUtils} root0.walletUtils + * @param {any} root0.delay + * @param {import('@agoric/client-utils').MinimalNetworkConfig} networkConfig + */ +export const makeAgdWalletUtils = async ( + { execFileSync, walletUtils, delay }, networkConfig, ) => { - const { agoricNames, fromBoard, marshaller, readLatestHead, vstorage } = - await makeVstorageKit({ fetch }, networkConfig); - /** * * @param {string} from @@ -23,17 +28,12 @@ export const makeWalletUtils = async ( delay, execFileSync, from, - marshaller, keyring: { backend: 'test' }, }); }; return { - agoricNames, + ...walletUtils, broadcastBridgeAction, - fromBoard, - networkConfig, - readLatestHead, - vstorage, }; }; diff --git a/a3p-integration/proposals/z:acceptance/test-lib/index.js b/a3p-integration/proposals/z:acceptance/test-lib/index.js index 82e2f302020..17fa62f6f75 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/index.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/index.js @@ -19,6 +19,6 @@ export const walletUtils = await makeWalletUtils( ); export const agdWalletUtils = await makeAgdWalletUtils( - { execFileSync, setTimeout, walletUtils }, + { execFileSync, walletUtils, delay }, networkConfig, ); diff --git a/a3p-integration/proposals/z:acceptance/test-lib/wallet.js b/a3p-integration/proposals/z:acceptance/test-lib/wallet.js index d19d09d0012..4329b269ab6 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/wallet.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/wallet.js @@ -1,73 +1,21 @@ -// TODO DRY in https://github.com/Agoric/agoric-sdk/issues/9109 // @ts-check -/* global */ +import { sendAction } from 'agoric/src/lib/index.js'; import { inspect } from 'util'; -import { execSwingsetTransaction, pollTx } from './chain.js'; -import { makeTimerUtils } from './utils.js'; - -/** - * Sign and broadcast a wallet-action. - * - * @throws { Error & { code: number } } if transaction fails - * @param {import('@agoric/smart-wallet/src/smartWallet.js').BridgeAction} bridgeAction - * @param {import('@agoric/client-utils').MinimalNetworkConfig & { - * from: string, - * marshaller: Pick, 'toCapData'>, - * fees?: string, - * verbose?: boolean, - * keyring?: {home?: string, backend: string}, - * stdout?: Pick, - * execFileSync: typeof import('child_process').execFileSync, - * delay: (ms: number) => Promise, - * dryRun?: boolean, - * }} opts - */ -export const sendAction = async (bridgeAction, opts) => { - const { marshaller } = opts; - const offerBody = JSON.stringify(marshaller.toCapData(harden(bridgeAction))); - - // tryExit should not require --allow-spend - // https://github.com/Agoric/agoric-sdk/issues/7291 - const spendMethods = ['executeOffer', 'tryExitOffer']; - const spendArg = spendMethods.includes(bridgeAction.method) - ? ['--allow-spend'] - : []; - - const act = ['wallet-action', ...spendArg, offerBody]; - const out = execSwingsetTransaction([...act, '--output', 'json'], opts); - if (opts.dryRun) { - return; - } - - assert(out); // not dry run - const tx = JSON.parse(out); - if (tx.code !== 0) { - const err = Error(`failed to send tx: ${tx.raw_log} code: ${tx.code}`); - // @ts-expect-error XXX how to add properties to an error? - err.code = tx.code; - throw err; - } - - return pollTx(tx.txhash, opts); -}; /** * Stop-gap using execFileSync until we have a pure JS signing client. * * @param {object} root0 - * @param {import('@agoric/client-utils').WalletUtils} root0.walletUtils * @param {import('child_process')['execFileSync']} root0.execFileSync - * @param {typeof setTimeout} root0.setTimeout + * @param {import('@agoric/client-utils').WalletUtils} root0.walletUtils + * @param {any} root0.delay * @param {import('@agoric/client-utils').MinimalNetworkConfig} networkConfig */ export const makeAgdWalletUtils = async ( - { execFileSync, walletUtils, setTimeout }, + { execFileSync, walletUtils, delay }, networkConfig, ) => { - const { marshaller } = walletUtils; - - const { delay } = await makeTimerUtils({ setTimeout }); /** * * @param {string} from @@ -80,12 +28,12 @@ export const makeAgdWalletUtils = async ( delay, execFileSync, from, - marshaller, keyring: { backend: 'test' }, }); }; return { + ...walletUtils, broadcastBridgeAction, }; };