Skip to content

Commit

Permalink
test(a3p): add helper function to list vaults of an address
Browse files Browse the repository at this point in the history
- Address review comments from Agoric#10123
- Comment: Agoric#10123 (comment)
  • Loading branch information
Jorge-Lopes committed Sep 27, 2024
1 parent 2afeb25 commit b98e148
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 4 additions & 1 deletion a3p-integration/proposals/z:acceptance/test-lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeAgd } from '@agoric/synthetic-chain';
import { makeAgd, agops } from '@agoric/synthetic-chain';
import { execFileSync } from 'node:child_process';
import { readFile, writeFile } from 'node:fs/promises';

Expand Down Expand Up @@ -44,3 +44,6 @@ export const getBalances = async (addresses, targetDenom = undefined) => {

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

export const agopsVaults = async addr =>
await agops.vaults('list', '--from', addr);
27 changes: 13 additions & 14 deletions a3p-integration/proposals/z:acceptance/vaults.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import test from 'ava';
import {
agops,
agoric,
bankSend,
getUser,
Expand All @@ -13,10 +12,10 @@ import {
USER1ADDR,
waitForBlock,
} from '@agoric/synthetic-chain';
import { getBalances } from './test-lib/utils.js';
import { getBalances, agopsVaults } from './test-lib/utils.js';

test.serial('attempt to open vaults under the minimum amount', async t => {
const activeVaultsBefore = await agops.vaults('list', '--from', USER1ADDR);
const activeVaultsBefore = await agopsVaults(USER1ADDR);
await bankSend(USER1ADDR, `20000000${ATOM_DENOM}`);
t.log('active vaults before:', activeVaultsBefore);

Expand All @@ -33,7 +32,7 @@ test.serial('attempt to open vaults under the minimum amount', async t => {
'Error message does not contain the expected text',
);

const activeVaultsAfter = await agops.vaults('list', '--from', USER1ADDR);
const activeVaultsAfter = await agopsVaults(USER1ADDR);
t.log('active vaults after:', activeVaultsAfter);

t.true(
Expand All @@ -44,7 +43,7 @@ test.serial('attempt to open vaults under the minimum amount', async t => {

test.serial('open new vault', async t => {
const istBalanceBefore = await getISTBalance(USER1ADDR);
const activeVaultsBefore = await agops.vaults('list', '--from', USER1ADDR);
const activeVaultsBefore = await agopsVaults(USER1ADDR);
t.log('uist balance before:', istBalanceBefore);
t.log('active vaults before:', activeVaultsBefore);

Expand All @@ -55,7 +54,7 @@ test.serial('open new vault', async t => {
await openVault(USER1ADDR, mint, collateral);

const istBalanceAfter = await getISTBalance(USER1ADDR);
const activeVaultsAfter = await agops.vaults('list', '--from', USER1ADDR);
const activeVaultsAfter = await agopsVaults(USER1ADDR);
t.log('uist balance after:', istBalanceAfter);
t.log('active vaults after:', activeVaultsAfter);

Expand All @@ -72,7 +71,7 @@ test.serial('open new vault', async t => {
});

test.serial('remove collateral', async t => {
const activeVaults = await agops.vaults('list', '--from', USER1ADDR);
const activeVaults = await agopsVaults(USER1ADDR);
const vaultPath = activeVaults[activeVaults.length - 1];
const vaultID = vaultPath.split('.').pop();

Expand All @@ -96,7 +95,7 @@ test.serial('remove collateral', async t => {
});

test.serial('remove IST', async t => {
const activeVaults = await agops.vaults('list', '--from', USER1ADDR);
const activeVaults = await agopsVaults(USER1ADDR);
const vaultPath = activeVaults[activeVaults.length - 1];
const vaultID = vaultPath.split('.').pop();

Expand All @@ -119,7 +118,7 @@ test.serial('remove IST', async t => {
});

test.serial('close vault', async t => {
const activeVaults = await agops.vaults('list', '--from', USER1ADDR);
const activeVaults = await agopsVaults(USER1ADDR);
const vaultPath = activeVaults[activeVaults.length - 1];
const vaultID = vaultPath.split('.').pop();

Expand Down Expand Up @@ -152,15 +151,15 @@ test.serial('open second vault', async t => {
const user2Address = await getUser('user2');
await bankSend(user2Address, `20000000${ATOM_DENOM}`);

const activeVaultsBefore = await agops.vaults('list', '--from', user2Address);
const activeVaultsBefore = await agopsVaults(user2Address);
t.log('active vaults before:', activeVaultsBefore);

const mint = '7.0';
const collateral = '11.0';
await openVault(user2Address, mint, collateral);
await waitForBlock();

const activeVaultsAfter = await agops.vaults('list', '--from', user2Address);
const activeVaultsAfter = await agopsVaults(user2Address);
t.log('active vaults after:', activeVaultsAfter);

t.is(
Expand All @@ -172,7 +171,7 @@ test.serial('open second vault', async t => {

test.serial('add collateral', async t => {
const user2Address = await getUser('user2');
const activeVaults = await agops.vaults('list', '--from', user2Address);
const activeVaults = await agopsVaults(user2Address);
const vaultPath = activeVaults[activeVaults.length - 1];
const vaultID = vaultPath.split('.').pop();

Expand All @@ -196,7 +195,7 @@ test.serial('add collateral', async t => {

test.serial('add IST', async t => {
const user2Address = await getUser('user2');
const activeVaults = await agops.vaults('list', '--from', user2Address);
const activeVaults = await agopsVaults(user2Address);
const vaultPath = activeVaults[activeVaults.length - 1];
const vaultID = vaultPath.split('.').pop();

Expand All @@ -220,7 +219,7 @@ test.serial('add IST', async t => {

test.serial('close second vault', async t => {
const user2Address = await getUser('user2');
const activeVaults = await agops.vaults('list', '--from', user2Address);
const activeVaults = await agopsVaults(user2Address);
const vaultPath = activeVaults[activeVaults.length - 1];
const vaultID = vaultPath.split('.').pop();

Expand Down

0 comments on commit b98e148

Please sign in to comment.