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

test(inter-protocol): snapshot storage/RPC API for auction, vaultFactory, reserve, psm, committees #7368

Merged
merged 10 commits into from
Apr 14, 2023

Conversation

dckc
Copy link
Member

@dckc dckc commented Apr 10, 2023

refs: #6111

in particular: #6111 (comment)

Description

Flesh out the "Reading data off-chain" section of the README with snapshots of chainStorage data produced by the inter protocol contracts.

NOTE: The README says auction.books.book0, but what shows up in the snapshot is just auction.books0. Is that by design?

If feedback on this draft shows that we do want this sort of test...

DRAFT TODO:

  • address copy-pasta from on-exit test

Security / Scaling Considerations

none, AFAICT.

Documentation Considerations

adds reliable docs.

rendered: Reading data off-chain

for example:

I think consumers look for "RPC API". I wonder if we should tweak the "Reading data off-chain" section heading to include that.

Testing Considerations

This adds a bit of test maintenance. As usual with ava snapshot tests: yarn test test/auction/test-auctionContract.js -m '*snap*' --update-snapshots

Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea.

NOTE: The README says auction.books.book0, but what shows up in the snapshot is just auction.books0. Is that by design?

I missed that in review. Good thing for snapshot tests! @Chris-Hibbert could you push a commit to correct that here?

@Chris-Hibbert
Copy link
Contributor

The README says auction.books.book0, but what shows up in the snapshot is just auction.books0. Is that by design?

I was guessing, I'll admit. I'm definitely okay with it the way it is. If there's a reason for it to be otherwise, it should be simple to fix.

could you push a commit to correct that here?

Done 3cc073a

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine to me. @turadg says this will be valuable, so I'm for it.

@@ -1250,3 +1253,102 @@ test('bid zero', async t => {
},
);
});

