Skip to content

Commit

Permalink
Upgrade solidity and tests infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-CZ committed Oct 4, 2024
1 parent c950937 commit c4b7d33
Show file tree
Hide file tree
Showing 49 changed files with 8,724 additions and 23,802 deletions.
5 changes: 0 additions & 5 deletions .babelrc

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc

This file was deleted.

15 changes: 6 additions & 9 deletions .github/workflows/push_checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
node-version: [20.x]

steps:
- name: Checkout
uses: 'actions/checkout@master'
uses: actions/checkout@v4

- name: Set Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -28,22 +28,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
node-version: [20.x]

steps:
- name: Checkout
uses: 'actions/checkout@master'
uses: actions/checkout@v4

- name: Set Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Install Truffle
run: npm install -g truffle

- name: Run tests
run: npm run test
32 changes: 21 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
.idea/
node_modules
.idea
.deps
build
coverage
coverage.json
/.coverage_artifacts/
/.coverage_contracts/
/coverageEnv/
/coverageEnv/
artifacts/
cache/
.env
contracts/artifacts
internal/rpc/contracts
.deploys
.states

node_modules
.env

# solidity-coverage files
/coverage
/coverage.json

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid",
"overrides": [
{
"files": "*.sol",
"options": {
"singleQuote": false,
"quoteProps": "consistent"
}
}
],
"plugins": ["prettier-plugin-solidity"]
}
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
skipFiles: ['common/ReentrancyGuard.sol', 'sfc/Migrations.sol']
skipFiles: ['common/ReentrancyGuard.sol', 'sfc/Migrations.sol'],
};
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ all: build

.PHONY: build
build:
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/src -w /src node:16.19.1 bash -c \
'export NPM_CONFIG_PREFIX=~; npm install --no-save; npm install --no-save [email protected]; npm run build'
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/src -w /src node:20.17.0 bash -c \
'export NPM_CONFIG_PREFIX=~; npm install --no-save; npx hardhat compile'

.PHONY: checksum
checksum:
for f in ./build/contracts/*.json; do echo -n "$$f "; jq -j .deployedBytecode $$f | shasum; done

.PHONY: test
test:
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/src -w /src node:16.19.1 bash -c \
'export NPM_CONFIG_PREFIX=~; npm install --no-save; npm install --no-save [email protected]; npm run test'
docker run --rm --user $$(id -u):$$(id -g) -v $(PWD):/src -w /src node:20.17.0 bash -c \
'export NPM_CONFIG_PREFIX=~; npm install --no-save; npx hardhat test'

.PHONY: workspace
workspace:
docker run -t -i --rm --user $$(id -u):$$(id -g) -v $(PWD):/src -w /src node:20.17.0 bash -c \
'export NPM_CONFIG_PREFIX=~; npm install --no-save; bash'
3 changes: 2 additions & 1 deletion contracts/common/Decimal.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

library Decimal {
// unit is used for decimals, e.g. 0.123456
Expand Down
76 changes: 31 additions & 45 deletions contracts/common/Initializable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pragma solidity >=0.4.24 <0.7.0;

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

/**
* @title Initializable
Expand All @@ -14,49 +14,35 @@ pragma solidity >=0.4.24 <0.7.0;
* because this is not dealt with automatically as with constructors.
*/
contract Initializable {

/**
* @dev Indicates that the contract has been initialized.
*/
bool private initialized;

/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private initializing;

/**
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");

bool isTopLevelCall = !initializing;
if (isTopLevelCall) {
initializing = true;
initialized = true;
/**
* @dev Indicates that the contract has been initialized.
*/
bool private initialized;

/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private initializing;

/**
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(initializing || !initialized, "Contract instance has already been initialized");

Check warning on line 31 in contracts/common/Initializable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (20.x)

Error message for require is too long: 46 counted / 32 allowed

Check warning on line 31 in contracts/common/Initializable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (20.x)

GC: Use Custom Errors instead of require statements

Check warning on line 31 in contracts/common/Initializable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (20.x)

Error message for require is too long: 46 counted / 32 allowed

Check warning on line 31 in contracts/common/Initializable.sol

View workflow job for this annotation

GitHub Actions / Lint sources (20.x)

GC: Use Custom Errors instead of require statements

bool isTopLevelCall = !initializing;
if (isTopLevelCall) {
initializing = true;
initialized = true;
}

_;

if (isTopLevelCall) {
initializing = false;
}
}

_;

if (isTopLevelCall) {
initializing = false;
}
}

/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
assembly { cs := extcodesize(self) }
return cs == 0;
}

// Reserved storage space to allow for layout changes in the future.
uint256[50] private ______gap;
// Reserved storage space to allow for layout changes in the future.
uint256[50] private ______gap;
}
4 changes: 3 additions & 1 deletion contracts/common/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma solidity ^0.5.0;
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import "./Initializable.sol";

Check warning on line 4 in contracts/common/ReentrancyGuard.sol

View workflow job for this annotation

GitHub Actions / Lint sources (20.x)

global import of path ./Initializable.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 4 in contracts/common/ReentrancyGuard.sol

View workflow job for this annotation

GitHub Actions / Lint sources (20.x)

global import of path ./Initializable.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

/**
Expand Down
Loading

0 comments on commit c4b7d33

Please sign in to comment.