Skip to content

Commit

Permalink
feat(core): Detect invalid network names in overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Aug 24, 2023
1 parent 4e50a3c commit 79ecfdf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/fluffy-geckos-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
---

Detect invalid network names for overrides
20 changes: 19 additions & 1 deletion packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import {
} from '../addresses'
import { getTargetAddress, getTargetSalt, toContractKindEnum } from './utils'
import {
SUPPORTED_LOCAL_NETWOKRS,
SUPPORTED_MAINNETS,
SUPPORTED_NETWORKS,
SUPPORTED_TESTNETS,
Expand Down Expand Up @@ -1623,7 +1624,14 @@ export const parseContractConstructorArgs = (
)
}

// Todo - check if any of network names listed in overrides are invalid
const invalidOverrideChains = userContractConfig.overrides?.flatMap((el) =>
el.chains.filter(
(name) =>
!Object.keys(SUPPORTED_MAINNETS).includes(name) &&
!Object.keys(SUPPORTED_TESTNETS).includes(name) &&
!Object.keys(SUPPORTED_LOCAL_NETWOKRS).includes(name)
)
)

// Check if there are any variables which have ambiguous overrides (due to fields being listed multiple times for a given network)
const ambigiousArgOverrides: {
Expand Down Expand Up @@ -1782,6 +1790,16 @@ export const parseContractConstructorArgs = (
})
}

if (invalidOverrideChains && invalidOverrideChains.length > 0) {
logValidationError(
'error',
`Detected invalid override network names for ${referenceName}:`,
invalidOverrideChains,
cre.silent,
cre.stream
)
}

if (ambiguousArgOutput.length > 0) {
logValidationError(
'error',
Expand Down
21 changes: 13 additions & 8 deletions packages/core/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ export const proposeAbstractTask = async (
getProviderForChainId: GetProviderForChainId,
spinner: ora.Ora = ora({ isSilent: true }),
failureAction: FailureAction = FailureAction.EXIT,
getCanonicalConfig: GetCanonicalConfig = fetchCanonicalConfig
): Promise<ProposalRequest | undefined> => {
getCanonicalConfig: GetCanonicalConfig = fetchCanonicalConfig,
signMetaTxn: boolean = true
): Promise<{
proposalRequest: ProposalRequest | undefined
ipfsData: string[] | undefined
}> => {
const apiKey = process.env.SPHINX_API_KEY
if (!apiKey) {
throw new Error(`Must provide a 'SPHINX_API_KEY' environment variable.`)
Expand Down Expand Up @@ -233,7 +237,7 @@ export const proposeAbstractTask = async (
spinner.succeed(
`Skipping proposal because your Sphinx config file has not changed.`
)
return
return { proposalRequest: undefined, ipfsData: undefined }
}

if (!cre.confirm && !dryRun) {
Expand Down Expand Up @@ -263,9 +267,10 @@ export const proposeAbstractTask = async (

// Sign the meta-txn for the auth root, or leave it undefined if we're not relaying the proposal
// to the back-end.
const metaTxnSignature = dryRun
? undefined
: await signAuthRootMetaTxn(wallet, root)
const metaTxnSignature =
!dryRun && !signMetaTxn
? undefined
: await signAuthRootMetaTxn(wallet, root)

const proposalRequestLeafs: Array<ProposalRequestLeaf> = []
for (const bundledLeaf of bundledLeafs) {
Expand Down Expand Up @@ -393,10 +398,10 @@ export const proposeAbstractTask = async (
},
}

const compilerConfigArray = Object.values(compilerConfigs)
if (!dryRun) {
const websiteLink = blue(hyperlink('website', WEBSITE_URL))
await relayProposal(proposalRequest)
const compilerConfigArray = Object.values(compilerConfigs)
await relayIPFSCommit(apiKey, orgId, compilerConfigArray)
spinner.succeed(
`Proposal succeeded! Go to the ${websiteLink} to approve the deployment.`
Expand All @@ -405,7 +410,7 @@ export const proposeAbstractTask = async (
spinner.succeed(`Proposal dry run succeeded!`)
}

return proposalRequest
return { proposalRequest, ipfsData: compilerConfigArray }
}

export const sphinxCommitAbstractSubtask = async (
Expand Down
10 changes: 3 additions & 7 deletions packages/plugins/test/MultiChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('Multi chain projects', () => {
},
}

const proposalRequest = await proposeAbstractTask(
const { proposalRequest } = await proposeAbstractTask(
newProjectTestInfo.userConfig,
true,
cre,
Expand All @@ -145,13 +145,9 @@ describe('Multi chain projects', () => {
getCanonicalConfig
)

if (!proposalRequest) {
throw new Error('The proposal is empty. Should never happen.')
}

await proposeThenApproveDeploymentThenExecute(
newProjectTestInfo,
proposalRequest,
proposalRequest!,
initialTestnets
)
})
Expand Down Expand Up @@ -192,7 +188,7 @@ describe('Multi chain projects', () => {
)

// Deploy the project on the existing chains.
const proposalRequest = await proposeAbstractTask(
const { proposalRequest } = await proposeAbstractTask(
newProjectTestInfo.userConfig,
true,
cre,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const setupThenProposeThenApproveDeploymentThenExecute = async (
const { authAddress, userConfig, ownerPrivateKeys, proposerAddresses } =
projectTestInfo

const proposalRequest = await proposeAbstractTask(
const { proposalRequest } = await proposeAbstractTask(
userConfig,
true, // Is testnet
cre,
Expand Down

0 comments on commit 79ecfdf

Please sign in to comment.