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

Standard JSON input for Solidity and Vyper #1197

Merged
merged 3 commits into from
Jan 17, 2025
Merged

Conversation

evilpeach
Copy link
Collaborator

@evilpeach evilpeach commented Jan 16, 2025

Fixes FRO-764, FRO-755

Summary by CodeRabbit

Release Notes

  • New Features

    • Added EVM contract verification with standard JSON input for Solidity and Vyper.
    • Enhanced file upload support for Vyper contract verification.
    • Expanded file type support in the dropzone component to accept JSON files.
  • Improvements

    • Updated optimizer configuration for the EVM contract verification page.
    • Refined contract address form validation.
    • Improved form handling for contract verification.
  • Bug Fixes

    • Resolved issues with EVM contract details verification boarding.
    • Fixed constructor argument handling.

Copy link

vercel bot commented Jan 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 16, 2025 10:44am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
celatone-frontend-main ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 10:44am
initia-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 10:44am
neutron-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 10:44am
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 10:44am
sei-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 10:44am
terra-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 10:44am

Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

This pull request introduces enhanced functionality for EVM contract verification by adding support for standard JSON input for both Solidity and Vyper contracts. The changes expand file type support in the dropzone component, modify form handling for JSON input, and update Zod schemas to accommodate new file upload options. The modifications improve the flexibility of contract verification processes by introducing new file types, optimizing configuration options, and refining the user interface for contract verification.

Changes

File Change Summary
CHANGELOG.md Added new features for EVM contract verification, including standard JSON input and Vyper file upload method. Improved optimizer configuration. Fixed bugs related to form validation.
src/lib/components/dropzone/config.ts Updated DropzoneFileType to replace "schema" with "json" and removed prettyFileType from DROPZONE_CONFIG.
src/lib/components/dropzone/index.tsx Changed file type key from schema to json in the sizes object. Updated drag-and-drop text reference.
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidity.tsx Modified prop passing for verification options based on selected input type.
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityJsonInput.tsx Restructured component to handle JSON input with react-hook-form, added file handling capabilities.
src/lib/pages/evm-contract-verify/components/vyper/EvmContractVerifyVyperJsonInput.tsx Updated file handling to accept JSON files, modified useController hook's name property.
src/lib/pages/evm-contract-verify/types.ts Added optional file schemas for JSON inputs in relevant forms.
src/lib/components/json-schema/UploadTemplate.tsx Changed accepted file type in DropZone from "schema" to "json".
src/lib/pages/custom-network/json/index.tsx Updated DropZone to accept files of type ["json"] instead of ["schema"].

Possibly related PRs

Suggested reviewers

  • songwongtp
  • Poafs1

Poem

🐰 Hop, hop, into the code we dive,
Contracts verified, now they come alive!
JSON and Vyper, dancing with grace,
Dropzone magic leaves not a trace.
Verification's rabbit has its day! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@evilpeach evilpeach changed the base branch from develop to feature/vyper-upload-file January 16, 2025 08:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 5

🧹 Nitpick comments (6)
src/lib/pages/evm-contract-verify/components/vyper/EvmContractVerifyVyperJsonInput.tsx (1)

28-35: Consider adding file size validation.

While the file type validation is in place, consider adding file size limits to prevent large JSON files from being uploaded.

src/lib/pages/evm-contract-verify/components/vyper/EvmContractVerifyVyperUploadFile.tsx (1)

32-35: Consider supporting multiple file uploads.

Since Vyper contracts might have dependencies or imports, consider supporting multiple file uploads.

 <DropZone
-  setFiles={(files) => onChange(files[0])}
+  setFiles={onChange}
   fileType={["vy"]}
+  multiple
 />
src/lib/pages/evm-contract-verify/helper.ts (1)

24-24: Consider improving type safety and configuration management.

A few suggestions to enhance the code:

  1. Extract "default" as a constant to avoid magic strings
  2. Consider using a more specific type for the file field
  3. Add TypeScript type annotations for the return types
