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
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');
```
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.
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`.
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
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
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.
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
`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.
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
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.
`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.
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.
The `"qa:full"` script comes into play in the contexts of
`scripts/release.js` (`npm run release`) and `scripts/stable-release.js`
(`npm run release:stable`).
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.
This only affected the demo. We somehow put the `enableEthereum()`
call right before the Demo `set` function, so since we now throw
when it's not available, it stopped the `set`. But it was never
needed because demo has `autoEnadble` on, meaning that `enable` is
called at the start.
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.
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)
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.