Coder Social home page Coder Social logo

paritytech / pallet-contracts-waterfall Goto Github PK

View Code? Open in Web Editor NEW
30.0 8.0 14.0 1.82 MB

Collection of simple Substrate smart contract examples written in Rust, AssemblyScript, Solang and the smart contract language ink! to test substrates pallet-contracts module

License: GNU General Public License v3.0

Shell 6.20% Rust 17.94% JavaScript 1.04% TypeScript 46.79% Solidity 28.03%
substrate smart-contracts rust polkadot-js assemblyscript solang ink

pallet-contracts-waterfall's Introduction

pallet-contracts test site

⚠️ This repository has been archived! ⚠️

It has been superseded by ink-waterfall.


This repo hosts tests for pallet-contracts.

It uses git submodules for some tests. To checkout the repository including the linked submodules, run the following command to clone it:

git clone --recursive https://github.com/paritytech/pallet-contracts-waterfall.git

Preparations

For running this test suite you would need to have:

  1. A nightly rust compiler equipped with the wasm32-unknown-unknown target.

    The easiest way to install it is with rustup. Please see https://rustup.rs.

    rustup toolchain install nightly
    rustup update
    rustup target add wasm32-unknown-unknown --toolchain nightly
    rustup component add rust-src --toolchain nightly

    Also, you might need to put cargo's bin directory on PATH. You can typically do it by executing:

    source ~/.cargo/env
  2. Yarn.

    Read on how to install it here.

  3. JavaScript test environment

    To install all depenmdencies used by the Jest testing suite, run the following command:

    yarn

    To upgrade to the latest versions of the Polkadot JS dependencies, run the following command:

    yarn upgrade --pattern @polkadot

  4. Initialize submodules manually

    If you cloned the repository without the --recursive parameter, you need to initialize the submodules manually:

    git submodule update --init
    

    If you were running this test suite before and want to update your local version to the latest master branches of the submodules, run:

    git submodule update --remote --merge
    

Compiling the examples

To build all artifacts required for running the tests, you need to invoke

./build.sh

This will also install https://github.com/WebAssembly/wabt on your computer.

Optional Solang test relying on Docker:

The recommended way to install Solang is currently to use the latest docker image from https://hub.docker.com/r/hyperledgerlabs/solang/tags. For this reason, the Solang tests-cases will only be compiled by running the build.sh script if Docker is installed and running on your machine. Alternatively you can also install Solang manually on your local machine.

Please see https://github.com/hyperledger-labs/solang for details.

Execute tests

To run the tests, launch the substrate node locally and run

yarn test

To only run a language specific subset of tests, the following commands are available:

Run AssemblyScript tests only: yarn test:as

Run Rust and ink! tests only: yarn test:rust

Run Solang tests only: yarn test:solang

Using a Docker image of Substrate for testing

To run this tests, you need to run a local Substrate on port ws://127.0.0.1:9944. The other alternative is to use one of the Docker images that are being automatically generated with every update to the master branch and published https://hub.docker.com/r/parity/substrate/.

The script to run this container is docker-compose.yml file in the root of this repository.

Before you can run this script, you need to install Docker and 'Docker Compose' on your machine. Please follow the steps described here (including the prerequisites): https://docs.docker.com/compose/install/

Usage:

  1. BUILD: Run docker-compose pull && docker-compose up to pull the latest docker imaged and run the Docker image of the latest Subtrate master.
  2. INFO: Run docker ps to get a list of Docker containers running in the background including their mapped ports on localhost
  3. QUIT: Run docker-compose down to stop and remove all running containers.

Provided endpoint for localhost: Substrate Master ws://127.0.0.1:9944/

Find more Docker images of Substrate https://hub.docker.com/r/parity/substrate/tags

pallet-contracts-waterfall's People

Contributors

athei avatar axelchalon avatar cmichi avatar dependabot[bot] avatar maxgraey avatar pepyakin avatar seanyoung avatar stefie avatar tripleight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pallet-contracts-waterfall's Issues

Integrate a simple ERC20 contract

ERC20 is a contract which is simple but still executes some amount of code. Adding such a contract to the test suite would be quite valueable.

A rough list of steps would be:

  1. compile inks example ERC20, obtaining the wasm binary and ABI
  2. deploy ERC20's code using put_code operation (see examples of other contracts)
  3. instantiate an ERC20 contract instance. Here one might need to use ABI to pass the correct input data for the init_value.
  4. call the transfer function on the contract to transfer tokens to another account,
  5. check if the balances are right using the balance_of function.

Feel free to ping me if you want to take this issue, I'd gladly provide more details or help if you are stuck.

CI broken for Solang test

The CI is throwing an error:
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory

Additional Info:

  • All tests are passing locally (with the latest versions)
  • Test are passing in the CI, if I'm commenting out the one Solang test
  • Cause of the error is the Solang setup in the CI
  • The problem has been around for a while, so it's no new behaviour related to any recent changes

I'm pretty sure it has something to do with the node configuration on Gitlab https://devcenter.heroku.com/articles/node-memory-use

Building the project leaves the git index dirty

I just tried building the project by calling ./build. Without any modification on my side this dirties my git index:

modified:   contracts/assemblyscript/flipper/package.json
modified:   contracts/assemblyscript/flipper/yarn.lock

This makes working with this project an unpleasant experience. The root cause seems to be these line in build.sh:
yarn add assemblyscript

Why not check in the proper version with the yarn.lock and be done? I noticed that there is a comment for this line that this is some kind of workaround. I think we need to check whether it is still needed.

Document how to get a contracts StorageKey

The StorageKey is needed to request any values from a smart contracts storage.

The plan is to provide a built-in function in srml-contracts to return the StorageKey of any given contract address.

As an interim solution, querying the substrate storage directly will give the required results:

How To:

1. Start a new Substrate development node with pruned database or use the docker image in this repository.

2. Deploy and instantiate the smart contract.

3. Open a new console window and paste the following code, to get the Keys of all modules in child_storage (currently only smart contracts):

curl -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method":"state_getKeys", "params":["0x3a6368696c645f73746f726167653a"], "id": 0}' -vv http://127.0.0.1:9933/

The result should look similar to this:
{"jsonrpc":"2.0","result":["0x3a6368696c645f73746f726167653a64656661756c743a275d68eb54aaa683c48f8920fc649f281898c92ea09bb0169d032bc808d765a2"],"id":0}

4. Copy the returned hex value as a param to this curl request:

curl -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method":"state_getChildKeys", "params": ["YOUR_HEX_VALUE", "0x"], "id": 0}' -vv http://127.0.0.1:9933/

Example:

curl -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method":"state_getChildKeys", "params": ["0x3a6368696c645f73746f726167653a64656661756c743a275d68eb54aaa683c48f8920fc649f281898c92ea09bb0169d032bc808d765a2", "0x"], "id": 0}' -vv http://127.0.0.1:9933/

5. Copy the returned value as your contracts StorageKey

Example reult:
{"jsonrpc":"2.0","result":["0xf40ceaf86e5776923332b8d8fd3bef849cadb19c6996bc272af1f648d9566a4c"],"id":0}

In this case, the StorageKey of the contract would be:
0xf40ceaf86e5776923332b8d8fd3bef849cadb19c6996bc272af1f648d9566a4c

Set up CI

Can you help us here, @TriplEight ?


  • build contract and run jest tests
  • change settings to 1 PR === 1 commit (SD: no idea where to that)
  • ....?

Assemblyscript flipper contract build is broken

cd contracts/assemblyscript/flipper
yarn
yarn build

ERROR TS2531: Object is possibly 'null'.

   const pointer = value ? value.dataStart : 0;
                           ~~~~~
 in assembly/lib.ts(30,26)

ERROR: Compile error
    at Object.main (/Users/alex/Developer/parity/pallet-contracts-waterfall/contracts/assemblyscript/flipper/node_modules/assemblyscript/cli/asc.js:584:21)
    at /Users/alex/Developer/parity/pallet-contracts-waterfall/contracts/assemblyscript/flipper/node_modules/assemblyscript/bin/asc:21:47

Write or copy tests for essential PolkadotJS API tests

The core functionality is already tested in the PolkadotJS API repo, but since the JS API currently is a core component in the contract ecosystem we should have our own tests in here.

There is no CI / no end to end tests implemented in the Polkadot JS API, that why it makes sense to run a subset of the tests daily in this repo.

See:
https://github.com/polkadot-js/api/tree/master/packages/api-contract/test
https://github.com/polkadot-js/api/blob/master/packages/api/test/e2e/api/promise-contract.spec.ts

Adjust getChildStorage function

The JS API currently doesn't support getting values from child storage through RPC with the latest substrate master.
This PR introduced 2 additional parameters for the childStorage RPC methods, so At the moment, the JS API expects 2, Substrate requires 4 parameters:
paritytech/substrate#4162

I already opened a ticket for that in the
polkadot-js/api#1679

Once implemented, we need to adjust thegetContractStorage function.

Integrate the delegator example from ink

Delegator is a more elaborate example that consists of multiple contracts and which among other things exercises cross-contract calls and instantiations.

A rough idea how we could integrate the test is as following:

  1. compile all contracts that the example comprises of: delegator (root), adder, subber, accumulator
  2. generate ABI definition for the delegator contract
  3. upload the wasm binaries using put_code
  4. instantiate the delegator contract using some default value
  5. then exercise the delegator by calling it and testing its return values

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.