Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Dec 18, 2024
1 parent e23d803 commit 1fa65c9
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions .github/scripts/createVault.mjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
import { execa } from 'execa';
import fs from 'fs';

const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops';

const createVault = async (containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral) => {
const createVault = async (containerName, agoricNet, userKey, wantMinted, giveCollateral) => {
console.log('Starting the vault creation process...');

if (!containerName || !agoricNet || !commandTimeout || !userKey || !wantMinted || !giveCollateral) {
console.error('Error: Missing one or more required parameters:', {
containerName,
agoricNet,
commandTimeout,
userKey,
wantMinted,
giveCollateral,
});
process.exit(1);
}

const createVaultCommand = `${agops} vaults open --wantMinted \"${wantMinted}\" --giveCollateral \"${giveCollateral}\" > /tmp/want-ist.json`;
const executeCreateVaultCommand = `docker exec ${containerName} /bin/bash -c "env AGORIC_NET=${agoricNet} timeout ${commandTimeout} ${createVaultCommand}"`;

try {
console.log(`Executing: ${executeCreateVaultCommand}`);
const { stdout: createVaultOutput } = await execa(executeCreateVaultCommand);
console.log('Vault creation output:', createVaultOutput);

console.log('Executing broadcast command...');
const broadcastCommand = `timeout ${commandTimeout} ${agops} perf satisfaction --executeOffer /tmp/want-ist.json --from ${userKey} --keyring-backend=test`;
const executeBroadcastCommand = `docker exec ${containerName} bash -c "env AGORIC_NET=${agoricNet} ${broadcastCommand}"`;
const env = {
AGORIC_NET: agoricNet,
};

const { stdout } = await execa(
'docker',
['exec', containerName, agops, 'vaults', 'open', '--wantMinted', wantMinted, '--giveCollateral', giveCollateral],
{ env },
);

fs.writeFileSync('/tmp/want-ist.json', stdout);
console.log('Vault creation output:', stdout);

const { stdout: broadcastOutput } = await execa(
'docker',
[
'exec',
containerName,
agops,
'perf',
'satisfaction',
'--executeOffer',
'/tmp/want-ist.json',
'--from',
userKey,
'--keyring-backend=test',
],
{ env, shell: true },
);

const { stdout: broadcastOutput } = await execa(executeBroadcastCommand);
console.log('Broadcast output:', broadcastOutput);
} catch (error) {
console.error('Error during vault creation:', error);
Expand All @@ -39,9 +46,8 @@ const createVault = async (containerName, agoricNet, commandTimeout, userKey, wa

const containerName = process.env.containerName;
const agoricNet = process.env.agoricNet;
const commandTimeout = process.env.commandTimeout;
const userKey = process.env.userKey;
const wantMinted = process.env.wantMinted;
const giveCollateral = process.env.giveCollateral;

createVault(containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral);
createVault(containerName, agoricNet, userKey, wantMinted, giveCollateral);

0 comments on commit 1fa65c9

Please sign in to comment.