Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

oz compile with nothing to compile overwrites typechain artifacts #1529

Open
abcoathup opened this issue Apr 24, 2020 · 1 comment
Open

oz compile with nothing to compile overwrites typechain artifacts #1529

abcoathup opened this issue Apr 24, 2020 · 1 comment
Labels

Comments

@abcoathup
Copy link
Contributor

Reported in Telegram by Anatol

Hello! I’m always having problems with typings generation when compiling with oz compile
if the built contracts are up to date - truffle generated typings are empty
and overwrites the good typings with empty ones

@abcoathup
Copy link
Contributor Author

abcoathup commented Apr 24, 2020

We have been able to reproduce this issue by following these steps:

Setup the project

$ mkdir issue1529 && cd issue1529
$ npm init -y
$ npm i @openzeppelin/cli

node v10.19.0
npm 6.14.4
oz --version 2.8.2
Windows Subsystem for Linux 2

Initialize CLI with typechain

$ touch tsconfig.json
$ npx oz init
? Welcome to the OpenZeppelin SDK! Choose a name for your project issue1529
? Initial project version 1.0.0
? Enable typechain support? Yes
? Typechain compilation target truffle-contract compatible
? Typechain output directory ./types/contracts/
Project initialized. Write a new contract in the contracts folder and run 'openzeppelin deploy' to deploy it.

Create a contract

Box.sol

// contracts/Box.sol
// https://docs.openzeppelin.com/learn/developing-smart-contracts#setting-up-a-solidity-project
pragma solidity ^0.5.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

Compile

$ npx oz compile
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
PATH build/contracts/Box.json
✓ Typechain artifacts generated with truffle

index.d.ts

/* Generated by ts-generator ver. 0.0.8 */
/* tslint:disable */

/// <reference types="truffle-typings" />
import { BigNumber } from "bignumber.js";

export interface BoxContract extends Truffle.Contract<BoxInstance> {
  "new"(meta?: Truffle.TransactionDetails): Promise<BoxInstance>;
}

export interface BoxInstance extends Truffle.ContractInstance {
  retrieve(txDetails?: Truffle.TransactionDetails): Promise<BigNumber>;

  store: {
    (
      newValue: number | BigNumber | string,
      txDetails?: Truffle.TransactionDetails
    ): Promise<Truffle.TransactionResponse>;
    call(
      newValue: number | BigNumber | string,
      txDetails?: Truffle.TransactionDetails
    ): Promise<void>;
    sendTransaction(
      newValue: number | BigNumber | string,
      txDetails?: Truffle.TransactionDetails
    ): Promise<string>;
    estimateGas(
      newValue: number | BigNumber | string,
      txDetails?: Truffle.TransactionDetails
    ): Promise<number>;
  };
}

merge.d.ts

/* Generated by ts-generator ver. 0.0.8 */
/* tslint:disable */

/// <reference types="truffle-typings" />

import * as TruffleContracts from ".";

declare global {
  namespace Truffle {
    interface Artifacts {
      require(name: "Box"): TruffleContracts.BoxContract;
    }
  }
}

Compile with nothing to compile

$ npx oz compile
Nothing to compile, all contracts are up to date.
PATH build/contracts/{}.json
✓ Typechain artifacts generated with truffle

index.d.ts

/* Generated by ts-generator ver. 0.0.8 */
/* tslint:disable */

/// <reference types="truffle-typings" />
import { BigNumber } from "bignumber.js";

merge.d.ts

/* Generated by ts-generator ver. 0.0.8 */
/* tslint:disable */

/// <reference types="truffle-typings" />

import * as TruffleContracts from ".";

declare global {
  namespace Truffle {
    interface Artifacts {}
  }
}

compile verbose

$ npx oz compile --verbose
[2020-04-24T01:26:01.387Z@SolidityProjectCompiler.js#call] <started> Nothing to compile, all contracts are up to date.
[2020-04-24T01:26:01.388Z@Compiler.js#compile] <started> Generating typechain artifacts...
PATH build/contracts/{}.json
[2020-04-24T01:26:01.615Z@Compiler.js#compile] <succeeded> Typechain artifacts generated with truffle
[2020-04-24T01:26:01.617Z@ProjectFile.js#write] <started> Updated /home/abcoathup/projects/forum/issue1529/.openzeppelin/project.json

The project owner will review and triage this issue during the next week. In the meantime, you can try the following workaround:

Remove the build directory and recompile to generate artifacts

$ rm -rf build
$ npx oz compile

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

No branches or pull requests

2 participants