Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Internal improvement: Remove faker from abi-utils and generate arbitraries manually #5484

Merged
merged 4 commits into from Aug 26, 2022

Conversation

eggplantzzz
Copy link
Contributor

One of the MetaMask team pointed out that faker is a big dependency of abi-utils and asked Truffle to remove it as they are trying to cut down the size of their extension. Truffle does not really use faker for much besides generating random names for when it creates arbitrary abis. This PR implements a simple utility that generates these names manually.

@eggplantzzz eggplantzzz force-pushed the ridda-faker branch 2 times, most recently from 8913b32 to 3d0a01a Compare August 24, 2022 21:01
Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

Seems basically good, but one part seems overly complicated, you might want to simplify it.

Btw, some history you may be interested in: When I added errors, I was originally going to do them as adjective-noun, but I ultimately went with noun-noun because one of faker's adjectives was "1080p" and that obviously caused problems if it went first! (Although I guess I could have filtered out things that started with digits.)

transform = camelCase
): fc.Arbitrary<string> => {
const results: fc.Arbitrary<string>[] = [];
for (const wordType of wordTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems overly complicated to me in two ways:

  1. Rather than having these separate noun-vs-verb branches, you could just use wordLists[wordType] everywhere with no branch.
  2. Instead of doing fc.integer(...).noBias().noShrink().map(...), you could just use fc.constantFrom(...), if I'm understanding correctly?

It looks to me like doing those would simplify this function a lot.

Copy link
Contributor

Choose a reason for hiding this comment

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

2. Instead of doing fc.integer(...).noBias().noShrink().map(...), you could just use fc.constantFrom(...), if I'm understanding correctly?

OMG I was looking for this very thing!

@eggplantzzz I'll address this concern and push up a new commit, since this is my mess that Harry's showing issue with.

Copy link
Contributor

Choose a reason for hiding this comment

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

Updated. Wow that's so much cleaner. Thanks @haltman-at!

Comment on lines +416 to +418
const EventName = () => Name(["verb", "noun"], pascalCase);
const ErrorName = () => Name(["noun", "noun"], pascalCase);
const FunctionName = () => Name(["verb", "noun"]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I really like how this makes it seem like fast-check just wants to play Mad Libs

@haltman-at
Copy link
Contributor

(Note this needs to be rebased against develop to solve the yarncheck problem.)

Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

Hooray!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants