Agoric / agoric-sdk

monorepo for the Agoric Javascript smart contract platform
Apache License 2.0
327 stars 207 forks source link

identity-preserving marshallers for vstorage testing, clients etc. #10491

Open dckc opened 1 week ago

dckc commented 1 week ago

What is the Problem Being Solved?

makeWalletFactoryDriver and makeAgoricNamesRemotesFromFakeStorage use fromCapData to make remote presences for instances, brands, and such. But they don't do so in an identity-preserving way.

So code such as this doesn't work:

    const current = watcherWallet.getCurrentWalletRecord();
    const invitationPurse = current.purses.find(
      p => p.brand === agoricNamesRemotes.brand.Invitation,
    );

Description of the Design

Use a a slot <-> value translation table, indexed in both directions, as in marshalTables.js 80f5cb1

Probably in @agoric/client-support in or around vstorage-kit.js.

Security Considerations

There's a risk of "over-indexing"; that is: using a shared marshal context across parts of a test that represent different vats.

For those cases, we should be able to use srcMarshaller.toCapData(passable) to externalize the data and then destMarshaller.fromCapData(data) to internalize it on the other side.

Scaling / Upgrade Considerations

n/a

Test Plan

Use of these tools in tests should validate them.