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

fix: handle missing schedule fields in inter auction status #7787

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 14 additions & 4 deletions packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { makeOfferSpecShape } from '@agoric/inter-protocol/src/auction/auctionBo
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { objectMap } from '@agoric/internal';
import { M, matches } from '@agoric/store';

// XXX scare away ambient type zombies to fix ScheduleNotification.activeStartTime etc.
// https://github.com/Agoric/agoric-sdk/issues/6512
// https://github.com/Agoric/agoric-sdk/issues/6343
import '@agoric/inter-protocol/src/vaultFactory/types.js';

import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js';
import {
asBoardRemote,
Expand Down Expand Up @@ -64,8 +70,12 @@ const makeFormatters = assets => {
const discount = r =>
r4(100 - (Number(r.numerator.value) / Number(r.denominator.value)) * 100);

/** @param {import('@agoric/time/src/types.js').TimestampRecord} tr */
const absTime = tr => new Date(Number(tr.absValue) * 1000).toISOString();
// XXX real TimeMath.absValue requires real Remotable timerBrand
/** @param {import('@agoric/time/src/types.js').Timestamp} ts */
const absValue = ts => (typeof ts === 'bigint' ? ts : ts.absValue);

/** @param {import('@agoric/time/src/types.js').Timestamp} tr */
const absTime = tr => new Date(Number(absValue(tr)) * 1000).toISOString();
/** @param {import('@agoric/time/src/types.js').RelativeTimeRecord} tr */
const relTime = tr =>
new Date(Number(tr.relValue) * 1000).toISOString().slice(11, 19);
Expand Down Expand Up @@ -290,8 +300,8 @@ inter auction status
const info = {
schedule: {
activeStartTime: fmt.absTimeOpt(schedule.activeStartTime),
nextStartTime: fmt.absTime(schedule.nextStartTime),
nextDescendingStepTime: fmt.absTime(
nextStartTime: fmt.absTimeOpt(schedule.nextStartTime),
nextDescendingStepTime: fmt.absTimeOpt(
schedule.nextDescendingStepTime,
),
},
Expand Down
152 changes: 88 additions & 64 deletions packages/agoric-cli/test/test-inter-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,84 +445,108 @@ test('README: inter auction status', async t => {

const { brand } = agoricNames;
const timerBrand = brand.timer;
const net = makeNet({
...publishedNames,
auction: {
schedule: {
_: {
activeStartTime: undefined,
nextDescendingStepTime: { absValue: 1681875302n, timerBrand },
nextStartTime: { absValue: 1681875302n, timerBrand },
const auctionInfo = {
schedule: {
_: {
activeStartTime: undefined,
nextDescendingStepTime: { absValue: 1681875302n, timerBrand },
nextStartTime: { absValue: 1681875302n, timerBrand },
},
},
book0: {
_: {
collateralAvailable: { brand: brand.ATOM, value: 0n },
currentPriceLevel: {
denominator: { brand: brand.ATOM, value: 10000000000n },
numerator: { brand: brand.IST, value: 44955000000n },
},
proceedsRaised: undefined,
remainingProceedsGoal: null,
startCollateral: { brand: brand.ATOM, value: 0n },
startPrice: {
denominator: { brand: brand.ATOM, value: 1000000n },
numerator: { brand: brand.IST, value: 9990000n },
},
startProceedsGoal: null,
},
book0: {
_: {
collateralAvailable: { brand: brand.ATOM, value: 0n },
currentPriceLevel: {
denominator: { brand: brand.ATOM, value: 10000000000n },
numerator: { brand: brand.IST, value: 44955000000n },
},
governance: {
_: {
current: {
AuctionStartDelay: {
type: 'relativeTime',
value: { relValue: 2n, timerBrand },
},
proceedsRaised: undefined,
remainingProceedsGoal: null,
startCollateral: { brand: brand.ATOM, value: 0n },
startPrice: {
denominator: { brand: brand.ATOM, value: 1000000n },
numerator: { brand: brand.IST, value: 9990000n },
ClockStep: {
type: 'relativeTime',
value: { relValue: 10n, timerBrand },
},
startProceedsGoal: null,
},
},
governance: {
_: {
current: {
AuctionStartDelay: {
type: 'relativeTime',
value: { relValue: 2n, timerBrand },
},
ClockStep: {
type: 'relativeTime',
value: { relValue: 10n, timerBrand },
},
DiscountStep: { type: 'nat', value: 500n },
Electorate: {
type: 'invitation',
value: {
brand: brand.Invitation,
value: [
{
description: 'questionPoser',
handle: {},
installation: {},
instance: {},
},
],
},
},
LowestRate: {
type: 'nat',
value: 4500n,
},
PriceLockPeriod: {
type: 'relativeTime',
value: { relValue: 60n, timerBrand },
},
StartFrequency: {
type: 'relativeTime',
value: { relValue: 300n, timerBrand },
},
StartingRate: {
type: 'nat',
value: 10500n,
DiscountStep: { type: 'nat', value: 500n },
Electorate: {
type: 'invitation',
value: {
brand: brand.Invitation,
value: [
{
description: 'questionPoser',
handle: {},
installation: {},
instance: {},
},
],
},
},
LowestRate: {
type: 'nat',
value: 4500n,
},
PriceLockPeriod: {
type: 'relativeTime',
value: { relValue: 60n, timerBrand },
},
StartFrequency: {
type: 'relativeTime',
value: { relValue: 300n, timerBrand },
},
StartingRate: {
type: 'nat',
value: 10500n,
},
},
},
},
};
const net = makeNet({
...publishedNames,
auction: auctionInfo,
});

const cmd = await makeInterCommand(makeProcess(t, testKeyring, out), net);
await cmd.parseAsync(argv);
t.deepEqual(JSON.parse(out.join('')), expected);

// schedule fields can be null
const auctionInfo2 = {
...auctionInfo,
schedule: {
_: {
activeStartTime: null,
nextDescendingStepTime: null,
nextStartTime: 1681875302n,
},
},
};

const { nextDescendingStepTime: _, ...schedule2 } = expected.schedule;
const net2 = makeNet({
...publishedNames,
auction: auctionInfo2,
});

out.splice(0);
const cmd2 = await makeInterCommand(makeProcess(t, testKeyring, out), net2);
await cmd2.parseAsync(argv);
t.deepEqual(JSON.parse(out.join('')), { ...expected, schedule: schedule2 });
});

test('README: inter vbank list', async t => {
Expand Down