Skip to content

Commit

Permalink
chore(upgrade-test): add test of auto-provision
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Dec 6, 2023
1 parent d372433 commit 3be8224
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ import { promises as fs } from 'fs';
import * as path from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { voteLatestProposalAndWait } from '../commonUpgradeHelpers.js';
import { CHAINID, GOV1ADDR, VALIDATORADDR } from '../constants.js';
import { getUser, voteLatestProposalAndWait } from '../commonUpgradeHelpers.js';
import { CHAINID, GOV1ADDR, HOME, VALIDATORADDR } from '../constants.js';
import { agd, bundleSource } from '../cliHelper.js';

const directoryName = dirname(fileURLToPath(import.meta.url));

export const addUser = async user => {
const userKeyData = await agd.keys('add', user, '--keyring-backend=test');
await fs.writeFile(`${HOME}/.agoric/${user}.key`, userKeyData.mnemonic);

const userAddress = await getUser(user);
return userAddress;
};

export const getISTBalance = async (addr, denom = 'uist', unit = 1_000_000) => {
const coins = await agd.query('bank', 'balances', addr);
const coin = coins.balances.find(a => a.denom === denom);
return Number(coin.amount) / unit;
};

export const installBundles = async bundlesData => {
const bundleIds = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
import test from 'ava';

import { agops } from '../cliHelper.js';
import { GOV1ADDR } from '../constants.js';
import { adjustVault, closeVault, mintIST, openVault } from '../econHelpers.js';
import { agd } from '../cliHelper.js';
import { ATOM_DENOM, CHAINID, GOV1ADDR } from '../constants.js';
import { addUser, getISTBalance } from './actions.js';
import { mintIST, openVault } from '../econHelpers.js';
import { waitForBlock } from '../commonUpgradeHelpers.js';

test.before(async t => {
await mintIST(GOV1ADDR, 12340000000, 10000, 2000);

await waitForBlock(2);
const userAddress = await addUser('user-auto');
await agd.tx(
'bank',
'send',
'gov1',
userAddress,
`1000000uist,2100000000${ATOM_DENOM}`,
'--from',
GOV1ADDR,
'--chain-id',
CHAINID,
'--keyring-backend',
'test',
'--yes',
);
t.context = { userAddress };
await waitForBlock(2);
});

test.skip('Open Vaults', async t => {
const currentVaults = await agops.vaults('list', '--from', GOV1ADDR);
t.is(currentVaults.length, 5);
test('Open Vaults with auto-provisioned wallet', async t => {
const { userAddress } = /** @type {{userAddress: string}} */ (t.context);
t.is(await getISTBalance(userAddress), 1);

const ATOMGiven = 2000;
const ISTWanted = 400;
await openVault(userAddress, ISTWanted, ATOMGiven);

await waitForBlock(2);

// TODO get as return value from openVault
const vaultId = 'vault6';
await openVault(GOV1ADDR, 7, 11);
await adjustVault(GOV1ADDR, vaultId, { giveMinted: 1.5 });
await adjustVault(GOV1ADDR, vaultId, { giveCollateral: 2.0 });
await closeVault(GOV1ADDR, vaultId, 5.75);
const newISTBalance = await getISTBalance(userAddress);
console.log('New IST Balance in u13 account:', newISTBalance);
t.true(newISTBalance >= ISTWanted, 'Got the wanted IST');
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ export const mintIST = async (addr, sendValue, giveCollateral, wantMinted) => {
'test',
'--yes',
);
await openVault(addr, giveCollateral, wantMinted);
await openVault(addr, wantMinted, giveCollateral);
};
15 changes: 5 additions & 10 deletions packages/deployment/upgrade-test/upgrade-test-scripts/env_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,11 @@ newOfferId() {

printKeys() {
echo "========== GOVERNANCE KEYS =========="
echo "gov1: $GOV1ADDR"
cat ~/.agoric/gov1.key || true
echo "gov2: $GOV2ADDR"
cat ~/.agoric/gov2.key || true
echo "gov3: $GOV3ADDR"
cat ~/.agoric/gov3.key || true
echo "validator: $VALIDATORADDR"
cat ~/.agoric/validator.key || true
echo "user1: $USER1ADDR"
cat ~/.agoric/user1.key || true
for i in ~/.agoric/*.key; do
name=$(basename $i .key)
echo "$name:"$'\t'$(agd keys add $name --dry-run --recover --keyring-backend=test --output=json < $i | jq -r .address) || true
echo $'\t'$(cat $i)
done
echo "========== GOVERNANCE KEYS =========="
}

Expand Down

0 comments on commit 3be8224

Please sign in to comment.