From d3200e333d899ea8f52af572c6a7732091671138 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Wed, 19 Feb 2020 16:32:29 +0100 Subject: [PATCH] fix: revert custom `deploy()` API for `EmbarkJS.Contract` `.deploy()` is an alias to `.new()` and in other tools also no longer used as API to deploy instances. In addition, we don't want it to shadow the original web3 `deploy()` API which actually caused a breeaking change. --- dapps/tests/app/test/simple_storage_deploy_spec.js | 13 ++++++++++++- packages/embarkjs/embarkjs/src/lib/blockchain.js | 6 ++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dapps/tests/app/test/simple_storage_deploy_spec.js b/dapps/tests/app/test/simple_storage_deploy_spec.js index d073de6c7..b5023ba34 100644 --- a/dapps/tests/app/test/simple_storage_deploy_spec.js +++ b/dapps/tests/app/test/simple_storage_deploy_spec.js @@ -5,7 +5,18 @@ const {Utils} = artifacts.require('EmbarkJS'); contract("SimpleStorage Deploy", function () { let simpleStorageInstance; before(async () => { - simpleStorageInstance = await SimpleStorage.deploy([150]); + return new Promise(async (resolve, reject) => { + const gas = await SimpleStorage.deploy({arguments: [150]}).estimateGas(); + + Utils.secureSend(web3, SimpleStorage.deploy({arguments: [150]}), {gas, from: web3.eth.defaultAccount}, true, function(err, receipt) { + if(err) { + return reject(err); + } + simpleStorageInstance = SimpleStorage; + simpleStorageInstance.options.address = receipt.contractAddress; + resolve(); + }); + }); }); it("should set constructor value", async function () { diff --git a/packages/embarkjs/embarkjs/src/lib/blockchain.js b/packages/embarkjs/embarkjs/src/lib/blockchain.js index 4a4018bb5..5689bd380 100644 --- a/packages/embarkjs/embarkjs/src/lib/blockchain.js +++ b/packages/embarkjs/embarkjs/src/lib/blockchain.js @@ -313,7 +313,7 @@ function Contract(options) { }); // Assign helpers too - for(const method of ["deploy", "new", "at", "send", "deployed"]) { + for(const method of ["new", "at", "send", "deployed"]) { // Make sure we don't override original methods here. if (originalMethods.includes(method)) { console.log(method + " is a reserved word and will not be aliased as a helper"); @@ -328,7 +328,7 @@ function Contract(options) { return ContractClass; } -Contract.prototype.deploy = function(args, _options, _txOptions) { +Contract.prototype.new = function(args, _options, _txOptions) { const self = this; const options = Object.assign({ arguments: args || [], @@ -358,8 +358,6 @@ Contract.prototype.deploy = function(args, _options, _txOptions) { return this._deployPromise; }; -Contract.prototype.new = Contract.prototype.deploy; - Contract.prototype.at = function(address) { return new Contract({abi: this.abi, code: this.code, address: address}); };