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

feat: Workspace optimizer and other breaking changes! #106

Merged
merged 14 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ module.exports = {
env: {
browser: true,
es2021: true,
'jest/globals': true,
},
extends: [
'airbnb-base',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: {
Expand All @@ -13,9 +16,17 @@ module.exports = {
},
plugins: [
'@typescript-eslint',
'jest',
],
rules: {
'import/extensions': 0,
'import/no-unresolved': 0,
'no-underscore-dangle': 0,
'no-shadow': 0,
'import/prefer-default-export': 0,
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-var-requires': 'warn',
'@typescript-eslint/ban-types': 'warn',
},
ignorePatterns: ['/packages/**', 'jest.config.ts'],
};
148 changes: 99 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,58 +328,71 @@ task(async ({ wallets, refs, config, client }) => {
});
```

## Scripting deployments

As of Terrain 0.4.0 it is possible to deploy and instantiate contracts from tasks. This can be useful for multi-contract, or multi-stage deployments.

```js
const { task } = require("@terra-money/terrain");

task(async ({ wallets, client, deploy }) => {
// First deploy the counter smart contract.
const counterCodeId = await deploy.storeCode(wallets.test1, "counter");
await deploy.storeCode('counter', wallets.test1);
const counterAddress = await deploy.instantiate(
// Contract name
'counter',
// Signer
wallets.test1,
// Contract name
"counter",
// Code ID
counterCodeId,
// Instance ID
"default",
// Contract admin
wallets.test1.key.accAddress
{
// Contract admin
admin: wallets.test1.key.accAddress,
},
);

// Now deploy a CW20 with the counter contract set as the minter in instantiation.
const cw20CodeId = await deploy.storeCode(wallets.test1, "cw20-base");
await deploy.storeCode('cw20-base', wallets.test1);
const cw20Address = await deploy.instantiate(
'cw20-base',
wallets.test1,
"cw20-base",
cw20CodeId,
"default",
wallets.test1.key.accAddress,
// Custom instantiation message.
// with no message provided the default from config.terrain will be used.
{
name: "counter",
symbol: "CTR",
decimals: 6,
initial_balances: [],
mint: {
minter: counterAddress,
},
{
admin: wallets.test1.key.accAddress,
// Custom instantiation message.
// with no message provided the default from config.terrain will be used.
init: {
name: "counter",
symbol: "CTR",
decimals: 6,
initial_balances: [],
mint: {
minter: counterAddress,
},
}
}
);

// Update the CW20 address in counter.
// Note: It's important to use the address returned by deploy.instantiate
// Refs are only read into memory at the start of the task.
await client.execute(wallets.test1, counterAddress, {
await client.execute(counterAddress, wallets.test1, {
update_token: { token: cw20Address },
});

console.log(`CW20 Address: ${cw20Address}`);
});
```

It is possible to tell Terrain to use a custom deploy task instead of the default deploy process. To do this, add the following to the `_global` section in `config.terrain.json`:

```json
"contracts": {
"counter": {
"deployTask": "deploy_counter"
}
}
```

Now instead of running `terrain task:run deploy_counter` you can run `terrain deploy counter`.

---

# Migrating CosmWasm Contracts on Terra
Expand Down Expand Up @@ -419,7 +432,7 @@ pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Respons

## Migrating the Contract

In the previous Terrain tutorial, we deployed the contract, but did not initilize it as migratable.
In the previous Terrain tutorial, we deployed the contract, but did not initialize it as migratable.

After adding MigrateMsg to the smart contract, we can redeploy the contract and add the `--set-signer-as-admin` flag. This allows the transaction signer to migrate the contract in the future.

Expand Down Expand Up @@ -477,16 +490,18 @@ npm unlink terrain

<!-- commands -->
* [`terrain console`](#terrain-console)
* [`terrain contract:build CONTRACT`](#terrain-contractbuild-contract)
* [`terrain contract:generateClient CONTRACT`](#terrain-contractgenerateclient-contract)
* [`terrain contract:instantiate CONTRACT`](#terrain-contractinstantiate-contract)
* [`terrain contract:migrate CONTRACT`](#terrain-contractmigrate-contract)
* [`terrain contract:new NAME`](#terrain-contractnew-name)
* [`terrain contract:optimize CONTRACT`](#terrain-contractoptimize-contract)
* [`terrain contract:store CONTRACT`](#terrain-contractstore-contract)
* [`terrain contract:updateAdmin CONTRACT ADMIN`](#terrain-contractupdateadmin-contract-admin)
* [`terrain deploy CONTRACT`](#terrain-deploy-contract)
* [`terrain help [COMMAND]`](#terrain-help-command)
* [`terrain new NAME`](#terrain-new-name)
* [`terrain sync-refs [FILE]`](#terrain-sync-refs-file)
* [`terrain sync-refs`](#terrain-sync-refs)
* [`terrain task:new [TASK]`](#terrain-tasknew-task)
* [`terrain task:run [TASK]`](#terrain-taskrun-task)
* [`terrain test CONTRACT-NAME`](#terrain-test-contract-name)
Expand All @@ -503,10 +518,10 @@ USAGE
[--keys-path <value>]

FLAGS
--config-path=<value> [default: config.terrain.json]
--keys-path=<value> [default: keys.terrain.js]
--network=<value> [default: localterra]
--refs-path=<value> [default: refs.terrain.json]
--config-path=<value> [default: ./config.terrain.json]
--keys-path=<value> [default: ./keys.terrain.js]
--network=<value> [default: localterra] network to deploy to from config.terrain.json
--refs-path=<value> [default: ./refs.terrain.json]
--signer=<value> [default: test1]

DESCRIPTION
Expand All @@ -516,6 +531,26 @@ DESCRIPTION

_See code: [src/commands/console.ts](https://github.com/terra-money/terrain/blob/v0.5.8/src/commands/console.ts)_

## `terrain contract:build CONTRACT`

Build and optimize wasm bytecode.

```
USAGE
$ terrain contract:build [CONTRACT] [--optimize] [--arm64] [--config-path <value>]

FLAGS
--arm64 use rust-optimizer-arm64 for optimization. Not recommended for production, but it will optimize
quicker on arm64 hardware during development.
--config-path=<value> [default: ./config.terrain.json]
--optimize optimize the wasm.

DESCRIPTION
Build and optimize wasm bytecode.
```

_See code: [src/commands/contract/build.ts](https://github.com/terra-money/terrain/blob/v0.5.8/src/commands/contract/build.ts)_

## `terrain contract:generateClient CONTRACT`

Generate a Wallet Provider or Terra.js compatible TypeScript client.
Expand All @@ -541,15 +576,15 @@ Instantiate the contract.

```
USAGE
$ terrain contract:instantiate [CONTRACT] [--signer <value>] [--set-signer-as-admin] [--network <value>] [--config-path
<value>] [--refs-path <value>] [--keys-path <value>] [--instance-id <value>] [--code-id <value>]
$ terrain contract:instantiate [CONTRACT] [--signer <value>] [--network <value>] [--set-signer-as-admin] [--instance-id
<value>] [--code-id <value>] [--config-path <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
--code-id=<value> specfic codeId to instantiate
--code-id=<value> specific codeId to instantiate
--config-path=<value> [default: ./config.terrain.json]
--instance-id=<value> [default: default]
--keys-path=<value> [default: ./keys.terrain.js]
--network=<value> [default: localterra]
--network=<value> [default: localterra] network to deploy to from config.terrain.json
--refs-path=<value> [default: ./refs.terrain.json]
--set-signer-as-admin set signer (deployer) as admin to allow migration.
--signer=<value> [default: test1]
Expand Down Expand Up @@ -613,6 +648,25 @@ EXAMPLES

_See code: [src/commands/contract/new.ts](https://github.com/terra-money/terrain/blob/v0.5.8/src/commands/contract/new.ts)_

## `terrain contract:optimize CONTRACT`

Optimize wasm bytecode.

```
USAGE
$ terrain contract:optimize [CONTRACT] [--arm64] [--config-path <value>]

FLAGS
--arm64 use rust-optimizer-arm64 for optimization. Not recommended for production, but it will optimize
quicker on arm64 hardware during development.
--config-path=<value> [default: ./config.terrain.json]

DESCRIPTION
Optimize wasm bytecode.
```

_See code: [src/commands/contract/optimize.ts](https://github.com/terra-money/terrain/blob/v0.5.8/src/commands/contract/optimize.ts)_

## `terrain contract:store CONTRACT`

Store code on chain.
Expand Down Expand Up @@ -650,7 +704,7 @@ FLAGS
--config-path=<value> [default: ./config.terrain.json]
--instance-id=<value> [default: default]
--keys-path=<value> [default: ./keys.terrain.js]
--network=<value> [default: localterra]
--network=<value> [default: localterra] network to deploy to from config.terrain.json
--refs-path=<value> [default: ./refs.terrain.json]
--signer=<value> [default: test1]

Expand All @@ -666,20 +720,21 @@ Build wasm bytecode, store code on chain and instantiate.

```
USAGE
$ terrain deploy [CONTRACT] [--signer <value>] [--arm64] [--no-rebuild] [--set-signer-as-admin] [--network
<value>] [--config-path <value>] [--refs-path <value>] [--keys-path <value>] [--instance-id <value>]
[--admin-address <value>] [--frontend-refs-path <value>]
$ terrain deploy [CONTRACT] [--signer <value>] [--arm64] [--network <value>] [--no-rebuild]
[--set-signer-as-admin] [--instance-id <value>] [--frontend-refs-path <value>] [--admin-address <value>] [--no-sync
<value>] [--config-path <value>] [--refs-path <value>] [--keys-path <value>]

FLAGS
--admin-address=<value> set custom address as contract admin to allow migration.
--arm64 use rust-optimizer-arm64 for optimization. Not recommended for production, but it will
optimize quicker on arm64 hardware during development.
--config-path=<value> [default: ./config.terrain.json]
--frontend-refs-path=<value> [default: ./frontend/src/refs.terrain.json]
--frontend-refs-path=<value> [default: ./frontend/src/]
--instance-id=<value> [default: default] enable management of multiple instances of the same contract
--keys-path=<value> [default: ./keys.terrain.js]
--network=<value> [default: localterra]
--network=<value> [default: localterra] network to deploy to from config.terrain.json
--no-rebuild deploy the wasm bytecode as is.
--no-sync=<value> don't attempt to sync contract refs to frontend.
--refs-path=<value> [default: ./refs.terrain.json]
--set-signer-as-admin set signer (deployer) as admin to allow migration.
--signer=<value> [default: test1]
Expand Down Expand Up @@ -742,16 +797,16 @@ EXAMPLES

_See code: [src/commands/new.ts](https://github.com/terra-money/terrain/blob/v0.5.8/src/commands/new.ts)_

## `terrain sync-refs [FILE]`
## `terrain sync-refs`

Sync configuration with frontend app.

```
USAGE
$ terrain sync-refs [FILE] [--refs-path <value>] [--dest <value>]
$ terrain sync-refs [--refs-path <value>] [--dest <value>]

FLAGS
--dest=<value> [default: ./frontend/src/refs.terrain.json]
--dest=<value> [default: ./frontend/src/]
--refs-path=<value> [default: ./refs.terrain.json]

DESCRIPTION
Expand All @@ -776,8 +831,6 @@ _See code: [src/commands/task/new.ts](https://github.com/terra-money/terrain/blo

## `terrain task:run [TASK]`

run predefined task

```
USAGE
$ terrain task:run [TASK] [--signer <value>] [--network <value>] [--config-path <value>] [--refs-path
Expand All @@ -789,9 +842,6 @@ FLAGS
--network=<value> [default: localterra]
--refs-path=<value> [default: refs.terrain.json]
--signer=<value> [default: test1]

DESCRIPTION
run predefined task
```

_See code: [src/commands/task/run.ts](https://github.com/terra-money/terrain/blob/v0.5.8/src/commands/task/run.ts)_
Expand Down
9 changes: 6 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ export default {
// ],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
testPathIgnorePatterns: [
'/node_modules/',
'/lib/', // TODO: Make sure we don't exclude tests in src/lib
'/src/commands/test.ts',
'/packages/',
],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading