Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

fix: fix bug about #110 #111

Merged
merged 1 commit into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/vvisp/contracts/test/DependencyA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ contract DependencyA {
address addressB;
address addressC;
address owner;
bool initialized;

constructor(address _addressB, address _addressC, address _owner) public {
addressB = _addressB;
addressC = _addressC;
owner = _owner;
}

function initialize() public {
require(!initialized);
// something
initialized = true;
}
}
7 changes: 7 additions & 0 deletions packages/vvisp/contracts/test/DependencyB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ contract DependencyB {
uint tmp;
address addressD;
address owner;
bool initialized;

constructor(uint _tmp, address _addressD, address _owner) public {
tmp = _tmp;
addressD = _addressD;
owner = _owner;
}

function initialize() public {
require(!initialized);
// something
initialized = true;
}
}
3 changes: 3 additions & 0 deletions packages/vvisp/contracts/test/SecondA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ pragma solidity >=0.5.0 <0.6.0;
contract SecondA {
address addressB;
address addressC;
bool initialized = false;

constructor(address _addressB, address _addressC, address[] memory _owners) public {
addressB = _addressB;
addressC = _addressC;
}

function initialize(address _token, address _owner, address[] memory _addressA) public {
require(!initialized);
// something
initialized = true;
}
}
7 changes: 7 additions & 0 deletions packages/vvisp/contracts/test/SecondD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ pragma solidity >=0.5.0 <0.6.0;
contract SecondD {
address addressB;
address owner;
bool initialized = false;

constructor(address _addressB, address _owner) public {
addressB = _addressB;
owner = _owner;
}

function initialize() public {
require(!initialized);
// something
initialized = true;
}
}
22 changes: 14 additions & 8 deletions packages/vvisp/scripts/deploy-service/preProcess/checkError.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function(targets, compileOutput, options) {
getCycle,
printOrSilent
} = require('@haechi-labs/vvisp-utils');
const { hasConstructArgs, hasInitArgs, getVar } = require('../utils/index');
const { hasConstructArgs, hasInit, getVar } = require('../utils/index');
const { INITIALIZE, CONSTRUCTOR, UPGRADEABLE } = require('../constants');

printOrSilent(chalk.head('Check Arguments...'), options);
Expand All @@ -16,21 +16,24 @@ module.exports = function(targets, compileOutput, options) {
const abi = JSON.parse(
getCompiledContracts(compileOutput, filePath).interface
);
const hasInit = hasInitArgs(contract);
const hasInitialize = hasInit(contract);
const hasConstruct = hasConstructArgs(contract);
if (hasInit && hasConstruct) {
if (hasInitialize && hasConstruct) {
let initialize = false;
let constructorArguments = false;
for (let i = 0; i < abi.length; i++) {
if (
abi[i].name === contract[INITIALIZE].functionName &&
abi[i].type === 'function'
) {
if (contract[INITIALIZE].arguments.length !== abi[i].inputs.length) {
const length = contract[INITIALIZE].arguments
? contract[INITIALIZE].arguments.length
: 0;
if (length !== abi[i].inputs.length) {
throw new Error(
`Arguments Number Error at ${name}: Expected ${
abi[i].inputs.length
}, but ${contract[INITIALIZE].arguments.length}`
}, but ${length}`
);
}
initialize = true;
Expand All @@ -49,17 +52,20 @@ module.exports = function(targets, compileOutput, options) {
break;
}
}
} else if (hasInit) {
} else if (hasInitialize) {
for (let i = 0; i < abi.length; i++) {
if (
abi[i].name === contract[INITIALIZE].functionName &&
abi[i].type === 'function'
) {
if (contract[INITIALIZE].arguments.length !== abi[i].inputs.length) {
const length = contract[INITIALIZE].arguments
? contract[INITIALIZE].arguments.length
: 0;
if (length !== abi[i].inputs.length) {
throw new Error(
`Arguments Number Error at ${name}: Expected ${
abi[i].inputs.length
}, but ${contract[INITIALIZE].arguments.length}`
}, but ${length}`
);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ module.exports = async function(deployState, options) {
const { contract, name } = nonUpgradeables[i];
const stateContract = stateClone.contracts[name];

if (!stateContract.pending) {
continue;
}
const initialize = stateContract[INITIALIZE];
if (initialize && initialize.functionName) {
const instancePath = path.join('./', contract.path);
Expand Down
6 changes: 3 additions & 3 deletions packages/vvisp/scripts/deploy-service/processes/injectVar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = function(deployState) {
const { CONSTRUCTOR, INITIALIZE, VARIABLES } = require('../constants');
const { forIn } = require('@haechi-labs/vvisp-utils');
const { getVar, hasConstructArgs, hasInitArgs } = require('../utils/index');
const { getVar, hasConstructArgs, hasInit } = require('../utils/index');

const stateClone = deployState.getState();
const variables = deployState[VARIABLES];

forIn(stateClone.contracts, (contract, name) => {
if (hasInitArgs(contract)) {
if (hasInit(contract)) {
_injectVar(variables, stateClone, name, INITIALIZE);
}
if (hasConstructArgs(contract)) {
Expand All @@ -22,7 +22,7 @@ module.exports = function(deployState) {
const _arguments =
_type === CONSTRUCTOR
? _contract[CONSTRUCTOR]
: _contract[INITIALIZE].arguments;
: _contract[INITIALIZE].arguments || [];
const _path = `${_name}/${_type}`;

_injecting(_variables, _stateClone, _path, _arguments, _contract);
Expand Down
4 changes: 4 additions & 0 deletions packages/vvisp/scripts/deploy-service/utils/hasInit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(contract) {
const { INITIALIZE } = require('../constants');
return contract[INITIALIZE] && contract[INITIALIZE].functionName;
};
8 changes: 0 additions & 8 deletions packages/vvisp/scripts/deploy-service/utils/hasInitArgs.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/vvisp/scripts/deploy-service/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const getVar = require('./getVar');
const hasConstructArgs = require('./hasConstructArgs');
const hasInitArgs = require('./hasInitArgs');
const hasInit = require('./hasInit');
const pathToInstance = require('./pathToInstance');
const writeState = require('./writeState.js');

module.exports = {
getVar,
hasConstructArgs,
hasInitArgs,
hasInit,
pathToInstance,
writeState
};
14 changes: 12 additions & 2 deletions packages/vvisp/test/dummy/justNonUpgradeables.service1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@
"${contracts.DependencyB.address}",
"${contracts.DependencyC.address}",
"${variables.owner}"
]
],
"initialize": {
"functionName": "initialize",
"arguments": [
]
}
},
"DependencyB": {
"path": "contracts/test/DependencyB.sol",
"constructorArguments": [
3,
"${contracts.DependencyD.address}",
"${variables.owner}"
]
],
"initialize": {
"functionName": "initialize",
"arguments": [
]
}
},
"DependencyC": {
"path": "contracts/test/DependencyC.sol",
Expand Down
7 changes: 6 additions & 1 deletion packages/vvisp/test/dummy/justNonUpgradeables.service2.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@
"constructorArguments": [
"${variables.owner}",
"${variables.owner}"
]
],
"initialize": {
"functionName": "initialize",
"arguments": [
]
}
}
}
}
4 changes: 2 additions & 2 deletions packages/vvisp/test/scripts/deploy-service/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const deployService = require('../../../scripts/deploy-service/');
const compareConfigAndState = require('../../../scripts/deploy-service/preProcess/compareConfigAndState');
const { PENDING_STATE } = require('../../../scripts/deploy-service/constants');
const { SERVICE_PATH, STATE_PATH, TEST } = require('../../../config/Constant');
const { hasInitArgs } = require('../../../scripts/deploy-service/utils');
const { hasInit } = require('../../../scripts/deploy-service/utils');
const {
Config,
forIn,
Expand Down Expand Up @@ -192,7 +192,7 @@ function getWaitingTxNum() {
nonUpgradeableExists = true;
}
resultNumber++; // nonUpgradeables
if (hasInitArgs(contract)) {
if (hasInit(contract)) {
resultNumber++; // init Tx
}
}
Expand Down