npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cpchain-tools/cpchain-dapps-utils

v0.0.7

Published

A tool library for creating dapps

Downloads

9

Readme

cpchain-dapps-utils

A tool library for creating dapps

Test Coverage Badge

Installation and Usage


npm install @cpchain-tools/cpchain-contracts

Ownership


import "@cpchain-tools/cpchain-contracts/ownership/Ownable.sol" 
contract Example is Ownable {
    function ownerGreet() public view onlyOwner returns (string) {
        return "Hello,Owner";
    }
}

Claimable need next owner send transaction to transfer ownership


import "@cpchain-tools/cpchain-contracts/ownership/Ownable.sol"
contract Example is Claimable {
    function ownerGreet() public view onlyOwner returns (string) {
        return "Hello,Owner";
    }
}

Lifecycle


import "@cpchain-tools/cpchain-contracts/lifecyle/Enable.sol"

contract Example is Enable {
    function enableGreet() public view onlyEnabled returns (string) {
        return "enabled";
    }
}

SafeMath

Arithmetic operations in Solidity wrap on overflow. This can easily result in bugs, because programmers usually assume that an overflow raises an error, which is the standard behavior in high level programming languages. SafeMath restores this intuition by reverting the transaction when an operation overflows.


pragma solidity ^0.4.24;

import "@cpchain-tools/cpchain-contracts/utils/math/SafeMath.sol";

contract SafeMathMock {
    function mul(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.mul(a, b);
    }

    function div(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.div(a, b);
    }

    function sub(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.sub(a, b);
    }

    function add(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.add(a, b);
    }

    function mod(uint256 a, uint256 b) public pure returns (uint256) {
        return SafeMath.mod(a, b);
    }
}

ERC20

This implementation is agnostic to the way tokens are created. This means that a supply mechanism has to be added in a derived contract using _mint.


pragma solidity ^0.4.24;

import "@cpchain-tools/cpchain-contracts/token/ERC20/ERC20.sol";

// mock class using ERC20
contract ERC20Mock is ERC20 {
    constructor (address initialAccount, uint256 initialBalance)
        ERC20("CBDD", "CPChain Big Data Dashboard", 18, 0) public {
        _mint(initialAccount, initialBalance);
    }

    // Mint token
    function mint(address account, uint256 amount) public {
        _mint(account, amount);
    }

    // Burn token
    function burn(address account, uint256 amount) public {
        _burn(account, amount);
    }

    // burn allowanced token
    function burnFrom(address account, uint256 amount) public {
        _burnFrom(account, amount);
    }
}

Test Helpers

This is a package to help users test contracts.


npm install @cpchain-tools/dapps-test-helpers

For example:


const MathMock = artifacts.require('./mocks/MathMock.sol');
const { expect, BN  } = require('@cpchain-tools/dapps-test-helpers');

contract("MathMock", () => {
  const min = new BN('1234');
  const max = new BN('5678');
  let instance = null

  beforeEach(async ()=> {
    instance = await MathMock.new()
    assert.ok(instance)
  })

  // Max
  it('is correctly detected in first argument position', async function () {
    expect(await instance.max(max, min)).to.be.bignumber.equal(max);
  });

  it('is correctly detected in second argument position', async function () {
    expect(await instance.max(min, max)).to.be.bignumber.equal(max);
  });

})

Building/Testing


npm run test:coverage

npm run build