Skip to content

Commit

Permalink
test(a3p-integration): Update "swap into IST" to force the default ga…
Browse files Browse the repository at this point in the history
…s limit
  • Loading branch information
gibson042 committed Nov 12, 2024
1 parent 0389a21 commit 1369e6b
Show file tree
Hide file tree
Showing 5 changed files with 999 additions and 28 deletions.
1 change: 1 addition & 0 deletions a3p-integration/proposals/z:acceptance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@endo/far": "^1.1.5",
"@endo/init": "^1.1.4",
"@endo/marshal": "^1.5.3",
"agoric": "dev",
"ava": "^6.1.2",
"execa": "^9.3.1",
"tsx": "^4.17.0"
Expand Down
5 changes: 3 additions & 2 deletions a3p-integration/proposals/z:acceptance/psm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
initializeNewUser,
maxMintBelowLimit,
psmSwap,
sendOfferAgd,
} from './test-lib/psm-lib.js';
import { getBalances } from './test-lib/utils.js';

Expand Down Expand Up @@ -128,7 +129,7 @@ test.serial('initialize new user', async t => {
t.pass();
});

test.serial('swap into IST', async t => {
test.serial('swap into IST using agd with default gas', async t => {
const {
newUser: { name },
anchor,
Expand Down Expand Up @@ -161,7 +162,7 @@ test.serial('swap into IST', async t => {
'--feePct',
wantMintedFeeVal,
],
psmSwapIo,
{ ...psmSwapIo, sendOffer: sendOfferAgd },
);

await checkSwapSucceeded(t, metricsBefore, balancesBefore, {
Expand Down
56 changes: 52 additions & 4 deletions a3p-integration/proposals/z:acceptance/test-lib/psm-lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env node */

import { getNetworkConfig } from 'agoric/src/helpers.js';
import {
boardSlottingMarshaller,
makeFromBoard,
Expand Down Expand Up @@ -390,21 +391,68 @@ export const sendOfferAgoric = async (address, offerPromise) => {
]);
};

/**
* A variant of {@link sendOfferAgoric} that uses `agd` directly to e.g.
* control gas calculation.
*
* @param {string} address
* @param {Promise<string>} offerPromise
* @returns {Promise<CommandResult>}
*/
export const sendOfferAgd = async (address, offerPromise) => {
const offer = await offerPromise;
const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const { chainName, rpcAddrs } = networkConfig;
const args = [
`--node=${rpcAddrs[0]}`,
`--chain-id=${chainName}`,
`--keyring-backend=test`,
`--from=${address}`,
'tx',
'swingset',
'wallet-action',
'--allow-spend',
offer,
'-bblock',
'--yes',
'-ojson',
];
const result = await runCommand('agd', args);
// Mimic --verbose
// https://github.com/Agoric/agoric-sdk/blob/master/packages/agoric-cli/src/lib/wallet.js
if (result.status === 0 && !result.signal && !result.error) {
const out = result.stdout.toString();
try {
const tx = JSON.parse(out);
if (tx.code !== 0) {
console.error('failed to send tx', tx);
return { ...result, error: Error(`code ${tx.code}`) };
}
console.log(tx);
} catch (err) {
console.error('unexpected output', JSON.stringify(out));
return { ...result, error: err };
}
}
return result;
};

/**
* @param {string} address
* @param {Array<any>} params
* @param {{
* follow: (...params: string[]) => Promise<object>;
* sendOffer?: (address: string, offerPromise: Promise<string>) => Promise<CommandResult>;
* setTimeout: typeof global.setTimeout;
* now: () => number
* }} io
*/
export const psmSwap = async (address, params, io) => {
const now = io.now();
const offerId = `${address}-psm-swap-${now}`;
const { now, sendOffer = sendOfferAgoric, ...waitIO } = io;
const offerId = `${address}-psm-swap-${now()}`;
const newParams = ['psm', ...params, '--offerId', offerId];
const offerPromise = executeCommand(agopsLocation, newParams);
const sendResult = await sendOfferAgoric(address, offerPromise);
const sendResult = await sendOffer(address, offerPromise);
const { status, stdout, stderr, signal, error } = sendResult;
if (status !== 0 || signal || error) {
console.error('psmSwap tx send failed', commandResultData(sendResult));
Expand All @@ -415,7 +463,7 @@ export const psmSwap = async (address, params, io) => {
}
console.log('psmSwap tx send results', stdout.toString(), stderr.toString());

await waitUntilOfferResult(address, offerId, true, io, {
await waitUntilOfferResult(address, offerId, true, waitIO, {
errorMessage: `${offerId} not succeeded`,
});
};
Expand Down
Loading

0 comments on commit 1369e6b

Please sign in to comment.