fix(@embark/core): ensure 0x0 address are extended to full zero addresses

This was a regression introduced in a web3 upgrade where `0x0` addresses where no longer
accepted as valid addresses and have to be replaced with full zero addresses.

This commit ensures that, if Embark apps still make use of `0x0` addresses in
their configs, they are properly replaced or extended to satisfy web3's APIs.

Fixes #956
This commit is contained in:
Pascal Precht 2018-11-14 10:35:13 +01:00 committed by Pascal Precht
parent 70a61c5965
commit d3f6b43986
5 changed files with 155 additions and 52 deletions

94
npm-shrinkwrap.json generated
View File

@ -3819,7 +3819,7 @@
"dependencies": {
"colors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
"resolved": "http://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
}
}
@ -10892,8 +10892,7 @@
"pem-jwk": "^1.5.1",
"protons": "^1.0.1",
"rsa-pem-to-jwk": "^1.1.3",
"tweetnacl": "^1.0.0",
"webcrypto-shim": "github:dignifiedquire/webcrypto-shim#190bc9ec341375df6025b17ae12ddb2428ea49c8"
"tweetnacl": "^1.0.0"
},
"dependencies": {
"base-x": {
@ -10911,6 +10910,10 @@
"requires": {
"base-x": "^3.0.2"
}
},
"webcrypto-shim": {
"version": "github:dignifiedquire/webcrypto-shim#190bc9ec341375df6025b17ae12ddb2428ea49c8",
"from": "github:dignifiedquire/webcrypto-shim#190bc9ec341375df6025b17ae12ddb2428ea49c8"
}
}
},
@ -12625,12 +12628,12 @@
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
},
"node-notifier": {
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-4.6.1.tgz",
"resolved": "http://registry.npmjs.org/node-notifier/-/node-notifier-4.6.1.tgz",
"integrity": "sha1-BW0UJE89zBzq3+aK+c/wxUc6M/M=",
"requires": {
"cli-usage": "^0.1.1",
@ -15762,7 +15765,6 @@
"resolved": "https://registry.npmjs.org/web3/-/web3-0.20.6.tgz",
"integrity": "sha1-PpcwauAk+yThCj11yIQwJWIhUSA=",
"requires": {
"bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934",
"crypto-js": "^3.1.4",
"utf8": "^2.1.1",
"xhr2": "*",
@ -15771,7 +15773,7 @@
"dependencies": {
"bignumber.js": {
"version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934",
"from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git"
"from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934"
}
}
}
@ -15803,7 +15805,7 @@
"dependencies": {
"acorn": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz",
"resolved": "http://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz",
"integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo="
},
"ajv": {
@ -15822,7 +15824,7 @@
},
"ansi-escapes": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz",
"resolved": "http://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz",
"integrity": "sha1-06ioOzGapneTZisT52HHkRQiMG4="
},
"ansi-styles": {
@ -15832,7 +15834,7 @@
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"requires": {
"ansi-styles": "^2.2.1",
@ -15860,7 +15862,7 @@
},
"doctrine": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
"resolved": "http://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz",
"integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=",
"requires": {
"esutils": "^2.0.2",
@ -15869,7 +15871,7 @@
},
"eslint": {
"version": "2.10.2",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-2.10.2.tgz",
"resolved": "http://registry.npmjs.org/eslint/-/eslint-2.10.2.tgz",
"integrity": "sha1-sjCUgv7wQ9MgM2WjIShebM4Bw9c=",
"requires": {
"chalk": "^1.1.3",
@ -15908,7 +15910,7 @@
},
"eslint-plugin-react": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-5.2.2.tgz",
"resolved": "http://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-5.2.2.tgz",
"integrity": "sha1-fbBo4fVIf2hx5N7vNqOBwwPqwWE=",
"requires": {
"doctrine": "^1.2.2",
@ -15917,7 +15919,7 @@
},
"espree": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/espree/-/espree-3.1.4.tgz",
"resolved": "http://registry.npmjs.org/espree/-/espree-3.1.4.tgz",
"integrity": "sha1-BybXrIOvl6fISY2ps2OjYJ0qaKE=",
"requires": {
"acorn": "^3.1.0",
@ -15963,7 +15965,7 @@
},
"inquirer": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-0.12.0.tgz",
"resolved": "http://registry.npmjs.org/inquirer/-/inquirer-0.12.0.tgz",
"integrity": "sha1-HvK/1jUE3wvHV4X/+MLEHfEvB34=",
"requires": {
"ansi-escapes": "^1.1.0",
@ -15988,7 +15990,7 @@
},
"onetime": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k="
},
"pluralize": {
@ -15998,7 +16000,7 @@
},
"progress": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz",
"resolved": "http://registry.npmjs.org/progress/-/progress-1.1.8.tgz",
"integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74="
},
"restore-cursor": {
@ -16025,17 +16027,17 @@
},
"shelljs": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.6.1.tgz",
"resolved": "http://registry.npmjs.org/shelljs/-/shelljs-0.6.1.tgz",
"integrity": "sha1-7GIRvtGSBEIIj+D3Cyg3Iy7SyKg="
},
"slice-ansi": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz",
"resolved": "http://registry.npmjs.org/slice-ansi/-/slice-ansi-0.0.4.tgz",
"integrity": "sha1-7b+JA/ZvfOL46v1s7tZeJkyDGzU="
},
"standard": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/standard/-/standard-7.1.2.tgz",
"resolved": "http://registry.npmjs.org/standard/-/standard-7.1.2.tgz",
"integrity": "sha1-QBZu7sJAUGXRpPDj8VurxuJ0YH4=",
"requires": {
"eslint": "~2.10.2",
@ -16059,7 +16061,7 @@
},
"table": {
"version": "3.8.3",
"resolved": "https://registry.npmjs.org/table/-/table-3.8.3.tgz",
"resolved": "http://registry.npmjs.org/table/-/table-3.8.3.tgz",
"integrity": "sha1-K7xULw/amGGnVdOUf+/Ys/UThV8=",
"requires": {
"ajv": "^4.7.0",
@ -16096,7 +16098,7 @@
},
"web3": {
"version": "0.20.6",
"resolved": "https://registry.npmjs.org/web3/-/web3-0.20.6.tgz",
"resolved": "http://registry.npmjs.org/web3/-/web3-0.20.6.tgz",
"integrity": "sha1-PpcwauAk+yThCj11yIQwJWIhUSA=",
"requires": {
"bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934",
@ -16805,6 +16807,14 @@
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz",
"integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"eth-lib": {
"version": "0.1.27",
"resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.1.27.tgz",
@ -17057,28 +17067,17 @@
"integrity": "sha1-fecPG4Py3jZHZ3IVa+z+9uNRbrM=",
"requires": {
"underscore": "1.8.3",
"web3-core-helpers": "1.0.0-beta.34",
"websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2"
"web3-core-helpers": "1.0.0-beta.34"
},
"dependencies": {
"websocket": {
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible",
"from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"requires": {
"debug": "^2.2.0",
"nan": "^2.3.3",
"typedarray-to-buffer": "^3.1.2",
"yaeti": "^0.0.6"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
}
}
}
@ -17112,6 +17111,7 @@
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible",
"requires": {
"debug": "^2.2.0",
"nan": "^2.3.3",
"typedarray-to-buffer": "^3.1.2",
"yaeti": "^0.0.6"
@ -20921,8 +20921,19 @@
"integrity": "sha1-fecPG4Py3jZHZ3IVa+z+9uNRbrM=",
"requires": {
"underscore": "1.8.3",
"web3-core-helpers": "1.0.0-beta.34",
"websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2"
"web3-core-helpers": "1.0.0-beta.34"
},
"dependencies": {
"websocket": {
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"requires": {
"debug": "^2.2.0",
"nan": "^2.3.3",
"typedarray-to-buffer": "^3.1.2",
"yaeti": "^0.0.6"
}
}
}
},
"web3-shh": {
@ -21266,8 +21277,7 @@
"integrity": "sha1-bUZ4Geoi3foba6FJjTHZVU4rBt0=",
"requires": {
"underscore": "1.8.3",
"web3-core-helpers": "1.0.0-beta.27",
"websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2"
"web3-core-helpers": "1.0.0-beta.27"
},
"dependencies": {
"debug": {
@ -21285,7 +21295,7 @@
},
"websocket": {
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible",
"from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
"requires": {
"debug": "^2.2.0",
"nan": "^2.3.3",
@ -21351,10 +21361,6 @@
}
}
},
"webcrypto-shim": {
"version": "github:dignifiedquire/webcrypto-shim#190bc9ec341375df6025b17ae12ddb2428ea49c8",
"from": "github:dignifiedquire/webcrypto-shim#master"
},
"webidl-conversions": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",

View File

@ -8,6 +8,7 @@ const web3 = require('web3');
const constants = require('../constants');
const {canonicalHost, defaultHost} = require('../utils/host');
const cloneDeep = require('lodash.clonedeep');
import { extendZeroAddressShorthand, replaceZeroAddressShorthand } from '../utils/addressUtils';
const DEFAULT_CONFIG_PATH = 'config/';
const unitRegex = /([0-9]+) ([a-zA-Z]+)/;
@ -299,16 +300,47 @@ Config.prototype.loadContractsConfigFile = function() {
}
});
}
Object.keys(newContractsConfig.contracts).forEach(contractName => {
let gas = newContractsConfig.contracts[contractName].gas;
let gasPrice = newContractsConfig.contracts[contractName].gasPrice;
const gas = newContractsConfig.contracts[contractName].gas;
const gasPrice = newContractsConfig.contracts[contractName].gasPrice;
const address = newContractsConfig.contracts[contractName].address;
const args = newContractsConfig.contracts[contractName].args;
const onDeploy = newContractsConfig.contracts[contractName].onDeploy;
if (gas && gas.match(unitRegex)) {
newContractsConfig.contracts[contractName].gas = utils.getWeiBalanceFromString(gas, web3);
}
if (gasPrice && gasPrice.match(unitRegex)) {
newContractsConfig.contracts[contractName].gasPrice = utils.getWeiBalanceFromString(gasPrice, web3);
}
if (address) {
newContractsConfig.contracts[contractName].address = extendZeroAddressShorthand(address);
}
if (args && args.length) {
newContractsConfig.contracts[contractName].args = args.map(val => {
if (typeof val === 'string') {
return extendZeroAddressShorthand(val);
}
return val;
});
}
if (onDeploy && onDeploy.length) {
newContractsConfig.contracts[contractName].onDeploy = onDeploy.map(replaceZeroAddressShorthand);
}
});
const afterDeploy = newContractsConfig.contracts.afterDeploy;
if (afterDeploy && afterDeploy.length) {
newContractsConfig.contracts.afterDeploy = afterDeploy.map(replaceZeroAddressShorthand);
}
if (!deepEqual(newContractsConfig, this.contractsConfig)) {
this.contractsConfig = newContractsConfig;
}

View File

@ -0,0 +1,14 @@
const ZERO_ADDRESS_SHORTHAND_REGEX = /^0x0$/;
const ZERO_ADDRESS_SHORTHAND_SEARCH_REGEX = /'0x0'/g;
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
export function extendZeroAddressShorthand(value: string) {
if (value.match(ZERO_ADDRESS_SHORTHAND_REGEX) !== null) {
return ZERO_ADDRESS;
}
return value;
}
export function replaceZeroAddressShorthand(value: string) {
return value.replace(ZERO_ADDRESS_SHORTHAND_SEARCH_REGEX, `'${ZERO_ADDRESS}'`);
}

View File

@ -130,6 +130,38 @@ describe('embark.Config', function () {
assert.deepEqual(config.contractsConfig, expectedConfig);
});
it('should replace occourences of `0x0` with full zero addresses', () => {
let expectedConfig = {
versions: {'web3': '1.0.0-beta', solc: '0.4.25'},
deployment: {host: 'localhost', port: 8545, type: 'rpc'},
dappConnection: ['$WEB3', 'localhost:8545'],
"gas": "auto",
"strategy": "implicit",
"contracts": {
"SimpleStorage": {
"args": [100, '0x0000000000000000000000000000000000000000'],
"address": '0x0000000000000000000000000000000000000000',
"onDeploy": [
"SimpleStorage.methods.changeAddress('0x0000000000000000000000000000000000000000')"
]
},
"afterDeploy": [
"SimpleStorage.methods.changeAddress('0x0000000000000000000000000000000000000000')",
"SimpleStorage.methods.changeAddress('$SomeToken')"
]
}
};
let zeroAddressconfig = new Config({
env: 'zeroaddress',
configDir: './dist/test/test1/config/',
events: new Events()
});
zeroAddressconfig.plugins = new Plugins({plugins: {}});
zeroAddressconfig.logger = new TestLogger({});
zeroAddressconfig.loadContractsConfigFile();
assert.deepEqual(zeroAddressconfig.contractsConfig, expectedConfig);
});
});
describe('#loadExternalContractsFiles', function () {

View File

@ -9,6 +9,25 @@
}
}
},
"zeroaddress": {
"gas": "auto",
"contracts": {
"SimpleStorage": {
"address": "0x0",
"args": [
100,
"0x0"
],
"onDeploy": [
"SimpleStorage.methods.changeAddress('0x0')"
]
},
"afterDeploy": [
"SimpleStorage.methods.changeAddress('0x0')",
"SimpleStorage.methods.changeAddress('$SomeToken')"
]
}
},
"myenv": {
"gas": "400 Kwei",
"contracts": {