+ const DEFAULT_EVM_VERSION = "default";
+ type VerifyFormValue = {
+   option: VerificationOptions;
+   constructorArgs: {
+     enabled: boolean;
+     value: string;
+   };
+   evmVersion?: string;
+   file?: File;
+ };

- export const getVerifyFormInitialValue = (
+ export const getVerifyFormInitialValue = (
+   language: EvmProgrammingLanguage,
+   verificationOption: VerificationOptions
+ ): VerifyFormValue => {

Also applies to: 45-45, 47-47

src/lib/pages/evm-contract-verify/components/EvmVersionToTarget.tsx (1)

45-57: Add aria-label for better accessibility.

The SelectInput component could benefit from additional accessibility attributes.

 <SelectInput
   label="EVM Version to target"
+  aria-label="Select EVM Version"
   menuPortalTarget={document.body}
   isRequired
   options={evmVersionOptions}
src/lib/components/forms/SelectInput.tsx (1)

131-136: Consider using a higher z-index value from a theme constant.

The current z-index of 2 might be too low for complex layouts with multiple stacking contexts. Consider using a theme constant for z-index values to maintain consistency.

 styles={{
   menuPortal: (provided) => ({
     ...provided,
-    zIndex: 2,
+    zIndex: theme.zIndices.dropdown ?? 1000,
   }),
 }}
src/lib/components/dropzone/index.tsx (1)

51-53: Extract file size limits to configuration constants.

The file size limits are hardcoded. Consider moving these to a configuration file or environment variables for better maintainability.

+const FILE_SIZE_LIMITS = {
+  STANDARD: 10_000_000,
+  SCHEMA: 10_000_000,
+  MOVE: 10_000_000,
+  VYPER: 10_000_000,
+} as const;

 const sizes: {
   [key in DropzoneFileType]: number;
 } = {
-  schema: 10_000_000,
-  move: 10_000_000,
+  schema: FILE_SIZE_LIMITS.SCHEMA,
+  move: FILE_SIZE_LIMITS.MOVE,
   wasm: wasm.enabled ? wasm.storeCodeMaxFileSize : 0,
   mv: move.enabled ? move.moduleMaxFileSize : 0,
   toml: 1_000_000,
-  vy: 10_000_000,
-  "standard-json": 10_000_000,
+  vy: FILE_SIZE_LIMITS.VYPER,
+  "standard-json": FILE_SIZE_LIMITS.STANDARD,
 };
🛑 Comments failed to post (5)
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityJsonInput.tsx (1)

1-39: 🛠️ Refactor suggestion

Consider creating a shared component for JSON input.

This component is identical to EvmContractVerifyVyperJsonInput. Consider extracting the common logic into a shared component to avoid duplication.

Example implementation:

interface ContractVerifyJsonInputProps {
  control: Control<EvmContractVerifyForm>;
  title?: string;
}

const ContractVerifyJsonInput = ({
  control,
  title = "Provide Standard JSON Input"
}: ContractVerifyJsonInputProps) => {
  const {
    field: { value, onChange },
  } = useController({
    control,
    name: "verifyForm.form.jsonFile",
  });

  return (
    <Stack spacing={12}>
      <Stack spacing={4}>
        <Heading as="h6" variant="h6">
          {title}
        </Heading>
        {value ? (
          <UploadCard file={value} deleteFile={() => onChange("")} />
        ) : (
          <DropZone
            setFiles={(files) => onChange(files[0])}
            fileType={["standard-json"]}
          />
        )}
      </Stack>
      <ConstructorArgs control={control} />
    </Stack>
  );
};

// Usage in Solidity component
export const EvmContractVerifySolidityJsonInput = ({ control }: EvmContractVerifySolidityJsonInputProps) => (
  <ContractVerifyJsonInput control={control} />
);

// Usage in Vyper component
export const EvmContractVerifyVyperJsonInput = ({ control }: EvmContractVerifyVyperJsonInputProps) => (
  <ContractVerifyJsonInput control={control} />
);
src/lib/components/dropzone/config.ts (1)

63-69: 💡 Codebase verification

Confirmed: Better distinction needed between JSON file types

The codebase shows that JSON file types are distinguished only through user selection, with no content validation. The prettyFileType for standard-json should be more descriptive (e.g., "Solidity Standard JSON Input") to help users select the correct file type.

🔗 Analysis chain

Consider distinguishing between JSON schema and standard JSON input files.

The standard-json type uses the same extension (.json) and MIME type as the existing schema type. This might cause confusion in file type detection. Consider:

  1. Adding a more descriptive prettyFileType to clearly indicate its purpose (e.g., "Solidity/Vyper Standard JSON Input")
  2. Adding validation to distinguish between schema and standard JSON input files based on their content structure

Run this script to check for potential file type conflicts:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for duplicate file extensions across different file types

# Extract and compare file extensions
echo "Analyzing file extensions in DROPZONE_CONFIG..."
rg -A 5 'accept:.*\[.*\]' src/lib/components/dropzone/config.ts

Length of output: 1136


Script:

#!/bin/bash
# Search for file type validation logic
echo "Searching for file type validation..."
rg -g '!*.test.*' -g '!*.spec.*' "standard-json|schema.*json" src/lib/components/dropzone/

# Check dropzone component implementation
echo -e "\nChecking dropzone component implementation..."
ast-grep --pattern 'function $_($$_) {
  $$$
  dropzone
  $$$
}'

Length of output: 542

src/lib/pages/evm-contract-verify/components/EvmVersionToTarget.tsx (1)

23-31: 🛠️ Refactor suggestion

Expand EVM version options beyond just "Default".

The current implementation only offers a single EVM version option. Consider adding commonly used EVM versions like "london", "berlin", "istanbul", etc.

 const evmVersionOptions = useMemo(
   () => [
     {
       label: "Default",
       value: "default",
     },
+    {
+      label: "London",
+      value: "london",
+    },
+    {
+      label: "Berlin",
+      value: "berlin",
+    },
+    {
+      label: "Istanbul",
+      value: "istanbul",
+    },
   ],
   []
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

  const evmVersionOptions = useMemo(
    () => [
      {
        label: "Default",
        value: "default",
      },
      {
        label: "London",
        value: "london",
      },
      {
        label: "Berlin",
        value: "berlin",
      },
      {
        label: "Istanbul",
        value: "istanbul",
      },
    ],
    []
  );
src/lib/pages/evm-contract-verify/types.ts (1)

54-54: 🛠️ Refactor suggestion

Add file size and type validation to File schemas.

The current File validation only checks if the value is an instance of File. Consider adding size and type validation to prevent invalid uploads.

-  jsonFile: z.instanceof(File).optional(),
+  jsonFile: z.instanceof(File)
+    .refine(
+      (file) => file.size <= 10_000_000,
+      "File size must be less than 10MB"
+    )
+    .refine(
+      (file) => file.type === "application/json",
+      "File must be a JSON file"
+    )
+    .optional(),

Also applies to: 69-69, 81-81

src/lib/components/ContractInputSection.tsx (1)

29-29: 💡 Codebase verification

Inconsistent naming between interface and implementation

The rename from contract to wasmContract creates an inconsistency:

  • Component's props interface uses contract
  • All consuming components pass contract prop
  • Only the internal implementation uses wasmContract

While this component is indeed WASM-specific (used only in WASM contexts), the rename should be consistent across both interface and implementation, or kept as contract since it's already in a WASM context.

🔗 Analysis chain

LGTM! Verify component usage context.

The rename from contract to wasmContract correctly reflects this component's WASM-specific nature.

Let's confirm this component is only used in WASM contexts:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for ContractInputSection usage
rg -l "ContractInputSection" | grep -v "test"

Length of output: 149


Script:

#!/bin/bash
# Check ContractInputSection usage context in migrate and admin pages
echo "=== migrate/index.tsx ==="
rg -B 2 -A 2 "ContractInputSection" src/lib/pages/migrate/index.tsx

echo -e "\n=== admin/index.tsx ==="
rg -B 2 -A 2 "ContractInputSection" src/lib/pages/admin/index.tsx

Length of output: 1332


Script:

#!/bin/bash
# Check if these pages are WASM-specific by looking at their imports and key terms
echo "=== migrate/index.tsx WASM context ==="
rg -i "wasm|cosmwasm" src/lib/pages/migrate/index.tsx

echo -e "\n=== admin/index.tsx WASM context ==="
rg -i "wasm|cosmwasm" src/lib/pages/admin/index.tsx

# Also check the component's props interface
echo -e "\n=== ContractInputSection props ==="
rg "interface.*Props" -A 5 src/lib/components/ContractInputSection.tsx

Length of output: 993

Base automatically changed from feature/vyper-upload-file to develop January 16, 2025 09:28
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/lib/components/json-schema/UploadTemplate.tsx (1)

Line range hint 1-1: Consider renaming the component directory.

The component is located in the "json-schema" directory, but it now handles general JSON files. Consider renaming the directory to better reflect its current purpose.

src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityJsonInput.tsx (1)

31-35: Consider adding file validation.

The component accepts JSON files but doesn't validate their content. Consider adding validation to ensure the file contains valid Solidity contract JSON input.

 <DropZone
   setFiles={(files) => onChange(files[0])}
   fileType={["json"]}
+  onError={(error) => {
+    // Handle validation error
+  }}
+  validate={(file) => {
+    return new Promise((resolve, reject) => {
+      const reader = new FileReader();
+      reader.onload = () => {
+        try {
+          const content = JSON.parse(reader.result as string);
+          if (!content.language || content.language !== 'Solidity') {
+            reject(new Error('Invalid Solidity JSON input'));
+          }
+          resolve(true);
+        } catch {
+          reject(new Error('Invalid JSON format'));
+        }
+      };
+      reader.readAsText(file);
+    });
+  }}
 />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 073a67f and 17926de.

📒 Files selected for processing (6)
  • src/lib/components/dropzone/config.ts (2 hunks)
  • src/lib/components/dropzone/index.tsx (2 hunks)
  • src/lib/components/json-schema/UploadTemplate.tsx (1 hunks)
  • src/lib/pages/custom-network/json/index.tsx (1 hunks)
  • src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityJsonInput.tsx (1 hunks)
  • src/lib/pages/evm-contract-verify/components/vyper/EvmContractVerifyVyperJsonInput.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/components/dropzone/index.tsx
  • src/lib/pages/evm-contract-verify/components/vyper/EvmContractVerifyVyperJsonInput.tsx
🔇 Additional comments (5)
src/lib/components/dropzone/config.ts (2)

3-3: LGTM! Type definition updated for JSON support.

The change from "schema" to "json" aligns with the PR's objective to support standard JSON input for contract verification.


19-24: LGTM! JSON configuration properly defined.

The configuration correctly specifies:

  • MIME type: "application/json"
  • File extension: ".json"
src/lib/pages/custom-network/json/index.tsx (1)

105-105: LGTM! DropZone configuration updated for JSON files.

The fileType prop change aligns with the updated dropzone configuration.

src/lib/components/json-schema/UploadTemplate.tsx (1)

117-117: LGTM! DropZone configuration updated for JSON files.

The fileType prop change aligns with the updated dropzone configuration.

src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityJsonInput.tsx (1)

8-39: LGTM! Well-structured component implementation.

The component follows React best practices:

  • Clear props interface definition
  • Proper form integration using react-hook-form
  • Consistent file handling with other components

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