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

Fuzzing, Context Props and Recursive Proxies #208

Merged
merged 5 commits into from
Mar 7, 2022
Merged

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Mar 2, 2022

This patch is three separate patches together, subsuming #129 and #196.

Fuzzing

This patch adds fuzzing (originally #129) to scenarios. This allows us to add multiple runs for different random values when testing a property, e.g. if I supply 1 DAI or 100 DAI, do things still work. This will be fundamental in showing the properties are not just one-off special tests. H/T 🪖 for this work.

Context Properties

Context Properties simplify a difficult process in scenario contexts. It used to be that for a scenario, it would accept scenario<C>(context: C, world: World), but this was difficult, since we often wanted to destructure scenario<C>({comet}: C, world: World), which means that C (the context) needed a property (or getter) called comet, which needed to be updated with the Context. Meaning that if we wanted to use a new Comet context (e.g. because we deployed a new one in ModernConstraint), then we'd need to also call context.comet = newComet (and it would break if we didn't), and then when we wanted to fork, we needed to... undo this change? Plus, when migrating to DeploymentManager, these functions became often async (since we needed to read the ABI from disk). So it just became a mess. Also, if you wanted to call a function on the context, you needed to make sure the this was bound correctly, which is messy in JavaScript. Now, we add a function called getContextProperties<C, P>(context: C): Promise<P> which is called before every scenario and passed in as the first argument. This allows us to write: getContextProperties = function(context) { return { comet: await context.getComet() } } and then scenario<C, P>({comet}: P, world: World, context: Context) { console.log(await comet.name()) } and it's guaranateed to work correctly. This makes life a ton easier when handling contexts, at the added code of adding a second generic param to manage.

Recursive Proxies

We add support for recurisve proxies with merged ABIs. That is, if a contract like comet has a proxy comet:implementation, and then comet:implemenation has a proxy comet:implementation:ext, now this can be picked up in spider and used in the deployed contract. This allows us to handle CometExt correctly in our scenarios.

@hayesgm hayesgm changed the title [WIP] Fuzzing Rebased Fuzzing, Context Props and Recursive Proxies Mar 4, 2022
@hayesgm hayesgm marked this pull request as ready for review March 4, 2022 21:30
This was referenced Mar 4, 2022
plugins/scenario/Runner.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jflatow jflatow left a comment

Choose a reason for hiding this comment

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

👏 great features

kevincheng96 and others added 5 commits March 7, 2022 11:10
Fix Issues with Forking and Snapshotting

This patch fixes issues with forking context and snapshotting. We ensure that forks actually do not conflict with one another by deep-cloning any necessary functions. Secondly, we improve snapshots so they are used between solutions of a solution-set. We probably need to work on what destructuring from CometContext looks like, which will be added to this branch before it's merged.

Context Properties

This patch creates "ContextProperties", which is a transformed version of context that is passed into scenarios. This allows us to not have to attach every possible value to the context object for destructuring, which becomes an issue when an object like `comet` changes (and thus should be received by an async getter), which either makes the scenario code more complicated (`let comet = await context.getComet()`), or we say `context.comet = comet` and then later if that value changes, we need to effectively observe those changes and reset this mirror-object. Instead, now, we create a function that is effectively: `getContextProperties(context) -> { comet: ..., ... }`. This function then can pull the data from the canonical source, but now the scenario can just destructure `{comet}` from this and not have to deal with guessing if this value is up to date (or awaiting it).

Additionally, we change `cache` to use `Map`s instead of objects for tracking its data and perform a smarter version of `deepClone`, which previously had a mistake that is was transforming `Map`s and other non-JSON data structures into flat objects, which then was failing further code. The new code deep clones Maps correctly and otherwise takes values as-is.
Copy link
Contributor

@kevincheng96 kevincheng96 left a comment

Choose a reason for hiding this comment

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

Nice! Can't wait to get this merged

deployments/fuji/relations.ts Show resolved Hide resolved
@hayesgm hayesgm merged commit c33e187 into main Mar 7, 2022
@hayesgm hayesgm deleted the hayesgm/fuzzing-rebased branch March 7, 2022 21:28
@kevincheng96 kevincheng96 mentioned this pull request Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants