Skip to content

Commit 31b4139

Browse files
committed
CI jobs for testing solc-js with Truffle and Hardhat
1 parent 5e4be61 commit 31b4139

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

.circleci/config.yml

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ workflows:
88
- node-v16:
99
run_coveralls: true
1010
- node-v17
11+
- hardhat-core-default-solc
12+
- hardhat-core-latest-solc
13+
- hardhat-sample-project
14+
- truffle-sample-project
1115

1216
version: 2.1
1317

@@ -44,6 +48,96 @@ commands:
4448
paths:
4549
- "<<parameters.path>>/node_modules/"
4650

51+
install-truffle-dependencies:
52+
steps:
53+
- run:
54+
name: Store current Truffle commit ID in a variable
55+
command: |
56+
cd truffle/
57+
echo "export _TRUFFLE_COMMIT_ID=$(git rev-parse --verify HEAD)" >> $BASH_ENV
58+
- restore_cache:
59+
key: truffle-dependency-cache-{{ checksum "truffle/yarn.lock" }}-{{ .Environment._TRUFFLE_COMMIT_ID }}
60+
- run:
61+
name: yarn install in truffle
62+
command: |
63+
cd truffle/
64+
[[ -e node_modules/ ]] || yarn install
65+
- save_cache:
66+
key: truffle-dependency-cache-{{ checksum "truffle/yarn.lock" }}-{{ .Environment._TRUFFLE_COMMIT_ID }}
67+
paths:
68+
- truffle/
69+
70+
inject-solc-js-tarball:
71+
description: "Recursively finds and replaces all instances of solc-js module installed in node_modules/ with the one from a tarball."
72+
parameters:
73+
path:
74+
type: string
75+
default: .
76+
tarball-path:
77+
type: string
78+
default: solc-js.tgz
79+
install-command:
80+
type: string
81+
default: npm install
82+
steps:
83+
- run:
84+
name: Inject solc-js from the tarball into dependencies at <<parameters.path>>
85+
command: |
86+
[[ -f "<<parameters.tarball-path>>" ]]
87+
absolute_tarball_path=$(realpath "<<parameters.tarball-path>>")
88+
for solc_module in $(find "<<parameters.path>>" -type d -path "*/node_modules/solc"); do
89+
pushd "${solc_module}/../.."
90+
<<parameters.install-command>> "$absolute_tarball_path" --ignore-workspace-root-check
91+
popd
92+
done
93+
94+
provision-and-package-solcjs:
95+
description: "Creates a package out of latest solc-js to test its installation as a dependency."
96+
steps:
97+
- checkout:
98+
path: solc-js/
99+
- install-dependencies:
100+
cache-id: solc-js
101+
path: solc-js
102+
- run:
103+
name: Package solc-js
104+
command: |
105+
cd solc-js/
106+
npm run build:tarball
107+
mv "$(npm run --silent tarballName)" ../solc-js.tgz
108+
109+
provision-hardhat-with-packaged-solcjs:
110+
description: "Clones Hardhat repository and configures it to use a local clone of solc-js."
111+
steps:
112+
- run: git clone --depth 1 "https://github.com/nomiclabs/hardhat" hardhat/
113+
- install-dependencies:
114+
cache-id: hardhat
115+
path: hardhat
116+
package-manager: yarn
117+
dependency-file: yarn.lock
118+
- inject-solc-js-tarball:
119+
path: hardhat/
120+
install-command: yarn add
121+
122+
provision-truffle-with-packaged-solcjs:
123+
description: "Clones Truffle repository and configures it to use a local clone of solc-js."
124+
steps:
125+
- run: git clone --depth 1 "https://github.com/trufflesuite/truffle" truffle/
126+
- install-truffle-dependencies
127+
- inject-solc-js-tarball:
128+
path: truffle/node_modules/
129+
install-command: yarn add
130+
- run:
131+
name: Neutralize any copies of solc-js outside of node_modules/
132+
command: |
133+
# NOTE: Injecting solc-js into node_modules/ dirs located under truffle/packages/ causes
134+
# an error 'Tarball is not in network and can not be located in cache'. These are not
135+
# supposed to be used but let's remove them just in case.
136+
find truffle/ \
137+
-path "*/solc/wrapper.js" \
138+
-not -path "truffle/node_modules/*" \
139+
-printf "%h\n" | xargs --verbose rm -r
140+
47141
jobs:
48142
node-base: &node-base
49143
working_directory: ~/solc-js
@@ -74,6 +168,119 @@ jobs:
74168
name: coveralls
75169
command: npm run coveralls
76170

