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

Upgrade tests to use typescript #19

Open
martinstellnberger opened this issue Nov 26, 2018 · 3 comments
Open

Upgrade tests to use typescript #19

martinstellnberger opened this issue Nov 26, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@martinstellnberger
Copy link
Member

Useful links
npm install -g yarn
https://www.npmjs.com/package/yarn
https://github.com/ethereum-ts/truffle-typechain-example#setup

@martinstellnberger martinstellnberger added the enhancement New feature or request label Nov 26, 2018
@martinstellnberger martinstellnberger self-assigned this Nov 26, 2018
@martinstellnberger
Copy link
Member Author

martinstellnberger commented Nov 26, 2018

Includes a bug in generating Library contract for complex type
https://github.com/ethereum-ts/TypeChain

     pragma solidity ^0.5.0;

     /** @title Library functions used by contracts within this ecosystem.*/
     library Lib {

     /**
     * @dev Enum to store the states of HashMapping entries
     */
     enum HashState {
         /*0*/ Invalid,
         /*1*/ Active,
         /*2*/ Archived
     }

    /**
    * @dev Efficient storage container for active and archived hashes enabling iteration
    */
	struct HashMappping {
        mapping(bytes32 => HashState) hashState;
        mapping(uint => bytes32) itHashMap;
        uint firstIdx;
        uint nextIdx;
        uint count;
    }

    /**
    * @dev Add a new hash to the storage container if it is not yet part of it
    * @param self Struct storage container pointing to itself
    * @param _hash Hash to add to the struct
    */
    function add(HashMappping storage self, bytes32 _hash) public {
        // Ensure that the hash has not been previously already been added (is still in an invalid state)
        assert(self.hashState[_hash] == HashState.Invalid);
        // Set the state of hash to Active
        self.hashState[_hash] = HashState.Active;
        // Index the hash with the next idx
        self.itHashMap[self.nextIdx] = _hash;
        self.nextIdx++;
        self.count++;
    }
}

See below info:

$ truffle compile --all
Compiling ./contracts/Greeter.sol...
Compiling ./contracts/Lib.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/Owned.sol...
Writing artifacts to ./build/contracts
$ yarn generate
yarn run v1.12.3
$ truffle compile && typechain --target truffle './build/**/*.json'
ts-gen: Running Typechain
ts-gen: ./build/**/*.json matched 4 files.
ts-gen: Processing build/contracts/Greeter.json
ts-gen: Processing build/contracts/Lib.json
**Error occured:  Unknown type: Lib.HashMappping storage**
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ truffle version
Truffle v5.0.0-beta.2 (core: 5.0.0-beta.2)
Solidity v0.5.0 (solc-js)
Node v10.13.0

@martinstellnberger
Copy link
Member Author

Contents of Package.json file

{
  "license": "ISC",
  "devDependencies": {
    "@types/bignumber.js": "^5.0.0",
    "@types/chai": "^4.1.7",
    "@types/mocha": "^5.2.5",
    "@types/node": "^10.12.10",
    "truffle-typings": "^1.0.5",
    "ts-generator": "^0.0.8",
    "ts-node": "^7.0.1",
    "typechain": "^0.3.9",
    "typescript": "^3.1.6"
  },
  "dependencies": {
    "solc": "^0.5.0",
    "truffle": "^5.0.0-beta.2"
  },
  "scripts": {
    "generate": "truffle compile && typechain --target truffle './build/**/*.json'",
    "prepare": "yarn generate",
    "test": "truffle test && yarn tsc",
    "tsc": "tsc --noEmit"
  }
}

@martinstellnberger
Copy link
Member Author

Not sure how the migration component of the example project
https://github.com/ethereum-ts/truffle-typechain-example
is supposed to work. Put on hold for 2 months and reinvestigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant