Commit Graph

843 Commits

Author SHA1 Message Date
Pascal Precht 40c3d98217 feat(plugins/scripts-runner): introduce exec command to run scripts
This commit introduces a new feature that enables users to run (migration) scripts.
Similar to deployment hooks, scripts are functions that may perform operations on newly
deployed Smart Contracts.

Therefore a script needs to export a function that has access to some dependencies:

```
// scripts/001-some-script.js

module.exports = async ({contracts, web3, logger}) => {
  ...
};
```

Where `contracts` is a map of newly deployed Smart Contract instances, `web3` a blockchain connector
instance and `logger` Embark's logger instance. Script functions can but don't have to be `async`.

To execute such a script users use the newly introduced `exec` command:

```
$ embark exec development scripts/001-some-script.js
```

In the example above, `development` defines the environment in which Smart Contracts are being
deployed to as well as where tracking data is stored.
Alternativey, users can also provide a directory in which case Embark will try to execute every
script living inside of it:

```
$ embark exec development scripts
```

Scripts can fail and therefore emit an error accordingly. When this happens, Embark will
abort the script execution (in case multiple are scheduled to run) and informs the user
about the original error:

```
.. 001_foo.js running....
Script '001_foo.js' failed to execute. Original error: Error: Some error
```

It's recommended for scripts to emit proper instances of `Error`.

(Migration) scripts can be tracked as well but there are a couple of rules to be aware of:

- Generally, tracking all scripts that have been executed by default is not a good thing because
  some scripts might be one-off operations.
- OTOH, there might be scripts that should always be tracked by default
- Therefore, we introduce a dedicated `migrations` directory in which scripts live that should be
  tracked by default
- Any other scripts that does not live in the specified `migrations` directory will not be tracked **unless**
- The new `--track` option was provided

For more information see: https://notes.status.im/h8XwB7xkR7GKnfNh6OnPMQ
2020-02-12 16:47:04 -06:00
Michael Bradley, Jr 0f59e0c216 fix(core/config): Fix `EmbarkConfig` type 2020-02-12 17:12:31 -05:00
Pascal Precht b021689387 feat(@embark/test-runner): introduce artifacts.require API
This commit adds a convenience API `artifacts.require(name)` that aims to make
requiring artifacts a little bit more straight forward.

Usage:

```
const SimpleStorage = artifacts.require('SimpleStorage');
const EmbarkJS = artifacts.require('EmbarkJS');
```
2020-02-12 14:17:30 -05:00
Andre Medeiros 70313352a5 fix: set helper methods on contracts
Set these up so we can call `deploy`, `at`, and `new` on contract
classes.
2020-02-12 14:14:13 -05:00
EmbarkBot e29a93bde5 chore(prerelease): 5.2.0-nightly.1 2020-02-08 00:12:06 +00:00
Jonathan Rainville 5592753116 fix(@embark/blockchain-api): add back contract event listen and log
Adds back the watch on contract events and writes them to a file
with the same method as contract logs from transaction-logger, so
I extracted those methods to utils/file so that both could use the
same functions.
2020-02-07 14:24:03 -05:00
Jonathan Rainville 87a04cd5db fix(@embark/contracts-manager): always deploy contracts with deploy: true
This was an issue experienced with ENS contracts not being deployed
because the configs used `strategy: explicit` and ENS configs are
not in configs.
To fix, I changed the way we check for deploy. If `deploy` is set as
`true` it should always deploy even if not in configs. It just means
they were added from a plugin (like ENS)
Also, I needed to set to `false` the `deploy` property of contracts
compiled that were not in config, because otherwise, they tried to
deploy, which goes against the strategy. This is because those
contracts get initiated as `deploy: true`.
2020-02-07 14:23:45 -05:00
Jonathan Rainville 0e30bf3926 fix(@embark/test-runner): fix reporter to only catch gas for txs
Before, we added the gas for all receipts that came in because they
had a `gasUsed`, instead of adding the gas for receipts that came
with a transaction
2020-02-07 14:20:31 -05:00
EmbarkBot a016fa8fb9 chore(prerelease): 5.2.0-nightly.0 2020-02-07 00:12:17 +00:00
Pascal Precht 3e3b4287a4 chore(stack/deployment): update dependencies 2020-02-06 13:19:10 -05:00
Jonathan Rainville 78fc7b6a90 fix(@embark/ens): fix tests erroring on FIFS contract deploy
Was caused by the contract being added in case another contract uses
it as a dependency, but it automatically tried to deploy with it, so
instead, set it as `deploy: false` until we see if we need to
register it
2020-02-06 13:17:20 -05:00
emizzle d5294203b7 fix(@embark/contracts-manager): Remove `logger` from serialized contract
For all instances where a `Contract` instance is serialized using `JSON.stringify`, the `logger` property was being stringified and written to logs and contract artifact files.

