Skip to content

Commit

Permalink
refactor(pg): add tests for CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Jan 5, 2024
1 parent b7614c6 commit bb0b9af
Show file tree
Hide file tree
Showing 14 changed files with 1,012 additions and 497 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-brooms-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sphinx-labs/plugins': patch
---

Add tests for CLI args
2 changes: 2 additions & 0 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"node-fetch": "^2.6.7",
"ora": "^5.4.1",
"semver": "^7.3.7",
"sinon": "^17.0.1",
"solidity-ast": "^0.4.52",
"sphinx-forge-std": "https://github.com/foundry-rs/forge-std.git#v1.7.1",
"sphinx-solmate": "npm:solmate@^6.7.0",
Expand All @@ -76,6 +77,7 @@
"@openzeppelin/contracts-upgradeable": "^4.8.3",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@types/chai-as-promised": "^7.1.5",
"@types/sinon": "^17.0.2",
"@types/stream-chain": "^2.0.2",
"@types/stream-json": "^1.7.4",
"@types/yargs": "^17.0.24",
Expand Down
25 changes: 25 additions & 0 deletions packages/plugins/src/cli/context.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import {
CompilerConfig,
ConfigArtifacts,
GetConfigArtifacts,
ParsedConfig,
ProposalRequest,
SphinxJsonRpcProvider,
SphinxTransactionReceipt,
getPreview,
isLiveNetwork,
userConfirmation,
} from '@sphinx-labs/core'
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
import { SphinxMerkleTree } from '@sphinx-labs/contracts'

import { makeGetConfigArtifacts } from '../foundry/utils'
import { ProposeArgs, propose } from './propose'
import { DeployArgs, deploy } from './deploy'

export type SphinxContext = {
makeGetConfigArtifacts: (
Expand All @@ -19,12 +28,28 @@ export type SphinxContext = {
isLiveNetwork: (
provider: SphinxJsonRpcProvider | HardhatEthersProvider
) => Promise<boolean>
propose: (args: ProposeArgs) => Promise<{
proposalRequest?: ProposalRequest
canonicalConfigData?: string
configArtifacts?: ConfigArtifacts
parsedConfigArray?: Array<ParsedConfig>
merkleTree?: SphinxMerkleTree
}>
deploy: (args: DeployArgs) => Promise<{
compilerConfig?: CompilerConfig
merkleTree?: SphinxMerkleTree
preview?: ReturnType<typeof getPreview>
receipts?: Array<SphinxTransactionReceipt>
configArtifacts?: ConfigArtifacts
}>
}

export const makeSphinxContext = (): SphinxContext => {
return {
makeGetConfigArtifacts,
prompt: userConfirmation,
isLiveNetwork,
propose,
deploy,
}
}
33 changes: 24 additions & 9 deletions packages/plugins/src/cli/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,37 @@ import {
import { simulate } from '../hardhat/simulate'
import { SphinxContext } from './context'

export interface DeployArgs {
scriptPath: string
network: string
skipPreview: boolean
silent: boolean
sphinxContext: SphinxContext
verify: boolean
forceRecompile: boolean
targetContract?: string
}

export const deploy = async (
scriptPath: string,
network: string,
skipPreview: boolean,
silent: boolean,
sphinxContext: SphinxContext,
targetContract?: string,
verify?: boolean,
skipForceRecompile: boolean = false
args: DeployArgs
): Promise<{
compilerConfig?: CompilerConfig
merkleTree?: SphinxMerkleTree
preview?: ReturnType<typeof getPreview>
receipts?: Array<SphinxTransactionReceipt>
configArtifacts?: ConfigArtifacts
}> => {
const {
scriptPath,
network,
skipPreview,
silent,
sphinxContext,
verify,
forceRecompile,
targetContract,
} = args

const projectRoot = process.cwd()
const foundryToml = await getFoundryToml()
const {
Expand Down Expand Up @@ -122,7 +137,7 @@ export const deploy = async (
// disabled. This ensures that we're using the correct artifacts for live network deployments.
// This is mostly out of an abundance of caution, since using an incorrect contract artifact will
// prevent us from writing the deployment artifact for that contract.
if (isLiveNetwork && !skipForceRecompile) {
if (isLiveNetwork && forceRecompile) {
forgeBuildArgs.push('--force')
}

Expand Down
Loading

0 comments on commit bb0b9af

Please sign in to comment.