Skip to content

feat: Add Typechain#67

Draft
fzavalia wants to merge 1 commit into
masterfrom
feat/typechain
Draft

feat: Add Typechain#67
fzavalia wants to merge 1 commit into
masterfrom
feat/typechain

Conversation

@fzavalia

@fzavalia fzavalia commented Apr 28, 2023

Copy link
Copy Markdown
Contributor

Add typed contracts created with typechain when published.

Current issues:

When imported in the builder and used, everything works when started with npm start. However, when running the tests, there is an error regarding this library that is:

 FAIL  src/modules/ens/sagas.spec.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/nando/Code/Decentraland/builder/node_modules/decentraland-transactions/typechain/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * as factories from "./factories";
                                                                                             ^^^^^^

    SyntaxError: Unexpected token 'export'

       6 | import { BuilderClient, LandCoords, LandHashes } from '@dcl/builder-client'
       7 | import { ContractName, getContract } from 'decentraland-transactions'
    >  8 | import { DCLControllerV2, DCLControllerV2__factory, DCLRegistrar__factory } from 'decentraland-transactions/typechain'
         | ^
       9 | import { getChainIdByNetwork, getNetworkProvider, getSigner } from 'decentraland-dapps/dist/lib/eth'
      10 | import { getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors'
      11 | import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (src/modules/ens/sagas.ts:8:1)

To try it for yourself, you can checkout decentraland/builder#2615 and run the tests.

If you want to compile this lib locally and import it in the builder to try changes, I recommend:

# decentraland-transactions
npm ci --legacy-peer-deps
make build
cd dist
npm pack

# builder
npm i /decentraland-transactions/dist/decentraland-transactions-0.0.0-development.tgz
npm test

@LautaroPetaccio

Copy link
Copy Markdown
Contributor

Now that we have changed the build process, we can modify the jest configuration to transform the typechain module into a ES6 module.

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.

2 participants