1.0.0 • Published 3 months ago

devphase v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

devPHAse

Development tool for Phala Phat contracts.

Install

Add to your projects using package manager (yarn@^1 / npm)
Sadly yarn@^3 is not supported (check #4)

yarn add -D devphase
yarn add -D typescript ts-node # required peer dependencies

Commands

Global flags

--json                      # Prints result of command in json format
--verbosity=X               # Adjusts verbosity (0 - silent, 1 - default, 2 - verbose)

Project commands

  • Init project (creates required files and directories)
yarn devphase init
  • Check project configuration and dependencies
yarn devphase check

Stack related commands

  • Starting local stack (node + pruntime + pherry)
yarn devphase stack run [--save-log]
--save-log                  # Saves logs to file
  • Setup local stack (register gatekeeper, create cluster, deploy system contract etc.)
yarn devphase stack setup
-n, --network               # Switch network (local - by default)

Accounts management

  • Prints list of managed accounts (from ./accounts.json)
yarn devphase account list [--columns <value> | -x] [--sort <value>] [--filter <value>] [--output csv|json|yaml] [--csv | --no-truncate] [--no-header]
  • Creates new managed account
yarn devphase account create -a <value> [-p <value>] [-n]

-a, --alias=<value>         # (required) Account alias
-n, --no-passphrase         # Force no passphrase (prompted if not specified)
-p, --passphrase=<value>    # Passphrase used to protect keyring

Contracts management

  • Prints list of managed contracts (from ./contracts.json)
yarn devphase contract list [--columns <value> | -x] [--sort <value>] [--filter <value>] [--output csv|json|yaml] [--csv | --no-truncate] [--no-header]
  • Creates new contract project from template
yarn devphase contract create -n <value>
-n, --name=<value>          # (required) Contract name
  • Compiles contract using system cargo binary
yarn devphase contract compile [-c <value>] [-w] [-r]
-c, --contract=<value>      # Contract name
-r, --release               # Compile in release mode
-w, --watch                 # Watch changes
  • Deployes contract to network
yarn devphase contract deploy [ARGS] -c <value> -o <value> [-t InkCode|SidevmCode] [-n <value>] [-l <value>] [-a <value>]
ARGS                        # Constructor arguments
-a, --account=<value>       # [default: alice] Account used to deploy (managed account key)
-c, --contract=<value>      # (required) Contract name
-l, --cluster=<value>       # Target cluster Id
-n, --network=<value>       # [default: local] Target network to deploy (local default)
-o, --constructor=<value>   # (required) Contract constructor to call (name)
-t, --type=<option>         # [default: InkCode] <options: InkCode|SidevmCode>
  • Executes contract call
yarn devphase contract call [ARGS] -c <value> -i <value> -m <value> [-t InkCode|SidevmCode] [-a query|tx] [-n <value>] [-l <value>] [-a <value>]
ARGS                        # Call arguments
-a, --accessor=<option>     # [default: query] Method type: transaction or query <options: query|tx>
-a, --account=<value>       # [default: alice] Account used to call (managed account key)
-c, --contract=<value>      # (required) Contract name
-i, --id=<value>            # (required) Contract ID
-l, --cluster=<value>       # Target cluster Id
-m, --method=<value>        # (required) Contract method to call (name)
-n, --network=<value>       # [default: local] Target network to deploy (local default)
-t, --type=<option>         # [default: InkCode] <options: InkCode|SidevmCode>
  • Contracts TS bindings creation
yarn devphase contract typegen -c <value>
-c, --contract=<value>      # (required) Contract name
  • Testing with mocha
yarn devphase contract test [-s <value>] [-n <value>]
-n, --network=<value>       # [default: local] Network key
-s, --suite=<value>         # Test suite name (directory)

Configuration

Create devphase.config.ts in root directory (init command in TODO)

Here is default configuration. All values are optional (merged recuresivly)

import { ProjectConfigOptions } from 'devphase';

const config : ProjectConfigOptions = {
    /*
     * Project directories
     */
    directories: {
        artifacts: 'artifacts',
        contracts: 'contracts',
        logs: 'logs',
        stacks: 'stacks',
        tests: 'tests',
        typings: 'typings'
    },
    /*
     * Stack configuration
     * {
     *     [componentName : string]: {
     *          binary: string, // path to binary
     *          workingDir: string, // working directory as above
     *          evns: {
     *              [name: string]: string,
     *          },
     *          args: {
     *              [name: string]: string,
     *          },
     *          timeout: number // start up timeout
     *     }
     * }
     */
    stack: {
        blockTime: 6000, // default block time for direct stack running (may be overriden in testing mode)
        version: 'latest', // version which you want to pull from official repository (tag name) or "latest" one
        node: {
            port: 9944, // ws port
            binary: '{{directories.stacks}}/{{stack.version}}/phala-node',
            workingDir: '{{directories.stacks}}/.data/node',
            envs: {},
            args: {
                '--dev': true,
                '--rpc-methods': 'Unsafe',
                '--block-millisecs': '{{stack.blockTime}}',
                '--ws-port': '{{stack.node.port}}'
            },
            timeout: 10000,
        },
        pruntime: {
            port: 8000, // server port
            binary: '{{directories.stacks}}/{{stack.version}}/pruntime',
            workingDir: '{{directories.stacks}}/.data/pruntime',
            envs: {},
            args: {
                '--allow-cors': true,
                '--cores': 0,
                '--port': '{{stack.pruntime.port}}'
            },
            timeout: 2000,
        },
        pherry: {
            gkMnemonic: '//Alice', // gate keeper mnemonic
            binary: '{{directories.stacks}}/{{stack.version}}/pherry',
            workingDir: '{{directories.stacks}}/.data/pherry',
            envs: {},
            args: {
                '--no-wait': true,
                '--mnemonic': '{{stack.pherry.gkMnemonic}}',
                '--inject-key': '0000000000000000000000000000000000000000000000000000000000000001',
                '--substrate-ws-endpoint': 'ws://localhost:{{stack.node.port}}',
                '--pruntime-endpoint': 'http://localhost:{{stack.pruntime.port}}',
                '--dev-wait-block-ms': '{{stack.blockTime}}',
            },
            timeout: 2000,
        }
    },
    /**
     * Testing configuration
     */
    testing: {
        mocha: {}, // custom mocha configuration
        spawnStack: true, // spawn runtime stack? or assume there is running one
        stackLogOutput: false, // if specifed pipes output of all stack component to file (by default it is ignored)
        blockTime: 100, // overrides block time specified in node (and pherry) component
        envSetup: { // environment setup
            setup: {
                custom: undefined, // custom setup procedure callback; (devPhase) => Promise<void>
                timeout: 60 * 1000,
            },
            teardown: {
                custom: undefined, // custom teardown procedure callback ; (devPhase) => Promise<void>
                timeout: 10 * 1000,
            }
        },
    },
    /**
     * Networks configuration
     * Default network is local and it can be changed using CLI argument
     */
    networks: {
        local: {
            nodeUrl: 'ws://localhost:{{stack.node.port}}',
            nodeApiOptions: {
                types: {
                    ...KhalaTypes,
                    ...PhalaSDKTypes,
                }
            },
            workerUrl: 'http://localhost:{{stack.pruntime.port}}',
            blockTime: 6000, // network block time (may be overriden in testing mode)
        }
    },
    /**
     * Accounts fallback configuration
     * It is overriden by values saved in ./accounts.json
     */
    accountsConfig: {
        keyrings: {
            alice: '//Alice', // string (in case of mnemonic) or account keyring JSON
            bob: '//Bob',
            charlie: '//Charlie',
            dave: '//Dave',
            eve: '//Eve',
            ferdie: '//Ferdie'
        },
        suAccount: 'alice'
    }
};

export default config;

Usage sample

Check usage sample repo

Sandbox

Check sandbox environment repo for easy testing with up-to-date code

1.0.0

3 months ago

0.0.34-1

6 months ago

0.2.1

1 year ago

0.2.2

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.8

1 year ago

0.1.9

1 year ago

0.1.7

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2-1

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago