Commit Graph

5190 Commits

Author SHA1 Message Date
Anthony Laibe 7ac27a0f93 fix: first parallel deploy
Zero is falsy
2019-01-24 12:04:41 -05:00
Anthony Laibe 5968eef349 fix: simulator proxy with ws 2019-01-24 09:08:55 +00:00
emizzle 2613e6d683 feat(@embark/core): Recursively import contracts
Add support to recursively import contracts. If we have three contracts

1. A imports B
2. B imports C

Then prior to this PR, contract A would import contract B, and a remapping would be added to the contract so the compiler would know how to find contract B. However, contract B imports contracts C, and because the `parseFileForImport` method was not recursive, the remappings were not able to go one level deeper to remap the path to contract C, and thus the compiler would not know how to locate contract C, and would complain with the error `File outside of allowed directories.`

With the introduction of this PR, the `parseFileForImport` method is now recursive, and so any contract imported is also checked for it's own imports that can be remapped. Specifically, this use case is applicable when there is a dependency containing contracts that imports one of it's own dependency's contracts, ie:

```
pragma solididty ^0.5.0;

import "dependency-1/contract-1.sol";
```
where the dependencies look like:
```
|- node_modules
|--- dependency-1
|----- contract-1.sol <--- contains import "dependency-2/contract-2.sol"
|--- dependency-2
|----- contract-2.sol
```

Add unit tests that verify recursive imports work.
Add embark depdendency that installs a contract used in the recursive unit tests.
2019-01-22 14:46:38 +11:00
emizzle 02305fa4e5 fix(@embark/core): Fix contract testing with `remix_tests`
Remix_test-injected contract files were not correctly being tested due to an update in the `remix-tests` signature. I'm really not sure how tests were not completely bombing out during testing.

This PR introduces a few changes:

1. Ensure all contract files have been compiled before skipping compilation. This can occur if contract files have been added after a compilation round has already completed (ie in the tests).
2. Update solc tests to support latest `remix_tests.runTests` signature and include `userdoc` in compiled contracts.
3. Ensure `EmbarkJS` is reset before executing solc tests - like in the js tests, this is required for built EmbarkJS contract objects to behave correctly when it's functions are executed against the chain.
4. Refactor “all files already compiled” function.

BLOCKER: base branch `feat/replace-node-vm` must be merged in https://github.com/embark-framework/embark/pull/1234 before this can be merged.
2019-01-22 14:46:06 +11:00
emizzle c1a5bfee3c feat(@embark/core): Improve VM
Improve support for external requires. Allows external requires to be called like so:
```
Embark.events.on('runcode:ready', () => {
    Embark.events.emit('runcode:register', 'generateClass', require('eth-contract-class'), false);

    Embark.registerCustomContractGenerator(contract => {
      return `
        ${contract.className} = generateClass(${JSON.stringify(contract.abiDefinition)}, '${contract.code}');
        ${contract.className}Instance = new ${contract.className}(web3, '${contract.deployedAddress}');
        `;
    });
  });
  Embark.events.once('contracts:deploy:afterAll', () => {
    Embark.events.request('runcode:eval', 'SimpleStorageInstance', (err, SimpleStorageInstance) => {
      if(err) return console.error(err);
      SimpleStorageInstance.get().then((result) => {
        console.log(`=====> SimpleStorageInstance.get(): ${result}`);
      });
    });
  });
```

* Add `runcode:ready` that is fired when the VM is ready to accept registration of variables.
* Add support for registration of ES6 modules
* Add callback to `registerVar` and `setupNodeVm` in the `VM` class.
* Add support for retaining modified sandbox values across new VM instances.
* Add VM unit tests for external reaquries and modified sandbox state.
2019-01-22 10:26:32 +11:00
Jonathan Rainville df872fdd5b feat(compiler): add a new compiler api that checks for compatibility 2019-01-18 09:03:39 -05:00
Pascal Precht e72d6483df feat(@cockpit/transaction-decoder): allow for decoding raw transaction hashes 2019-01-17 10:40:33 +01:00
Anthony Laibe eab9aa57d7 feat(embark-ui): add storybook 2019-01-16 09:03:57 +00:00
Anthony Laibe 85db678f89 chores: rename env var 2019-01-16 09:03:46 +00:00
emizzle 9a9eb45836 feat(@embark/core): Run all code in VM2
All code to be run in the console is run through a completely sandboxed VM2 instance, instead of the default Node VM.

VM2 will only allow whitelisted packages in a `require` statement. The whitelisted packages needed to run EmbarkJS scripts are:
```
[
  "@babel/runtime-corejs2/helpers/interopRequireDefault",
  "@babel/runtime-corejs2/core-js/json/stringify",
  "@babel/runtime-corejs2/core-js/promise",
  "@babel/runtime-corejs2/core-js/object/assign",
  "eth-ens-namehash"
]
```

This can be circumvented in an Embark context (ie Plugin) if needed, for example in a Plugin constructor:
```
Embark.events.emit('runcode:register', 'require', require('lodash'), false);

Embark.events.request("runcode:eval", "_.head(['a', 'b', 'c', 'd']);", (err, result) => {
  if(err) return console.log('========> error: ' + err);
  console.log('========> ' + result);
});
```
Will emit `========> a`.

NOTE: Attempts to use this method to override `require` and `eval` should be handled by Embark and not allowed.

NOTE: VM2 seems to allow `eval`, however it is in a completely sandboxed environment, so I'm unsure that we need to be too concerned with this. Thoughts?

Refactor tests to use standalone instance of the newly created VM class, so that code is not evaluated through the console. This was done based on the new unit test case where accounts are redefined in a subsequent unit test, which was not originally working with the initial VM2 PR.

Refactor `codeRunner`, put all code-affecting logic in the `VM` class.

Changed `runCode` to `VM` and converted to TypeScript

Add unit tests for `VM`.
2019-01-16 10:16:54 +11:00
Jonathan Rainville bdb6719baf Revert "feat(blockchain/config): adds a cors command to add it to the config"
This reverts commit ebafe45f22.
2019-01-14 08:29:21 -05:00
Jonathan Rainville 84a74ac4a2 feat(blockchain/config): adds a cors command to add it to the config 2019-01-14 08:29:21 -05:00
Jonathan Rainville 1bafc41d97 change to use an object instead and change templates 2019-01-14 08:29:21 -05:00
Jonathan Rainville 9e349ff267 feat(blockchainConfig): enable having auto cors plus other origins 2019-01-14 08:29:21 -05:00
Jonathan Rainville 540ff751a9 fix(code-generator): use isDev instead of checking env 2019-01-14 10:33:42 +01:00
Anthony Laibe 1e4eaa5fb6 fix: allow to debug instanceOf contracts 2019-01-14 10:33:08 +01:00
emizzle 518d319917 fix(@embark/ipfs): Update IPFS config CORS with default config
Check if IPFS config has `API.HTTPHeaders.Access-Control-Allow-Origin` before attempting to update it.

`ipfs init` produces a default configuration without a `API.HTTPHeaders.Access-Control-Allow-Origin` element in the JSON. This caused an error to be thrown when attempting to update the IPFS config to provide CORS values.
2019-01-13 15:51:34 +01:00
Eric Mastro 05803fcf42
Merge pull request #1220 from embark-framework/feat/enable-regular-txs
feat(@embark/core): Disable regular txs until needed
2019-01-11 23:38:50 +11:00
Anthony Laibe 52d830a34b feat: allow to stop debugger 2019-01-11 11:46:50 +00:00
Iuri Matias 2d716e1101 chore(release): 4.0.0-beta.0 2019-01-10 13:07:10 -05:00
Anthony Laibe 34f5f97b28 feat: add option --no-single-use-cockpit-token
This option is added to run and console.
This can be usefull while developing on cockpit,
the auto reload don't always ask to authenticate
2019-01-10 12:05:01 +00:00
emizzle 135fde0a85 feat(@embark/core): Disable regular txs until needed
Regular transactions (aka “dev funds”) exist in embark as a workaround to a known bug in geth when using metamask. The workaround is to send a transaction at a regular interval (1.5s), which pushes through any transactions that were stuck. The problem is that the transaction logs and trace logs become cluttered and difficult to parse visually.

This PR disables regular transactions until the following conditions are met:
1. Embark is running geth
2. The user is running metamask in their browser
3. The user authenticates to the cockpit with `enableRegularTxs=1|true` in the query string.

A console warning is show in large letters in the browser with a link to the cockpit URL that includes the special query string to enable regular txs.

This could be extended later to have a button in the cockpit that start/stops regular txs. Or at least extended to allow disabling of regular txs once started.

Support standalone blockchain process.
2019-01-10 12:43:18 +11:00
Anthony Laibe 8efa8895aa feat: allow cockpit with docker 2019-01-09 17:35:28 -05:00
Anthony Laibe 2505fa5284 feat: add development mode to cockpit 2019-01-09 17:34:13 -05:00
emizzle 2613c56da7 feat(@embark-ui): Change page title and description
Update page title and description tags in the page head when the view changes.
2019-01-09 17:27:55 -05:00
Jonathan Rainville d0711305fc fix(contracts): fix linking libraries with long paths using output 2019-01-09 17:13:08 -05:00
Michael Bradley, Jr 2dea50ab13 fix(@embark/coderunner): use custom require function in vm context
Supply a custom require function to the vm context for `doEval` so that module
resolution succeeds for both DApp dependencies and Embark dependencies.
2019-01-09 17:12:16 -05:00
emizzle c6c6af01c9 Expose embark version to plugin constructor
Expose Embark’s version to the plugin constructor, allowing plugins to make logical decisions based on the version of Embark.
2019-01-09 16:56:47 -05:00
emizzle f54982254d fix(@embark/core): fix to allow large ether values
Specifying large ether values in the configs was causing embark to crash as javascript could not handle the large integer after the value was converted to wei.

The fix involves converting all values to BigNumbers and then comparing and adding/subtracting BigNumbers from that point forward.

There are two specific components that this affected: `config/contracts > accounts > balance` and `config/blockchain > account > balance`. The contracts config is used to fund accounts for contract deployment while the blockchain config is used for dev_funds accounts.

JSON.stringify unknown log messages

Add a unit test in the test app that sets a large ether value in the config before contract deployment and ensures the account balance is the value specified in the config.

Prior to this commit, if subsequent unit tests contained different account configurations, the blockchain VM was essentially reset, however EmbarkJS was hanging on to the old providers it used from the previous configuation.

In addition, there is a limitation with `embark.registerActionForEvent` in that the action will be persisted across configuration changes. In our case, once the configuration was updated in a subsequent unit test, the directive subdomains would be attempted to be registered in ENS using the old configuration.

This commit does two things:
1) It resets the EmbarkJS.Blockchain and EmbarkJS.Names providers to the new chain configuration
2) Update to the ENS directives that prevents attempts at registered configured subdomains for previous configurations.
2019-01-09 16:56:23 -05:00
Anthony Laibe d67863cff6 feat: add API server 2019-01-09 14:11:03 +00:00
Anthony Laibe df3435f02b feat: coverage without emit
For solc version below 0.4.21

