Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(a3p): migrate wallet and vaults related tests from a3p-proposals to the z:acceptance #10123

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
00f9789
test(a3p): migrate wallet related test to z:acceptance
Jorge-Lopes Sep 17, 2024
3587bd3
test(a3p): extend coverage of z:acceptance wallet tests
Jorge-Lopes Sep 20, 2024
89e2a86
test(a3p): add vaults actions test cases to z:acceptance
Jorge-Lopes Sep 20, 2024
e026fc0
fix(a3p): fix typo on documentation
Jorge-Lopes Sep 20, 2024
e9215ee
fix(a3p): remove unnecessary shebang from script
Jorge-Lopes Sep 24, 2024
6fb17e5
Revert "fix(a3p): remove unnecessary shebang from script"
Jorge-Lopes Sep 24, 2024
2886370
fix(a3p): remove unnecessary shebang from script
Jorge-Lopes Sep 24, 2024
dec7783
fix(a3p): add new line to the end of script
Jorge-Lopes Sep 24, 2024
8d5ee47
fix(a3p): replace agd with makeAgd
Jorge-Lopes Sep 24, 2024
061a373
fix(a3p): use getContractInfo method to get vault data from Vstorage
Jorge-Lopes Sep 24, 2024
c3bd20e
fix(a3p): replace assertions that were using t.true()
Jorge-Lopes Sep 24, 2024
7a0a8bb
test(a3p): assert that assets were returned after closing vaults
Jorge-Lopes Sep 25, 2024
a04e0a9
fix(a3p): remove unnecessary waitForBlock calls
Jorge-Lopes Sep 25, 2024
bd97afc
fix(a3p): assert expected error message from openVault call
Jorge-Lopes Sep 25, 2024
d82267e
fix(a3p): remove only condition from test
Jorge-Lopes Sep 25, 2024
9a0e874
fix(a3p): replace JSON stringify mnemonic from q to jq
Jorge-Lopes Sep 25, 2024
7325b9c
fix(a3p): replace conversion to BigInt and rename getBalance
Jorge-Lopes Sep 27, 2024
2e76423
test(a3p): add helper function to list vaults of an address
Jorge-Lopes Sep 27, 2024
040f1e6
fix(a3p): provide expected error message as a regex to openVault call
Jorge-Lopes Sep 27, 2024
4bdb485
fix(a3p): improve description of send script
Jorge-Lopes Sep 27, 2024
f9f2660
fix(a3p): remove unnecessary message and add underscores to digits
Jorge-Lopes Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion a3p-integration/proposals/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Steps:
1. Get the upgrade branch
2. Build the submissions
3. Migrate the proposal
4. Update the `latest` iamge
4. Update the `latest` image

### Get the proposal's branch

Expand Down
97 changes: 97 additions & 0 deletions a3p-integration/proposals/z:acceptance/exitOffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Note: limit imports to node modules for portability
import { parseArgs, promisify } from 'node:util';
import { execFile } from 'node:child_process';
import { writeFile, mkdtemp, rm } from 'node:fs/promises';
import { join } from 'node:path';

const options = /** @type {const} */ ({
id: { type: 'string' },
from: { type: 'string' },
bin: { type: 'string', default: '/usr/src/agoric-sdk/node_modules/.bin' },
});

const Usage = `
Try to exit an offer, reclaiming any associated payments.

node exitOffer.js --id ID --from FROM [--bin PATH]

Options:
--id <offer id>
--from <address or key name>

--bin <path to agoric and agd> default: ${options.bin.default}
`;

const badUsage = () => {
const reason = new Error(Usage);
reason.name = 'USAGE';
throw reason;
};

const { stringify: jq } = JSON;
// limited to JSON data: no remotables/promises; no undefined.
const toCapData = data => ({ body: `#${jq(data)}`, slots: [] });

const { entries } = Object;
/**
* @param {Record<string, string>} obj - e.g. { color: 'blue' }
* @returns {string[]} - e.g. ['--color', 'blue']
*/
const flags = obj =>
entries(obj)
.map(([k, v]) => [`--${k}`, v])
.flat();

const execP = promisify(execFile);

const showAndRun = (file, args) => {
console.log('$', file, ...args);
return execP(file, args);
};

