Skip to content

Commit

Permalink
fix(pg): update init tasks and add tests for TypeScript init tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman authored and RPate97 committed Jul 13, 2023
1 parent d6bb68c commit f0bb035
Show file tree
Hide file tree
Showing 18 changed files with 334 additions and 272 deletions.
6 changes: 6 additions & 0 deletions .changeset/kind-suns-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chugsplash/plugins': patch
'@chugsplash/demo': patch
---

Update init tasks and add tests for TypeScript init tasks
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- v2-cache-yarn-install
- run:
name: Install dependencies
command: yarn --frozen-lockfile
command: yarn --frozen-lockfile --link-duplicates
- save_cache:
key: v2-cache-yarn-install-{{ checksum "yarn.lock" }}
paths:
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"@chugsplash/{contracts,plugins}/@eth-optimism/contracts-bedrock",
"@chugsplash/{contracts,plugins}/@eth-optimism/contracts",
"@chugsplash/contracts/@layerzerolabs/solidity-examples",
"@chugsplash/plugins/@chugsplash/contracts",
"@chugsplash/plugins/forge-std",
"@chugsplash/plugins/ds-test",
"@chugsplash/{plugins,demo}/@chugsplash/contracts",
"@chugsplash/{plugins,demo}/forge-std",
"@chugsplash/{plugins,demo}/ds-test",
"@chugsplash/plugins/solidity-stringutils",
"@chugsplash/plugins/@prb/math"
]
Expand Down
22 changes: 0 additions & 22 deletions packages/demo/chugsplash/hello-chugsplash.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/demo/contracts/HelloChugSplash.sol

This file was deleted.

17 changes: 17 additions & 0 deletions packages/demo/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[profile.default]
src = 'contracts'
ffi = true
build_info = true
extra_output = ['storageLayout', 'evm.gasEstimates']
fs_permissions = [{ access = "read", path = "/"}]
allow_paths = ["../.."]

remappings=[
'@chugsplash/plugins=../../node_modules/@chugsplash/plugins/contracts/foundry',
'@chugsplash/contracts=node_modules/@chugsplash/contracts/',
'forge-std/=node_modules/forge-std/src/',
'ds-test/=node_modules/ds-test/src/'
]

[rpc_endpoints]
anvil = "http://127.0.0.1:8545"
3 changes: 3 additions & 0 deletions packages/demo/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const config: HardhatUserConfig = {
accounts,
},
},
mocha: {
timeout: 100_000,
},
}

export default config
8 changes: 4 additions & 4 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
"clean": "rimraf dist/ ./tsconfig.tsbuildinfo",
"test:coverage": "echo 'no tests'",
"lint": "yarn lint:fix && yarn lint:check",
"lint:check": "yarn lint:contracts:check && yarn lint:ts:check",
"lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix",
"lint:check": "yarn lint:ts:check",
"lint:fix": "yarn lint:ts:fix",
"lint:ts:check": "eslint .",
"lint:ts:fix": "yarn lint:ts:check --fix",
"lint:contracts:check": "yarn solhint -f table 'contracts/**/*.sol'",
"lint:contracts:fix": "prettier --write 'contracts/**/*.sol'",
"pre-commit": "lint-staged"
},
"homepage": "https://github.com/smartcontracts/chugsplash/tree/develop/packages/demo#readme",
Expand Down Expand Up @@ -48,6 +46,8 @@
"@chugsplash/core": "^0.11.0",
"@chugsplash/plugins": "^0.16.0",
"@types/node": "^18.0.0",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
"forge-std": "https://github.com/foundry-rs/forge-std.git#66bf4e2c92cf507531599845e8d5a08cc2e3b5bb",
"solidity-ast": "^0.4.46"
}
}
28 changes: 0 additions & 28 deletions packages/demo/test/HelloChugSplash.spec.ts

This file was deleted.

99 changes: 99 additions & 0 deletions packages/demo/test/InitTask.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as fs from 'fs'
import path from 'path'

import { execAsync } from '@chugsplash/core'
import {
foundryTestFileName,
foundryScriptFileName,
sampleContractFileName,
sampleConfigFileNameTypeScript,
hhTestFileNameTypeScript,
} from '@chugsplash/plugins'
import { expect } from 'chai'

const configDirPath = 'chugsplash'

describe('Init Task', () => {
let configPath: string
let contractPath: string
let foundryTestPath: string
let foundryScriptPath: string
let hardhatTestPath: string
before(async () => {
const forgeConfigOutput = await execAsync('forge config --json')
const forgeConfig = JSON.parse(forgeConfigOutput.stdout)
const { src, test, script } = forgeConfig

configPath = path.join(configDirPath, sampleConfigFileNameTypeScript)
contractPath = path.join(src, sampleContractFileName)
foundryTestPath = path.join(test, foundryTestFileName)
foundryScriptPath = path.join(script, foundryScriptFileName)

hardhatTestPath = path.join(test, hhTestFileNameTypeScript)
})

afterEach(async () => {
// Delete all of the generated files

fs.rmSync(configPath)
fs.rmSync(contractPath)

if (fs.existsSync(foundryTestPath)) {
fs.rmSync(foundryTestPath)
}

if (fs.existsSync(foundryScriptPath)) {
fs.rmSync(foundryScriptPath)
}

if (fs.existsSync(hardhatTestPath)) {
fs.rmSync(hardhatTestPath)
}
})

it('Succeeds for a sample Foundry project with a TypeScript config', async () => {
// Check that the sample files haven't been created yet
expect(fs.existsSync(configPath)).to.be.false
expect(fs.existsSync(contractPath)).to.be.false
expect(fs.existsSync(foundryTestPath)).to.be.false
expect(fs.existsSync(foundryScriptPath)).to.be.false

await execAsync('npx chugsplash init --ts')

// Check that the files have been created
expect(fs.existsSync(configPath)).to.be.true
expect(fs.existsSync(contractPath)).to.be.true
expect(fs.existsSync(foundryTestPath)).to.be.true
expect(fs.existsSync(foundryScriptPath)).to.be.true

// Next, we'll run the test and script files. If a Foundry test case fails, or if there's some
// other error that occurs when running either command, this test case will also fail.
await execAsync(`forge test --match-path ${foundryTestPath}`)
await execAsync(`forge script ${foundryScriptPath}`)
})

it('Succeeds for a sample Hardhat project with a TypeScript config', async () => {
// Check that the sample files haven't been created yet
expect(fs.existsSync(configPath)).to.be.false
expect(fs.existsSync(contractPath)).to.be.false
expect(fs.existsSync(hardhatTestPath)).to.be.false

// This command infers that we're using a TypeScript project based on the fact that we have a
// hardhat.config.ts (instead of .js).
await execAsync('npx hardhat chugsplash-init')

// Check that the files have been created
expect(fs.existsSync(configPath)).to.be.true
expect(fs.existsSync(contractPath)).to.be.true
expect(fs.existsSync(hardhatTestPath)).to.be.true

// Next, we'll run the test and script files. If a Hardhat test case fails, or if there's some
// other error that occurs when running either command, this test case will also fail.
await execAsync(
`npx hardhat test ${hardhatTestPath} --config-path ${configPath} --project MyFirstProject --use-default-signer`
)
await execAsync(
`npx hardhat chugsplash-deploy --config-path ${configPath} --project MyFirstProject --use-default-signer`
)
})
})
6 changes: 4 additions & 2 deletions packages/plugins/src/foundry/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export const getEncodedFailure = (err: Error): string => {
const prettyWarnings = getPrettyWarnings()

let prettyError: string
if (err.name === 'ValidationError') {
// We return the error messages and warnings.
if (err.name === 'ValidationError' && err.message === '') {
// We throw a ValidationError with an empty message inside `logValidationError` if there's one or
// more parsing errors. In this situation, we return the parsing error messages that have been
// collected in the `validationErrors` variable.

// Removes unnecessary '\n' characters from the end of 'errors'
prettyError = validationErrors.endsWith('\n\n')
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/src/hardhat/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export const chugsplashInitTask = async (
}

task(TASK_CHUGSPLASH_INIT)
.setDescription('Sets up a ChugSplash project.')
.setDescription('Sets up a sample ChugSplash project.')
.addFlag('silent', "Hide ChugSplash's logs")
.setAction(chugsplashInitTask)

Expand Down
Loading

0 comments on commit f0bb035

Please sign in to comment.