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

Feature Request: allow plugins to generate contract classes to be used in test,console, & dapps #1066

Closed
ewingrj opened this issue Nov 9, 2018 · 3 comments

Comments

@ewingrj
Copy link

ewingrj commented Nov 9, 2018

Feature Request

Summary

Currently there is the method registerContractsGeneration that plugins can use. However, apparently this only affects the code loaded by the dapp.

It would be great if there was a hook that was called to generate the class instances for tests and console use.

This would greatly simplify the adoption process of converting an existing codebases over to using embark. Conversion would be as simple as minimal embark configuration and writing a simple plugin for the js instances their code is already using (or use an existing plugin). Then they are using embark and get cool features like code coverage, etc fairly painlessly.

A truffle compatible plugin would be a great 2nd plugin after moving the existing embark code to a plugin.

@0x-r4bbit
Copy link
Contributor

@perissology Hey man,

I was just looking into this and having a bit of a hard time following what exactly you're looking for as there's a bit information lacking.

After having a call with @jrainville as well on this, to sync up on both of our interpretations of this issue, we thought it'd be better to reach out to you to ask what your intention is.

Here's our understanding (consider that this involved a lot of self interpretation):

Currently there is the method registerContractsGeneration that plugins can use. However, apparently this only affects the code loaded by the dapp.

Correct, this API enables you to write a plugin which controls what the code looks like that'll be used later in the dapp to create (web3) instances of your contracts.

It would be great if there was a hook that was called to generate the class instances for tests and console use.

So this sounds like, you'd like to write a plugin, which controls the same thing, just for tests, as the contract instances for tests are currently completely controlled by Embark (we actually create those instances in memory and monkey-patch require() to look up your requested instance from there).

Is that correct, or are we on a wrong path here?

Looking forward to hearing back from you!

@0x-r4bbit
Copy link
Contributor

Quick update: had another chat meanwhile with @iurimatias and he could clarify and confirm that assumption above.

@ewingrj
Copy link
Author

ewingrj commented Nov 23, 2018

So this sounds like, you'd like to write a plugin, which controls the same thing, just for tests, as the contract instances for tests are currently completely controlled by Embark (we actually create those instances in memory and monkey-patch require() to look up your requested instance from there).

exactly. Would also be nice if these were loaded when you use embark console as well instead of the Embark instances

0x-r4bbit added a commit that referenced this issue Nov 26, 2018
This commit introduces a new API `registerTestContractFactory()` which can be
used to register a factory function for the creation of web3 contract instances
in the testing environment.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory((contractRecipe, web3) => {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

Closes #1066
0x-r4bbit added a commit that referenced this issue Nov 27, 2018
This commit introduces a new API `registerContractFactory()` which can be
used to register a factory function for the creation of web3 contract instances.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

- It's also used for `EmbarkJS.Blockchain.Contract` within `embark console`.
  In that scenario, this function has to be a constructor function and therefore
  cannot be registered using fat arrow functions. Also, we don't control what
  gets passed to that function in that scenario.

Closes #1066
0x-r4bbit added a commit that referenced this issue Nov 27, 2018
This commit introduces a new API `registerContractFactory()` which can be
used to register a factory function for the creation of web3 contract instances.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

- It's also used for `EmbarkJS.Blockchain.Contract` within `embark console`.
  In that scenario, this function has to be a constructor function and therefore
  cannot be registered using fat arrow functions. Also, we don't control what
  gets passed to that function in that scenario.

Closes #1066
0x-r4bbit added a commit that referenced this issue Nov 30, 2018
This commit introduces two new plugin APIs `registerTestContractFactory()` and
`registerCustomContractGenerator()`, which can be used to register a factory function
for the creation of web3 contract instances within tests, and custom code generation
  for `embark console` respectively.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerCustomContractGenerator(function (contractRecipe) {
    // returns code string that will be eval'ed
  });
};
```

**Notice that**:

- Once registered, this generator will be used for **all** contract instances
  that will be created for `embark console`, including built-in once like
  ENSRegistry.

- While this does affect contract creation in client-side code, it doesn't
  actually affect the instances created for deployment hooks **if** deployment
  hooks are written as functions.

Closes #1066
0x-r4bbit added a commit that referenced this issue Nov 30, 2018
This commit introduces two new plugin APIs `registerTestContractFactory()` and
`registerCustomContractGenerator()`, which can be used to register a factory function
for the creation of web3 contract instances within tests, and custom code generation
  for `embark console` respectively.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerCustomContractGenerator(function (contractRecipe) {
    // returns code string that will be eval'ed
  });
};
```

**Notice that**:

- Once registered, this generator will be used for **all** contract instances
  that will be created for `embark console`, including built-in once like
  ENSRegistry.

- While this does affect contract creation in client-side code, it doesn't
  actually affect the instances created for deployment hooks **if** deployment
  hooks are written as functions.

Closes #1066
0x-r4bbit added a commit that referenced this issue Dec 4, 2018
This commit introduces two new plugin APIs `registerTestContractFactory()` and
`registerCustomContractGenerator()`, which can be used to register a factory function
for the creation of web3 contract instances within tests, and custom code generation
  for `embark console` respectively.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerCustomContractGenerator(function (contractRecipe) {
    // returns code string that will be eval'ed
  });
};
```

**Notice that**:

- Once registered, this generator will be used for **all** contract instances
  that will be created for `embark console`, including built-in once like
  ENSRegistry.

- While this does affect contract creation in client-side code, it doesn't
  actually affect the instances created for deployment hooks **if** deployment
  hooks are written as functions.

Closes #1066

Always use custom generator and fallback to vanilla
0x-r4bbit added a commit that referenced this issue Dec 4, 2018
This commit introduces two new plugin APIs `registerTestContractFactory()` and
`registerCustomContractGenerator()`, which can be used to register a factory function
for the creation of web3 contract instances within tests, and custom code generation
  for `embark console` respectively.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerCustomContractGenerator(function (contractRecipe) {
    // returns code string that will be eval'ed
  });
};
```

**Notice that**:

- Once registered, this generator will be used for **all** contract instances
  that will be created for `embark console`, including built-in once like
  ENSRegistry.

- While this does affect contract creation in client-side code, it doesn't
  actually affect the instances created for deployment hooks **if** deployment
  hooks are written as functions.

Closes #1066

Always use custom generator and fallback to vanilla
0x-r4bbit added a commit that referenced this issue Dec 5, 2018
This commit introduces two new plugin APIs `registerTestContractFactory()` and
`registerCustomContractGenerator()`, which can be used to register a factory function
for the creation of web3 contract instances within tests, and custom code generation
  for `embark console` respectively.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerCustomContractGenerator(function (contractRecipe) {
    // returns code string that will be eval'ed
  });
};
```

**Notice that**:

- Once registered, this generator will be used for **all** contract instances
  that will be created for `embark console`, including built-in once like
  ENSRegistry.

- While this does affect contract creation in client-side code, it doesn't
  actually affect the instances created for deployment hooks **if** deployment
  hooks are written as functions.

Closes #1066

Always use custom generator and fallback to vanilla
0x-r4bbit added a commit that referenced this issue Dec 5, 2018
This commit introduces two new plugin APIs `registerTestContractFactory()` and
`registerCustomContractGenerator()`, which can be used to register a factory function
for the creation of web3 contract instances within tests, and custom code generation
  for `embark console` respectively.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerTestContractFactory(function (contractRecipe, web3) {
    // do something with web3 and contractRecipe and return contract instance here
  });
};
```

**Notice that**:

- This factory function is used for contract instance creation within tests.
  A `contractRecipe` and a `web3` instance is accessible within the factory.

Example:

```
// some.plugin.js

module.exports = function (embark) {
  embark.registerCustomContractGenerator(function (contractRecipe) {
    // returns code string that will be eval'ed
  });
};
```

**Notice that**:

- Once registered, this generator will be used for **all** contract instances
  that will be created for `embark console`, including built-in once like
  ENSRegistry.

- While this does affect contract creation in client-side code, it doesn't
  actually affect the instances created for deployment hooks **if** deployment
  hooks are written as functions.

Closes #1066

Always use custom generator and fallback to vanilla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants