o1-labs / zkapp-cli

CLI to create a zkApp (zero-knowledge app) for Mina Protocol
https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp
Apache License 2.0
115 stars 43 forks source link

zk deploy does not recognize the TokenContract as a smart contract class #676

Closed 45930 closed 1 month ago

45930 commented 1 month ago

Describe the bug

zk deploy searches the file system for smart contracts that can be deployed. Any class that extends SmartContract should be deployable.

When a smart contract extends the TokenContract abstract class, which is a smart contract, the token implementation is not recognized as a smart contract.

Steps to Reproduce

Clone this project, run npm i; npm run build; zk deploy, and you will reproduce the error:

.../fungible-token-exploration/node_modules/enquirer/lib/types/array.js:38
      throw new Error('At least one choice must be selectable');
            ^

Error: At least one choice must be selectable
    at SelectPrompt.reset (.../fungible-token-exploration/node_modules/enquirer/lib/types/array.js:38:13)
    at async SelectPrompt.initialize (.../fungible-token-exploration/node_modules/enquirer/lib/types/array.js:25:5)
    at async .../fungible-token-exploration/node_modules/enquirer/lib/prompt.js:246:7

Node.js v20.15.0

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) arm64 Apple M2
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.17.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v18.17.0/bin/npm
  npmPackages:
    o1js: 1.4.0
  npmGlobalPackages:
    zkapp-cli: 0.21.5


### Severity

serious, but I can work around it

### Additional Information

_No response_
45930 commented 1 month ago
/**
 * Finds all classes that extend or implement the 'SmartContract' class from 'o1js'.
 *
 * @param {string} entryFilePath - The path of the entry file.
 * @returns {Array<Object>} - An array of objects containing the class name and file path of the smart contract classes found.
 */
export function findIfClassExtendsOrImplementsSmartContract(entryFilePath) {
  const classesMap = buildClassHierarchy(entryFilePath);
  const importMappings = resolveImports(entryFilePath);
  const smartContractClasses = [];

  // Check each class in the class map for inheritance from the o1js `SmartContract`
  for (let className of Object.keys(classesMap)) {
    const result = checkClassInheritance(
      className,
      'SmartContract',
      classesMap,
      new Set(),
      importMappings
    );
    if (result) {
      smartContractClasses.push({
        className,
        filePath: classesMap[className].filePath,
      });
    }
  }

  return smartContractClasses;
}

This function should locate the class MyToken, but returns an empty array instead.

shimkiv commented 1 month ago

Hey @45930 can you please link the repository you mentioned above?

Clone this project

45930 commented 1 month ago

@shimkiv my bad! Added to the original post. This is the repo: https://github.com/boray/fungible-token-exploration/tree/89321ac39cd13fae73357c70e03e6b20e8dbd7cc

ymekuria commented 1 month ago

Thanks for adding this issue @45930 .

shimkiv commented 1 month ago

Hey @45930 can you please try with this zkapp-cli version (since we now have continuous releases 🎉 ):

npm i https://pkg.pr.new/o1-labs/zkapp-cli@677
emlautarom1 commented 1 month ago

@shimkiv I'm facing the same issue and trying your suggested fix does not work at the moment:

npm error code E404
npm error 404 Not Found - GET https://pkg.pr.new/o1-labs/zkapp-cli/zkapp-cli@677
npm error 404
npm error 404  'https://pkg.pr.new/o1-labs/zkapp-cli@677' is not in this registry.
npm error 404 This package name is not valid, because 
npm error 404  1. name can only contain URL-friendly characters
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /home/emlautarom1/.npm/_logs/2024-07-11T15_47_56_294Z-debug-0.log
shimkiv commented 1 month ago

@emlautarom1 we did not release this fix on NPM yet and pkg.pr.new seems to host releases for a limited time. You can try this one:

npm i https://pkg.pr.new/o1-labs/zkapp-cli@2bfa96f