Skip to content

Testing

JimChen2002 edited this page Nov 1, 2021 · 19 revisions

This is the src dir

How to test the truffle node.

Deploying a Contract on a local node

  • Install a truffle

    • npm install -g truffle
  • Initialize a new truffle project

    • truffle init
  • To deploy, we need a blockchain so we fork ganache.

    • npm install -g @celo/ganache-cli
  • Start ganache

    • ganache-cli --port 7545
  • Deploy the contract to the local network

    • truffle migrate --network test
  • Interact with the contract via the truffle console

    • truffle console --network test
  • Add truffle-assertions

    • npm install truffle-assertions

Deploying a Contract to Alfajores

  • When deploying to Alfajores, we'll need a Celo client.
    • export CELO_IMAGE=us.gcr.io/celo-org/geth:alfajores
  • Use a Docker image containing the Celo node software
    • docker pull $CELO_IMAGE
  • Set up a data directory
    • mkdir celo-data-dir
    • cd celo-data-dir

More detailed instructions can be found below

Problems we encountered

  • Start ganache

    • Command: ganache-cli --port 7545
    • Error: Callback was already called.
    • Potential reason: ganache is not compatible with newer version of node
    • Solution: download Ganache from official website, open and click Quickstart. It should have the same effect as the command
  • Run docker

    • Command: any docker command that specifies a path
    • Error: docker: invalid reference format: repository name must be lowercase.
    • Solution: surround the path with quotation mark
  • Start the node

    • Command: docker run --name celo-ultralight-node ......
    • Error: docker: Error response from daemon: driver failed programming external connectivity on endpoint celo-ultralight-node (<YOUR-ACCOUNT-ADDRESS>): Bind for 127.0.0.1:8545 failed: port is already allocated.
    • Environment: port 8545 is not allocated before running the command
    • Potential reason: docker fail to reinitialize
    • Solution: restart docker
  • Migrate to Alfajores

    • Command: truffle migrate --network alfajores
    • Error: *** Deployment Failed *** "Bolt" -- Returned error: invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go struct field SendTxArgs.gas of type hexutil.Uint64. at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    • Potential reason: newer version of truffle is not compatible with alfajores
    • Solution (from Celo Discord): change the version of truffle from 5.4.14 to 5.4.0 with commands npm uninstall -g truffle and npm install -g [email protected]