171+
hardhat-core-default-solc:
172+
docker:
173+
- image: circleci/node:16
174+
steps:
175+
- show-npm-version
176+
- provision-and-package-solcjs
177+
- provision-hardhat-with-packaged-solcjs
178+
- run:
179+
name: Run hardhat-core test suite with its default solc
180+
command: |
181+
cd hardhat/packages/hardhat-core
182+
yarn test
183+
184+
hardhat-core-latest-solc:
185+
docker:
186+
- image: circleci/node:16
187+
steps:
188+
- show-npm-version
189+
- provision-and-package-solcjs
190+
- provision-hardhat-with-packaged-solcjs
191+
- run:
192+
name: Run hardhat-core test suite with latest solc
193+
command: |
194+
HARDHAT_TESTS_SOLC_PATH="${PWD}/solc-js/soljson.js"
195+
HARDHAT_TESTS_SOLC_VERSION=$(jq --raw-output .version solc-js/package.json)
196+
export HARDHAT_TESTS_SOLC_PATH HARDHAT_TESTS_SOLC_VERSION
197+
198+
cd hardhat/packages/hardhat-core
199+
yarn test
200+
201+
hardhat-sample-project:
202+
docker:
203+
- image: circleci/node:16
204+
steps:
205+
- show-npm-version
206+
- provision-and-package-solcjs
207+
- run: git clone --depth 1 "https://github.com/nomiclabs/hardhat-hackathon-boilerplate" boilerplate/
208+
- run:
209+
# Leaving package-lock.json causes a weird error in arborist when npm is used again after
210+
# `npm install`: 'The "from" argument must be of type string. Received undefined'
211+
name: Neutralize package-lock.json
212+
command: rm boilerplate/package-lock.json
213+
- install-dependencies:
214+
cache-id: hardhat-hackathon-boilerplate
215+
path: boilerplate
216+
- run:
217+
name: Update to the latest Hardhat release
218+
command: |
219+
# We can just use a release here because injection does not require rebuilding it.
220+
cd boilerplate/
221+
npm update hardhat
222+
- inject-solc-js-tarball:
223+
path: boilerplate/
224+
- run:
225+
name: Configure the boilerplate project to force Hardhat not to use a native binary
226+
command: |
227+
solc_version=$(jq --raw-output .version solc-js/package.json)
228+
229+
cd boilerplate/
230+
231+
sed -i 's|pragma solidity [^;]\+;|pragma solidity *;|g' contracts/Token.sol
232+
233+
{
234+
echo "const {TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD} = require('hardhat/builtin-tasks/task-names');"
235+
echo "const assert = require('assert');"
236+
echo
237+
echo "subtask(TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD, async (args, hre, runSuper) => {"
238+
echo " assert(args.solcVersion == '${solc_version}', 'Unexpected solc version: ' + args.solcVersion);"
239+
echo " return {"
240+
echo " compilerPath: '$(realpath "../solc-js/soljson.js")',"
241+
echo " isSolcJs: true,"
242+
echo " version: args.solcVersion,"
243+
echo " longVersion: args.solcVersion"
244+
echo " };"
245+
echo "})"
246+
echo "module.exports = {solidity: '${solc_version}'};"
247+
} >> hardhat.config.js
248+
- run:
249+
name: Build and test the boilerplate project with local Hardhat
250+
command: |
251+
cd boilerplate/
252+
npm run test
253+
254+
truffle-sample-project:
255+
docker:
256+
- image: circleci/node:12
257+
steps:
258+
- show-npm-version
259+
- provision-and-package-solcjs
260+
- provision-truffle-with-packaged-solcjs
261+
- run:
262+
name: Unbox MetaCoin
263+
command: |
264+
mkdir metacoin/
265+
cd metacoin/
266+
node ../truffle/node_modules/.bin/truffle unbox metacoin
267+
- run:
268+
name: Strip version pragmas
269+
command: sed -i 's|pragma solidity [^;]\+;|pragma solidity *;|g' $(find metacoin/{contracts,test}/ -name "*.sol")
270+
- run:
271+
name: Build and test the sample project with local Truffle and its default solc
272+
command: |
273+
cd metacoin/
274+
node ../truffle/node_modules/.bin/truffle test
275+
- run:
276+
name: Build and test the sample project with local Truffle and latest solc
277+
command: |
278+
cd metacoin/
279+
# `truffle test` compiles the project but artifacts go into /tmp/
280+
! [[ -e build/ ]] || false
281+
echo "module.exports['compilers'] = {solc: {version: '$(realpath node_modules/solc/)'}}" > truffle-config.js
282+
node ../truffle/node_modules/.bin/truffle test
283+
77284
node-v10:
78285
<<: *node-base
79286
docker:

0 commit comments

Comments
 (0)