test('auctioneer chainStorage RPC API snapshot', async t => {
//#region copied from on-exit test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of #region comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed that this one, at least, doesn't carry its weight. As noted above, I aim to "DRY out copy-pasta from on-exit test".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find a straightforward way to DRY out the common stuff; I changed the #region comments into a function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it occurs to me that, rather than repeating a bunch of stuff from another test, I can just add the t.snapshot() into that test.

- `books`
- `book0`
- `data`
- `book0`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we want book0, book1 etc. under auction after all?

I'm standing by to see if by "correct this" @turadg meant to change the published structure to include a book or books node rather than tweaking this README.

Copy link
Member

@turadg turadg Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Chris-Hibbert my earlier comment wasn't clear on the request:. I meant to fix the code so it matches the README, and the enumeration principle sketched in #6111

If keys are an index of high cardinality, they should be under their own parent key so that they don't make siblings of other types hard to find. E.g. if manager102 sibling to metrics is bad because the latter will be easy to miss. managers sibling to metrics is good.

Managers and Books are high enough cardinality to merit an grouping key.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't seem to me like a change that should be made by adding a commit to a PR on another subject.
@dckc would you excise the commit I inserted?
@turadg, would you mind creating an issue that can be prioritized?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each commit ends up separately in master so a bugfix commit is reasonable to me to include in any PR that has the appropriate reviewers. if you want to do the work in a different PR up to you.

as an issue to prioritize, #6111 encompasses the requirement. it's prioritized as a blocker for Vaults Release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried integrating the change with the existing commit stack, but the changes to the README are in a different commit than where I'd put the code changes. When I tried it, it turned into a mess, because several later commits also edit the same section of the README. It'll be far simpler as a follow-on.

},
electionType: 'survey',
issue: {
text: 'why3',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lacks detail on parameter change issues. I think developers of dapp-gov, i.e. us, are the most interested consumers of that API, and we already figured it out.

@@ -30,6 +30,8 @@ To maintain that the keys of vaults to liquidate are stable requires that its ke

VaultFactory publishes data using StoredPublishKit which tees writes to off-chain storage. These can then be followed off-chain like so,
```js
import { makeFollower } from '@agoric/casting';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does makeDefaultLeader come from? I don't see it in @agoric/casting.

- `governance`
- `metrics`
- `priceFeed` - [snapshot of details](./test/price/snapshots/test-fluxAggregator.js.md)
- `${inputBrand}-${outputBrand}_price_feed`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this formerly had a _ as in ATOM_USD when snapshotting shows it's ATOM-USD.

- `metrics`
- `priceFeed` - [snapshot of details](./test/price/snapshots/test-fluxAggregator.js.md)
- `${inputBrand}-${outputBrand}_price_feed`
- `${inputBrand}-${outputBrand}_price_feed.latestRound`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latestRound was missing.

Is it worth trying to maintain this tree of all the keys? Now that I have snapshots for all but stakeFactory, maybe it's better to just list the top level?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latestOutcome below was missing as well.

'published.priceAggregator.LINK-USD_price_feed.latestRound',
{
roundId: 3n,
startedAt: 5n,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suppose this will change to a time record in #5799 so that we can keep from exposing the whole timer below

@dckc dckc changed the title test(inter-protocol): snapshot auction/auctioneer storage/RPC API test(inter-protocol): snapshot storage/RPC API for auction, vaultFactory, reserve, psm, committees Apr 11, 2023
@dckc dckc marked this pull request as ready for review April 11, 2023 17:43
@dckc
Copy link
Member Author

dckc commented Apr 11, 2023

The technique I eventually found for the auction contract was so straightforward that I applied it to the other contracts as well (except stakeFactory).

PTAL.

@dckc
Copy link
Member Author

dckc commented Apr 11, 2023

Basis points vs. Ratios

We seem to publish basis points in some cases. I wonder if the econ-gov UI is set up for that.

        LowestRate: {
          type: 'nat',
          value: 4500n,
        },

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on chainStorage, but this looks fine to me.

@@ -134,7 +134,28 @@ test('committee-open question:one', async t => {
);
});

test('committee-open question:mixed', async t => {
const snapshotStorage = async (t, storage) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types please

Suggested change
const snapshotStorage = async (t, storage) => {
const snapshotStorage = async (
/** @type {import('ava').ExecutionContext<unknown>} */ t,
/** @type {import('@agoric/internal/src/storage-test-utils.js').MockChainStorageRoot} */ storage,
) => {

@@ -906,6 +924,8 @@ test.serial('onDeadline exit', async t => {
currentPriceLevel: { numerator: { value: 9_350_000_000_000n } },
});

await snapshotStorage(t, driver.mockChainStorage);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each test is defining its own snapshotStorage but they follow the same pattern. please DRY it out. I think something like,

Suggested change
await snapshotStorage(t, driver.mockChainStorage);
await snapshotStorage(t, driver.mockChainStorage, {'mockChainStorageRoot.thisAuction': 'published.auction'}, `Under "published", the "auction" node is delegated to
the auctioneer contract, which publishes data as follows.
See also board marshalling conventions (_to appear_).
` );

or maybe more to the point: documentStorageKeys since the note and the rewriting to published: is not really about testing.

Comment on lines +185 to +189
storageNode: mockChainStorage
.makeChildNode('psm')
.makeChildNode('IST')
.makeChildNode('AUSD'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like logic that is meant to be under test but is part of the driver.

consider a function to make a storage path for a PSM which can be re-used in startPSM:

const psmStorageNode = await makeStorageNodeChild(chainStorage, 'psm');
const storageNode = E(
E(psmStorageNode).makeChildNode(Stable.symbol),
).makeChildNode(keyword);

Comment on lines 149 to 150
const note = `Under "published", the "committees.Economic_Committee" node is delegated to
a committee contract, which publishes data as follows.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever way to mix docs into tests into docs!

"which publishes data as follows" isn't clear to me. The following is an instance of the possible data. A plausible instance? Just conformant? What can the reader count on it for?

Whatever language is chosen, I think it should be consistent across contract instances (see comment below on DRY)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be illustrative. Ideally, it would illustrate all branches of any union types. I'm not sure how to be precise about what the reader can count without putting so much text in the way that it's distracting..

A plausible instance?

That's accurate and concise, if not complete. I suppose I can go with that.

@turadg turadg mentioned this pull request Apr 12, 2023
@dckc dckc added automerge:rebase Automatically rebase updates, then merge bypass:integration Prevent integration tests from running on PR labels Apr 13, 2023
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done

Comment on lines +232 to +233
pattern: 'mockChainStorageRoot.thisElectorate.',
replacement: 'published.committees.Economic_Committee.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these would read more easily as a map, even if it has just one item.

Suggested change
pattern: 'mockChainStorageRoot.thisElectorate.',
replacement: 'published.committees.Economic_Committee.',
rekey: {'mockChainStorageRoot.thisElectorate': published.committees.Economic_Committee`},

@dckc dckc force-pushed the dc-auction-rpc-snapshot branch 2 times, most recently from f40093b to 899c566 Compare April 14, 2023 17:39
@dckc
Copy link
Member Author

dckc commented Apr 14, 2023

A couple storage keys in the vaults snapshot flip-flopped. I'm not sure how stable they were. I sorted them all an regenerated the snapshots.

Also, I squashed all the inter-protocol snapshot commits together. And moved all the governance commits before inter-protocol.

@mergify mergify bot merged commit 2b027a4 into master Apr 14, 2023
@mergify mergify bot deleted the dc-auction-rpc-snapshot branch April 14, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge bypass:integration Prevent integration tests from running on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants