Skip to content

Commit 115edb6

Browse files
satyamakgecmaxsam4
authored andcommitted
[3.38]: Add ST storage layout check script in CI pipeline (#704)
* add st storage layout check script in CI pipeline * add info comment
1 parent b22c7bc commit 115edb6

File tree

5 files changed

+53
-27
lines changed

5 files changed

+53
-27
lines changed

.circleci/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ jobs:
6969
key: dependency-cache-{{ checksum "package.json" }}
7070
paths:
7171
- node_modules
72+
st-storage-layout-check:
73+
docker:
74+
- image: maxsam4/solidity-kit
75+
steps:
76+
- checkout
77+
- restore_cache:
78+
key: dependency-cache-{{ checksum "package.json" }}
79+
- run: yarn install
80+
- run: node --version
81+
- run: truffle version
82+
- run: npm run st-storage-layout-check
83+
- save_cache:
84+
key: dependency-cache-{{ checksum "package.json" }}
85+
paths:
86+
- node_modules
7287
docs:
7388
docker:
7489
- image: maxsam4/solidity-kit
@@ -90,6 +105,7 @@ workflows:
90105
jobs:
91106
- coverage
92107
- clash-check
108+
- st-storage-layout-check
93109
daily-builds:
94110
triggers:
95111
- schedule:

contracts/tokens/OZStorage.sol

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
pragma solidity ^0.5.0;
22

3+
/*
4+
* @dev It is the contract that contains the storage items related to the ERC20 contract implementaiton
5+
* of the openzeppelin-solidity. Used to allow the storage declaration of ERC20 to the STGetter contract
6+
*/
7+
38
contract OZStorage {
49

5-
mapping (address => uint256) public _balances;
10+
mapping (address => uint256) private _balances;
611

7-
mapping (address => mapping (address => uint256)) public _allowed;
12+
mapping (address => mapping (address => uint256)) private _allowed;
813

9-
uint256 public _totalSupply;
14+
uint256 private _totalSupply;
1015

1116
/// @dev counter to allow mutex lock with only one SSTORE operation
1217
uint256 private _guardCounter;
@@ -19,4 +24,8 @@ contract OZStorage {
1924
return _balances[_investor];
2025
}
2126

27+
function _allowance(address owner, address spender) internal view returns(uint256) {
28+
return _allowed[owner][spender];
29+
}
30+
2231
}

contracts/tokens/STGetter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ contract STGetter is OZStorage, SecurityTokenStorage {
212212
* @return Whether the `_operator` is an operator for all partitions of `_tokenHolder`
213213
*/
214214
function isOperator(address _operator, address _tokenHolder) external view returns (bool) {
215-
return (_allowed[_tokenHolder][_operator] == uint(-1));
215+
return (_allowance(_tokenHolder, _operator) == uint(-1));
216216
}
217217

218218
/**

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"flatten-all": "npm run flatten-modules && npm run flatten-token && npm run flatten-mocks && npm run flatten-oracles && npm run flatten-proxies && npm run flatten && npm run flatten-proxyFactories",
3737
"ethereum-bridge": "node_modules/.bin/ethereum-bridge -H localhost:8545 -a 9 --dev",
3838
"st20generator": "node demo/ST20Generator",
39-
"pretty": "prettier --write --print-width 140 --tab-width 4 \"**/*.js\""
39+
"pretty": "prettier --write --print-width 140 --tab-width 4 \"**/*.js\"",
40+
"st-storage-layout-check": "node scripts/compareStorageLayout.js SecurityToken STGetter"
4041
},
4142
"repository": {
4243
"type": "git",
@@ -84,7 +85,6 @@
8485
"mocha-junit-reporter": "^1.18.0",
8586
"openzeppelin-solidity": "2.2.0",
8687
"prettier": "^1.15.3",
87-
"prompt": "^1.0.0",
8888
"request": "^2.88.0",
8989
"request-promise": "^4.2.2",
9090
"sol-merger": "^0.1.2",

scripts/compareStorageLayout.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
11
const fs = require("fs");
22
const _ = require("underscore");
33
const solc = require("solc");
4-
const prompt = require("prompt");
54
const path = require("path");
65
const util = require("util");
76
const exec = util.promisify(require("child_process").exec);
87

9-
console.log(`Mandatory: Solc cli tool should be installed globally. Please put the contract name only`);
10-
prompt.start();
8+
console.log(`Mandatory: Solc cli tool should be installed globally. Please put the contract name only in any order`);
119

12-
prompt.get(["LogicContract", "ProxyContract"], async (err, result) => {
13-
let temp;
14-
let logicFilePath;
15-
let proxyFilePath;
10+
let contractA = process.argv.slice(2)[0];
11+
let contractB = process.argv.slice(2)[1];
1612

17-
const fileList = walkSync("./contracts", []);
13+
compareStorage(contractA, contractB);
14+
15+
async function compareStorage() {
1816

19-
let paths = findPath(result.LogicContract, result.ProxyContract, fileList);
17+
const fileList = walkSync("./contracts", []);
18+
let paths = findPath(contractA, contractB, fileList);
2019

2120
if (paths.length == 2) {
2221
console.log("Contracts exists \n");
2322

2423
await flatContracts(paths);
2524
let temp;
26-
let logicFilePath = `./flat/${path.basename(paths[0])}`;
27-
let proxyFilePath = `./flat/${path.basename(paths[1])}`;
25+
let contractAPath = `./flat/${path.basename(paths[0])}`;
26+
let contractBPath = `./flat/${path.basename(paths[1])}`;
2827

29-
if (path.basename(paths[0]) === result.LogicContract) {
30-
temp = logicFilePath;
31-
logicFilePath = proxyFilePath;
32-
proxyFilePath = temp;
28+
if (path.basename(paths[0]) === contractA) {
29+
temp = contractAPath;
30+
contractAPath = contractBPath;
31+
contractBPath = temp;
3332
}
3433

35-
let logicAST = await getAST(logicFilePath);
36-
let proxyAST = await getAST(proxyFilePath);
34+
let contractAAST = await getAST(contractAPath);
35+
let contractBAST = await getAST(contractBPath);
3736
// Deleting the temp folder (no longer required)
3837
await flushTemp();
3938

40-
console.log(compareStorageLayouts(parseContract(logicAST), parseContract(proxyAST)));
39+
var result = compareStorageLayouts(parseContract(contractAAST), parseContract(contractBAST));
40+
if (!result)
41+
process.exit(1);
4142
} else {
4243
console.log("Contracts doesn't exists");
4344
}
44-
});
45+
}
4546

4647
function traverseAST(_input, _elements) {
4748
if (_input.children) {
@@ -101,7 +102,7 @@ function parseContract(input) {
101102
return orderedStateVariables;
102103
}
103104

104-
var walkSync = function(dir, filelist) {
105+
function walkSync(dir, filelist) {
105106
files = fs.readdirSync(dir);
106107
filelist = filelist || [];
107108
files.forEach(function(file) {
@@ -114,7 +115,7 @@ var walkSync = function(dir, filelist) {
114115
return filelist;
115116
};
116117

117-
var findPath = function(logicContractName, proxyContractName, fileList) {
118+
function findPath(logicContractName, proxyContractName, fileList) {
118119
let paths = new Array();
119120
for (let i = 0; i < fileList.length; i++) {
120121
if (

0 commit comments

Comments
 (0)