Skip to content

Commit

Permalink
SQUASHME: update usage: inter-tool bid list
Browse files Browse the repository at this point in the history
to match spec
  • Loading branch information
dckc committed Jul 12, 2023
1 parent 1bcf8d6 commit fe02449
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 31 deletions.
14 changes: 9 additions & 5 deletions packages/inter-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ const fmtBid = (bid, fmt) => {
*
* @typedef {import('@cosmjs/tendermint-rpc').RpcClient} RpcClient
*/
export const addAuctionCommand = (
export const addBidCommand = (
interCmd,
{ tui, getBatchQuery, makeRpcClient },
) => {
const auctionCmd = interCmd.command('auction').description('auction queries');
const bidCmd = interCmd
.command('bid')
.description('Add a Bid command/operation');

const makeBoard = () => getBatchQuery().then(makeBoardClient);

auctionCmd
.command('list-bids')
.description('XXX TODO list desc')
bidCmd
.command('list')
.description('List Bids operation')
.option('--book', 'auction book number', Number, 0)
.action(async (/** @type {{book: number}} */ { book }) => {
const bidsPart = 'schedule'; // XXX something goofy is going on in the contract
Expand All @@ -137,4 +139,6 @@ export const addAuctionCommand = (
tui.show(fmtBid(bid, fmt));
}
});

return bidCmd;
};
4 changes: 2 additions & 2 deletions packages/inter-cli/src/commands/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { makeVstorageQueryService } from '../lib/vstorage.js';
* @param {ReturnType<import('../lib/agd-lib').makeAgd>} io.agd
* @param {() => Promise<import('@cosmjs/tendermint-rpc').RpcClient>} io.makeRpcClient
*/
export const addBidCommand = (interCmd, { tui, agd, makeRpcClient }) => {
export const addBidCommand0 = (interCmd, { tui, agd, makeRpcClient }) => {
const bidCmd = interCmd
.command('bid')
.command('bid0')
.description('auction bidding commands');

/** @param {string} literalOrName */
Expand Down
46 changes: 25 additions & 21 deletions packages/inter-cli/src/inter-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import { makeHttpClient } from '@agoric/casting/src/makeHttpClient.js';

import { makeTUI } from './lib/tui.js';
import { makeAgd } from './lib/agd-lib.js';
import { addBidCommand } from './commands/bid.js';
import { addAuctionCommand } from './commands/auction.js';
import { addBidCommand0 } from './commands/bid.js';
import { addBidCommand } from './commands/auction.js';
import { getNetworkConfig } from './lib/networkConfig.js';
import { makeBatchQuery } from './lib/vstorage.js';

const { Fail } = assert;

const assertUint32 = x =>
(Number.isSafeInteger(x) && x >= 0 && x < 2 ** 32) ||
Fail`${x} is not a valid uint32`;
// const assertUint32 = x =>
// (Number.isSafeInteger(x) && x >= 0 && x < 2 ** 32) ||
// Fail`${x} is not a valid uint32`;

/**
* Create and run the inter command,
Expand All @@ -35,6 +35,8 @@ const main = () => {

const { env } = process;
let config;
// NOTE: delay getNetworkConfig() and all other I/O
// until a command .action() is run
const provideConfig = async () => {
await null;
if (config) return config;
Expand All @@ -52,25 +54,27 @@ const main = () => {
return makeHttpClient(rpcAddr, globalThis.fetch);
});

const interCmd = createCommand('inter')
.description('Inter Protocol commands for liquidation bidding etc.')
.option('--home <dir>', 'agd CosmosSDK application home directory')
.option(
'--keyring-backend <os|file|test>',
`keyring's backend (os|file|test) (default "${
env.AGORIC_KEYRING_BACKEND || 'os'
}")`,
env.AGORIC_KEYRING_BACKEND,
);
const interCmd = createCommand('inter-tool').description(
'Inter Protocol auction bid query',
);
// TODO: commands involving signing
// .option('--home <dir>', 'agd CosmosSDK application home directory')
// .option(
// '--keyring-backend <os|file|test>',
// `keyring's backend (os|file|test) (default "${
// env.AGORIC_KEYRING_BACKEND || 'os'
// }")`,
// env.AGORIC_KEYRING_BACKEND,
// );

const { now } = Date;
const makeTimeout = delay =>
assertUint32(delay) &&
new Promise(resolve => globalThis.setTimeout(resolve, delay));
// const { now } = Date;
// const makeTimeout = delay =>
// assertUint32(delay) &&
// new Promise(resolve => globalThis.setTimeout(resolve, delay));

const agd = makeAgd({ execFileSync });
addBidCommand(interCmd, { tui, makeRpcClient, agd });
addAuctionCommand(interCmd, { tui, getBatchQuery, makeRpcClient });
addBidCommand0(interCmd, { tui, makeRpcClient, agd });
addBidCommand(interCmd, { tui, getBatchQuery, makeRpcClient });

return Promise.resolve(interCmd.parseAsync(process.argv)).catch(err => {
if (err instanceof CommanderError) {
Expand Down
52 changes: 49 additions & 3 deletions packages/inter-cli/test/test-auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

import { QueryDataResponse } from '@agoric/cosmic-proto/vstorage/query.js';
import { toBase64 } from '@cosmjs/encoding';
import { addAuctionCommand } from '../src/commands/auction.js';
import { addBidCommand } from '../src/commands/auction.js';
import { listBidsRPC } from './rpc-fixture.js';
import { extractCapData } from '../src/lib/boardClient.js';
import { makeBatchQuery } from '../src/lib/vstorage.js';
Expand All @@ -32,6 +32,48 @@ test.before(async t => {
t.context = await makeTestContext();
});

/** @typedef {import('commander').Command} Command */

/** @type {(c: Command) => Command[]} */
const subCommands = c => [c, ...c.commands.flatMap(subCommands)];

const usageTest = (words, blurb = 'Command usage:') => {
test(`FR5: Usage: ${words}`, async t => {
const argv = `node ${words} --help`.split(' ');

const out = [];
const tui = {
show: (info, _pretty) => {
out.push(info);
},
warn: () => {},
};
const program = createCommand('inter-tool');
const { context: io } = t;
const rpcClient = makeHttpClient('', io.fetch);
const cmd = addBidCommand(program, {
tui,
getBatchQuery: async () => makeBatchQuery(io.fetch, []),
makeRpcClient: async () => rpcClient,
});
for (const c of subCommands(program)) {
c.exitOverride();
}
cmd.configureOutput({
writeOut: s => out.push(s),
writeErr: s => out.push(s),
});

await t.throwsAsync(program.parseAsync(argv), { message: /outputHelp/ });
t.snapshot(out.join('').trim(), blurb);
});
};
usageTest('inter-tool --help');
usageTest('inter-tool bid --help');
usageTest('inter-tool bid list --help');

test.todo('FR5: --asset');

/**
* Decode JSON RPC response value from base64 etc.
*
Expand Down Expand Up @@ -90,7 +132,7 @@ const encodeDetail = webMap => {
};

test('inter auction list-bids', async t => {
const args = 'node inter auction list-bids';
const args = 'node inter-tool bid list';
const expected = [
{
timestamp: '2023-07-11T17:49:18.000Z',
Expand Down Expand Up @@ -118,6 +160,7 @@ test('inter auction list-bids', async t => {
const out = [];
const tui = {
show: (info, _pretty) => {
t.log(JSON.stringify(info));
out.push(info);
},
warn: () => {},
Expand All @@ -134,7 +177,7 @@ test('inter auction list-bids', async t => {
const rpcClient = makeHttpClient(config.rpcAddrs[0], fetchMock);

const prog = createCommand('inter');
addAuctionCommand(prog, {
addBidCommand(prog, {
tui,
getBatchQuery: async () => makeBatchQuery(fetchMock, config.rpcAddrs),
makeRpcClient: async () => rpcClient,
Expand All @@ -157,3 +200,6 @@ test('inter auction list-bids', async t => {
}
t.deepEqual(out, expected);
});

test.todo('FR3: show partially filled bids');
test.todo('FR5: --from-bidder, --from-everyone');

0 comments on commit fe02449

Please sign in to comment.