fixes #1230
2019-01-09 13:44:48 +00:00
Jonathan Rainville 749c32cf07 fix(blockchain): fix metamask using the old web3 2019-01-08 09:24:13 -05:00
Michael Bradley, Jr 919d271996 feat(@embark/cli): unify command history without needing a restart
Send a message over IPC when a command is executed from the REPL so that
command history is immediately unified across `embark run` and one/more `embark
console`. Previously, for `embark console` to pick up a command entered in the
REPL of an `embark run` of which it was an IPC client it would have to be
restarted, and vice versa.
2019-01-07 17:02:28 -06:00
Iuri Matias 39d5e9f205 chore(release): 4.0.0-alpha.3 2018-12-31 15:10:59 -05:00
Iuri Matias 0958a17f3c refactor(@embark/contracts_manager) fix: The for-in loop variable 'className' should be explicitly scoped with var to avoid pollution 2018-12-24 16:14:01 -05:00
Iuri Matias d2a37f9bdf chore(@embark) remove extra line 2018-12-24 16:14:01 -05:00
Iuri Matias 035dfb84cf refactor(@embark/embark-ui) remove unused variables 2018-12-24 16:14:01 -05:00
Iuri Matias c693db9c2e refactor(@embark/embark-ui) remove usage of use strict 2018-12-24 16:14:01 -05:00
Michael Bradley, Jr 9e7bc53ebf fix(@embark/blockchain_process): proxy listens on the specified host
Change the blockchain proxy so that it listens on the `host` argument passed to
`Proxy#serve` rather than on `defaultHost`.
2018-12-21 22:06:46 -06:00
Michael Bradley d840198fc1 Revert "Fix for error running anything on Windows"
This reverts commit 0bea97c98a.
2018-12-21 21:45:57 -06:00
Wil Bown 0bea97c98a Fix for error running anything on Windows
I had to eject the webpack config and add this to get any project at all to run on Windows/Git Bash without this error:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.                                                                                                                                                                              ││  - configuration.context: The provided value "C:/Users/xxx/GitHub/xxxxxx" is not an absolute path!                                                                                                                                                                                              ││    -> The base directory (absolute path!) for resolving the `entry` option. If `output.pathinfo` is set, the included pathinfo is shortened to this directory.

Not sure if this is the best place, but should work on any platform.

Context (Environment)
OS: Windows 10, Git Bash v2.20.0 64bit
Embark Version: 3.2.7
Node Version: 10.14.2
NPM Version: 6.4.1
2018-12-21 13:01:41 -05:00
Jonathan Rainville d5f6da3599 fix(ens/web3): use blockchain connector for ens and fix global web3
Use the blockchain connector for the ENS module to remove direct web3 usages
Fix global web3 being overidden by the code generator
2018-12-21 12:55:39 -05:00
Jonathan Rainville 604e267e9d fix(proxy): delete old ids for accounts
Caused issues because the different ids come in
2018-12-21 12:55:39 -05:00
Jonathan Rainville 9a6149fef7 fix(gethClient): clear timeout when call backing 2018-12-21 12:48:41 -05:00
Jonathan Rainville b20bce9880 fix(ws): up fragmentation threshold to patch Geth bug with WS 2018-12-21 12:48:41 -05:00
Jonathan Rainville f2d6f609ba chore(browser): change Go to refresh since that's what they do 2018-12-21 12:48:13 -05:00
emizzle 1ccc3e7796 fix(@embark/core): Support legacy Parity version parsing
Parse legacy version of Parity. Pre-version 2 of Parity outputs “Parity <version>” instead of the post-version 2 “Parity-Ethereum”. Embark was emitting an error when the version of an older Parity client could not be parsed, and no warning messages regarding the version were shown.

This PR modifies the regex that parses the version so that older versions of Parity can be detected and the appropriate warning message can appear.
2018-12-21 11:49:21 -05:00
Michael Bradley, Jr a91a4dd7c0 feat(@embark/core): store IPC files in a dir within os.tmpdir()
This PR replaces #1202.

When embark is running on Linux and macOS, unix socket files are used for
geth's and embark's IPC files. A problem can arise if a DApp is in a deeply
nested directory structure such that character-length of the path to a socket
file exceeds the maximum supported length. See #450.

Also, if the DApp context is a Linux container running on a Windows Docker
host, and if the DApp is mounted from the host's file system, there is a
problem: unix socket files are incompatible with the Windows file system.

Solve both problems at once by storing a DApp's `.ipc` files in a directory
within `os.tmpdir()`. Introduce `ipcPath()` in `core/fs.js` and use a truncated
SHA-512 hash of the DApp's path in the name of the temporary directory created
for that purpose so that DApps won't collide (with an acceptably low
probability of collision).
2018-12-21 11:31:49 -05:00
Jonathan Rainville 9c37f9738e fix(debugger): fix debugger displays 2018-12-20 19:04:21 -05:00
Jonathan Rainville e207537d6e fix(profiler): do not exit on error but print it 2018-12-20 17:42:54 -05:00