const withTempFile = async (tail, fn) => {
const tmpDir = await mkdtemp('offers-');
const tmpFile = join(tmpDir, tail);
try {
const result = await fn(tmpFile);
return result;
} finally {
await rm(tmpDir, { recursive: true, force: true }).catch(err =>
console.error(err),
);
}
};

const doAction = async (action, from) => {
await withTempFile('offer.json', async tmpOffer => {
await writeFile(tmpOffer, jq(toCapData(action)));

const out = await showAndRun('agoric', [
'wallet',
...flags({ 'keyring-backend': 'test' }),
'send',
...flags({ offer: tmpOffer, from }),
]);
return out.stdout;
});
};

const main = async (argv, env) => {
const { values } = parseArgs({ args: argv.slice(2), options });
const { id: offerId, from, bin } = values;
(offerId && from) || badUsage();

env.PATH = `${bin}:${env.PATH}`;
const action = { method: 'tryExitOffer', offerId };
const out = await doAction(action, from);
Jorge-Lopes marked this conversation as resolved.
Show resolved Hide resolved
console.log(out);
};

main(process.argv, process.env).catch(e => {
if (e.name === 'USAGE' || e.code === 'ERR_PARSE_ARGS_UNKNOWN_OPTION') {
console.error(e.message);
} else {
console.error(e);
}
process.exit(1);
});
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,33 @@
/* global E */

/// <reference types="@agoric/vats/src/core/core-eval-env"/>
/// <reference types="@agoric/vats/src/core/types-ambient"/>

/**
* The primary purpose of this script is to access the depositFacet of a given address
* via the namesByAddress and then send a payment to it.
*
* The {{ADDRESS}} placeholder should be replaced with the desired address before use.
*
* The payment in this case is an invitation to add collateral to the reserve.
* However, the use of the reserve is incidental and simply provides an easy payment to construct.
*
* see a3p-integration/proposals/z:acceptance/wallet.test.js
*
* @param {BootstrapPowers} powers
*/
const sendIt = async powers => {
const addr = '{{ADDRESS}}';
const {
consume: { namesByAddress, zoe },
instance: {
consume: { reserve },
},
} = powers;
const pf = E(zoe).getPublicFacet(reserve);
const anInvitation = await E(pf).makeAddCollateralInvitation();
const addressDepositFacet = E(namesByAddress).lookup(addr, 'depositFacet');
await E(addressDepositFacet).receive(anInvitation);
};

sendIt;
49 changes: 49 additions & 0 deletions a3p-integration/proposals/z:acceptance/test-lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { makeAgd, agops } from '@agoric/synthetic-chain';
import { execFileSync } from 'node:child_process';
import { readFile, writeFile } from 'node:fs/promises';

/**
* @param {string} fileName base file name without .tjs extension
* @param {Record<string, string>} replacements
*/
export 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);
};

const showAndExec = (file, args, opts) => {
console.log('$', file, ...args);
return execFileSync(file, args, opts);
};

// @ts-expect-error string is not assignable to Buffer
export const agd = makeAgd({ execFileSync: showAndExec }).withOpts({
keyringBackend: 'test',
});

/**
* @param {string[]} addresses
* @param {string} [targetDenom]
*/
export const getBalances = async (addresses, targetDenom = undefined) => {
const balancesList = await Promise.all(
addresses.map(async address => {
const { balances } = await agd.query(['bank', 'balances', address]);

if (targetDenom) {
const balance = balances.find(({ denom }) => denom === targetDenom);
return balance ? BigInt(balance.amount) : undefined;
}

return balances;
}),
);

return addresses.length === 1 ? balancesList[0] : balancesList;
};

export const agopsVaults = async addr =>
await agops.vaults('list', '--from', addr);
6 changes: 6 additions & 0 deletions a3p-integration/proposals/z:acceptance/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ yarn ava valueVow.test.js
echo ACCEPTANCE TESTING state sync
./state-sync-snapshots-test.sh
./genesis-test.sh

echo ACCEPTANCE TESTING wallet
yarn ava wallet.test.js

echo ACCEPTANCE TESTING vaults
Jorge-Lopes marked this conversation as resolved.
Show resolved Hide resolved
yarn ava vaults.test.js
Loading
Loading