Add Serializer class that allows ignoring of class properties during serialization when using `JSON.stringify`.

NOTE: The `Serializer` relies on TypeScript’s decorators which are still listed as experimental (requiring the necessary compiler flag) despite being around for several years. Decorators are a stage 2 proposal for JavaScript.
2020-02-06 12:37:29 -05:00
Jonathan Rainville de0102223d feat(@mbark/ens): enable the use of $accounts in registrations
Enable putting `$accounts[i]` in subdomain registrations, where `i`
is the index of the `getAccounts` array.
This is the same behaviour we have for contract deployement
2020-02-06 12:36:36 -05:00
EmbarkBot a71211e863 chore(prerelease): 5.1.2-nightly.1 2020-02-06 00:11:14 +00:00
Pascal Precht 88c8135d9c refactor(core/engine): make serviceMonitor a module group
`Engine`s internal `coreComponents()` API sets up a bunch of things like
a `ProcessManager` and the `ServiceMonitor`. The `ServiceMonitor` activates
itself on `embark:engine:started` and practically monitors registered services
until the process has been explicitly stopped.

There are some commands that don't actually need service monitoring like `build` and
a future `exec` command that's in the making. For those cases it's useful to have them
disable the service monitor when `coreComponents()` is used.

This commit moves the `ServiceMonitor` instantiation out of `coreComponents()` and introduces
a new module group instead. This then lets commands that need service monitoring instantiate it
explicitly.
2020-02-05 13:47:18 +01:00
EmbarkBot d4136ffa8a chore(prerelease): 5.1.2-nightly.0 2020-02-05 00:12:23 +00:00
Jonathan Rainville 5359cc63da fix(@embark/cmd-controller): exit build if afterDeploy is not array
Before, `embark build` would wait at the end if there was an
afterDeploy, because there was no way with the old string and array
syntax to know when the commands were done.
Now, with the function syntax, we can wait for the end.
This way, we can exit the build at the end if it is a function
afterDeploy.
Otherwise, we show a message saying that they should update
2020-02-04 12:46:49 -05:00
Jonathan Rainville f502650c17 fix: only show account warning when Geth will actually start
Before, we checked if the network was a testnet or mainnet and
warned if there were no account sconfigured to sync. However, that
didn't take into account that we could connect to an external node,
hence not starting Geth at all.
So to fix that, I moved the condition and message to the Geth module
and only log when we start the node and the condition is met.
2020-02-04 12:45:32 -05:00
Michael Bradley, Jr 63831f6110 fix(@embark/dashboard): update dashboard's `logEntry` to match core/logger's `logFunction`
`packages/embark/src/cmd/dashboard/dashboard.js` overwrites the logger
instance's `logFunction` method with a method named `logEntry` defined on the
class exported from `packages/embark/src/cmd/dashboard/monitor.js`. Update
`logEntry` in the same way as `logFunction` was revised in #2184.
2020-02-04 11:30:45 -06:00
Michael Bradley, Jr 5b988ead7a refactor(@embark/core): refactor logger to provide correct origins
Also make a few more revisions:

Revise the "write logs" testing strategy such that it's not necessary for the
logger functions to take an optional callback.

Drop unused `tmp` package from `packages/core/logger` since it's not used in
the tests.

Strip colors before writing to the log file, use a two-space delimiter between
sections of each logged line in the log file, and collapse whitespace in the
message section of each line. These changes make the log file more amenable to
being processed with cli tools such as awk, cut, etc. It's also possible in a
text editor to replace `'  '` with `\t` and then load the file in a spreadsheet,
with each line-section in its own column.

Rearrange the sections of each logged line so that it's easier to read, and
only include the origin if the loglevel is debug or trace.
2020-02-03 20:47:23 -06:00
Pascal Precht 60cbb9fa3e refactor(@embark/core): make logger async when writing to log file 2020-02-03 20:47:23 -06:00
Pascal Precht 8c9e6b11c8 refactor(@embark/core): refactor logger to use modern JS APIs
This also removes `parseLogFile()` as it's not used anywhere inside Embark.
2020-02-03 20:47:23 -06:00
Pascal Precht 6b4052ee7b test(@embark/core): add tests for logger module 2020-02-03 20:47:23 -06:00
Michael Bradley, Jr 110957f273 chore(release): 5.1.1 2020-02-03 13:59:08 -06:00
Michael Bradley, Jr 030fb4acc6 build(deps): bump web3[-*] from 1.2.4 to 1.2.6
Remove `bignumber.js` workaround (in the root, from PR #2152) because it's no
longer needed (verified locally).

Remove the `"skipLibCheck"` workaround (in `packages/plugins/solidity-tests`,
from PR #2152) because it's no longer needed (verified locally).

Refactor a typing in `packages/plugins/geth`. What's happening is that in web3
v1.2.4 `sendTransaction` has a return type of `PromiEvent<TransactionReceipt>`
but in v1.2.6 it has a return type of `PromiEvent<TransactionReceipt |
TransactionRevertInstructionError>`.

Compare:
* [v1.2.4/packages/web3-eth/types/index.d.ts#L291-L294](https://github.com/ethereum/web3.js/blob/v1.2.4/packages/web3-eth/types/index.d.ts#L291-L294)
* [v1.2.6/packages/web3-eth/types/index.d.ts#L295-L298](https://github.com/ethereum/web3.js/blob/v1.2.6/packages/web3-eth/types/index.d.ts#L295-L298)

The problem is that the `TransactionRevertInstructionError` type doesn't have a
`transactionHash` property. Since at present the code in
`packages/plugins/geth/src/devtxs.ts` only deals with the success case re:
`sendTransaction`, import the `TransactionReceipt` type from `web3-eth` and
cast the resolved return value's type using TypeScript's `as` operator.
2020-02-03 10:17:07 -06:00
Jonathan Rainville 5fc96c089f chore(@embarkens): update ENS Registry mainnet address
Change address to the updated one because of a flaw found in the old
2020-02-03 09:34:11 -06:00
Michael Bradley, Jr 7b16e834e5 build(deps): remove unused package node-http-proxy-json 2020-02-03 09:26:06 -06:00
EmbarkBot 6b502e14d8 chore(prerelease): 5.1.1-nightly.4 2020-02-03 00:13:02 +00:00
dependabot-preview[bot] abfba2d829 build(deps-dev): bump history from 4.7.2 to 4.10.1
Bumps [history](https://github.com/ReactTraining/history) from 4.7.2 to 4.10.1.
- [Release notes](https://github.com/ReactTraining/history/releases)
- [Changelog](https://github.com/ReactTraining/history/blob/master/createBrowserHistory.js)
- [Commits](https://github.com/ReactTraining/history/compare/v4.7.2...v4.10.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-02 13:52:49 -06:00
dependabot-preview[bot] b973a36fec build(deps): bump babel-plugin-module-resolver from 3.2.0 to 4.0.0
Bumps [babel-plugin-module-resolver](https://github.com/tleunen/babel-plugin-module-resolver) from 3.2.0 to 4.0.0.
- [Release notes](https://github.com/tleunen/babel-plugin-module-resolver/releases)
- [Changelog](https://github.com/tleunen/babel-plugin-module-resolver/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tleunen/babel-plugin-module-resolver/compare/v3.2.0...v4.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-02 13:42:54 -06:00
dependabot-preview[bot] 58bc342c1c build(deps-dev): bump velocity-react from 1.4.1 to 1.4.3
Bumps [velocity-react](https://github.com/twitter-fabric/velocity-react) from 1.4.1 to 1.4.3.
- [Release notes](https://github.com/twitter-fabric/velocity-react/releases)
- [Changelog](https://github.com/google-fabric/velocity-react/blob/master/CHANGELOG.md)
- [Commits](https://github.com/twitter-fabric/velocity-react/compare/v1.4.1...v1.4.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-02 13:32:07 -06:00
EmbarkBot a9807b77f5 chore(prerelease): 5.1.1-nightly.2 2020-01-31 00:12:28 +00:00
Michael Bradley, Jr c4ad3d63e7 build(deps-dev): update other @storybook packages to 5.3.9
This follows on PR #2227.

Satisfy new peer dependencies following the bumps: `@storybook/core`,
`regenerator-runtime`.

Follow storybook's instructions to add `@storybook/preset-create-react-app` as
a dependency and also add the needed `.storybook/main.js` in
`packages/cockpit/ui/`.

Storybook is sensitive to presets being in the immediate project's
`node_modules` so add a `"nohoist"` in the root `package.json` for
`"embark-ui/@storybook/**"`.

After making the changes above, problems related to babel were observed when
running `yarn start`. It has been known for some time that having the root
babel config's dependencies spec'd in
`packages/utils/collective/package.json` (which is the package that actually
drives the babel cli) could lead to problems related to deduping, but such
problems hadn't been experienced until now. Move the dependencies relevant to
the root `babel.config.js` into the root `package.json` and update the
explanatory comment in the config.
2020-01-30 17:21:47 -06:00
EmbarkBot a5c7527d68 chore(prerelease): 5.1.1-nightly.1 2020-01-30 00:12:57 +00:00
Jonathan Rainville 3ceac534e1 fix(@embark/ens): fix registerSubDomain in tests and add test
registerSubDomain  didn't work in tests because it used the old way
of checking the env, which is checking the `this.env` string, but in
tests, we use the `test` env. So instead, we now check if it is a
known network using the network ID (like we do for other place)
2020-01-29 12:54:10 -05:00
dependabot-preview[bot] 3f583761bd build(deps-dev): bump @storybook/addon-links from 5.2.7 to 5.3.9
Bumps [@storybook/addon-links](https://github.com/storybookjs/storybook/tree/HEAD/addons/links) from 5.2.7 to 5.3.9.
- [Release notes](https://github.com/storybookjs/storybook/releases)
- [Changelog](https://github.com/storybookjs/storybook/blob/next/CHANGELOG.md)
- [Commits](https://github.com/storybookjs/storybook/commits/v5.3.9/addons/links)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-29 12:52:09 -05:00
Jonathan Rainville 2f5c16b8cd fix(@embark/contracts): fix ENS contracts not being resolved as deps
This was caused by the fact that we add the ENS contract to the
manager when before they deploy, but the dependency resolution was
done while building the contracts, so even before.
So the solution was to add a "before build" action so that the ENS
module could add its contracts to the manager if needed.
2020-01-29 10:15:48 -05:00
EmbarkBot 03ca790ffd chore(prerelease): 5.1.1-nightly.0 2020-01-29 00:12:23 +00:00
Iuri Matias d328b9953a chore: update site urls 2020-01-28 12:07:17 -05:00
Pascal Precht f5db7fe88d chore(stack/communication): update module dependencies 2020-01-28 11:36:24 -05:00
Michael Bradley, Jr 0d1da2971c chore(release): 5.1.0 2020-01-27 12:33:50 -06:00
Jonathan Rainville 0a4d13f64c fix(@embark/pipeline): make generateAll async so it completes tasks
generateAll was async, but it called the write functions with a sync
loop, so at the end of the function, the files were not written yet.
This is a problem in `embark build` because the process ends after
genrateAll is done, so no artifacts were written
2020-01-27 09:26:25 -05:00
EmbarkBot c891c2de95 chore(prerelease): 5.1.0-nightly.6 2020-01-25 00:12:13 +00:00
Iuri Matias 292331f229 bugfix(@embark/console): fix included package files 2020-01-24 15:21:58 -05:00
EmbarkBot 84448f8732 chore(prerelease): 5.1.0-nightly.5 2020-01-24 00:10:58 +00:00
dependabot-preview[bot] 9caa424aeb build(deps): bump solc from 0.5.0 to 0.6.1
Make various related changes to templates, tests, etc. The methodology for
finding files that needed changes was to search through the whole monorepo for
the strings "solc" and "solidity" and then inspect the hits to see whether
changes were needed/appropriate.

Remove `solc` as a dependency in `packages/embark/package.json` so that it's
only a proper dependency in `packages/plugins/solidity/package.json`. Adjust
how the "bundled" `solc` package's version is determined, i.e. inspect the
`package.json` of `embark-solidity` instead of `embark`.

When `solc`'s version is `>=0.6.0` use the [new callback API][api].

[api]: https://github.com/ethereum/solc-js/blob/master/README.md#example-usage-with-import-callback
2020-01-23 14:20:42 -05:00
Jonathan Rainville b6856b2083 fix(@embark/test): increase default gas limit to 8M so tests support bigger contracts
Was needed for the Teller Dapp as its Escrow contract is too big for the other default
2020-01-23 14:01:20 -05:00
Marc b8f93ea2ad fix(@embark/embarkjs): change enableEthereum to not rely on returned accounts array
Some ethereum providers (e.g. Opera implementation) do not return the accounts array in the 'enable' call.
2020-01-23 11:49:24 -06:00
Jonathan Rainville df2aaabfc3 refactor(@embark/transaction-logger): change log storage and read
Changes the way the logs are stored to straight up be logged as an
array and then reads it as such. It also removes the reverse from
the read and puts it in the UI instead since it's the UI that needs
it reversed.
2020-01-23 11:49:09 -05:00
Pascal Precht d0d584a934 refactor(@embark/core): move console source out of lib folder 2020-01-23 10:11:58 -05:00