Skip to content

Commit

Permalink
fix(core): fix bug parsing proxied config variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Apr 10, 2023
1 parent acdb0e4 commit f1cf9ac
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-houses-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/core': patch
---

Fix bug parsing proxied config variables
77 changes: 37 additions & 40 deletions packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,9 @@ const parseContractVariables = (
cre: ChugSplashRuntimeEnvironment
): ParsedConfigVariables => {
const parsedConfigVariables: ParsedConfigVariables = {}
if (
!contractConfig.variables ||
Object.keys(contractConfig.variables).length === 0
) {
return {}
}

const userConfigVariables: UserConfigVariables =
contractConfig.variables ?? {}

const dereferencer = astDereferencer(compilerOutput)
const extendedLayout = extendStorageLayout(storageLayout, dereferencer)
Expand All @@ -947,7 +944,7 @@ const parseContractVariables = (
const unnecessarilyDefinedVariables: string[] = []
const missingVariables: string[] = []

for (const variableName of Object.keys(contractConfig.variables)) {
for (const variableName of Object.keys(userConfigVariables)) {
const existsInLayout = extendedLayout.storage.some(
(storageObj) => storageObj.configVarName === variableName
)
Expand All @@ -958,7 +955,7 @@ const parseContractVariables = (
}

for (const storageObj of Object.values(extendedLayout.storage)) {
const configVarValue = contractConfig.variables[storageObj.configVarName]
const configVarValue = userConfigVariables[storageObj.configVarName]
if (configVarValue === undefined) {
missingVariables.push(storageObj.configVarName)
}
Expand Down Expand Up @@ -1777,41 +1774,41 @@ const assertValidContractVariables = (
for (const [referenceName, userContractConfig] of Object.entries(
userConfig.contracts
)) {
if (
userContractConfig.kind === 'no-proxy' &&
userContractConfig.variables &&
Object.entries(userContractConfig.variables).length > 0
) {
logValidationError(
'error',
`Detected variables for contract '${referenceName}', but variables are not supported for non-proxied contracts.`,
[],
cre.silent,
cre.stream
)
continue
}
if (userContractConfig.kind === 'no-proxy') {
if (
userContractConfig.variables &&
Object.entries(userContractConfig.variables).length > 0
) {
logValidationError(
'error',
`Detected variables for contract '${referenceName}', but variables are not supported for non-proxied contracts.`,
[],
cre.silent,
cre.stream
)
}
parsedVariables[referenceName] = {}
} else {
const artifact = cachedArtifacts[referenceName]
const { sourceName, contractName } = artifact

const artifact = cachedArtifacts[referenceName]
const { sourceName, contractName } = artifact
const compilerOutput = cachedCompilerOutput[referenceName]
const storageLayout =
compilerOutput.contracts[sourceName][contractName].storageLayout

const compilerOutput = cachedCompilerOutput[referenceName]
const storageLayout =
compilerOutput.contracts[sourceName][contractName].storageLayout

// Only run the parsing logic if the contract is proxied
const parsedContractVariables = parseContractVariables(
JSON.parse(
Handlebars.compile(JSON.stringify(userContractConfig))({
...contracts,
})
),
storageLayout,
compilerOutput,
cre
)
const parsedContractVariables = parseContractVariables(
JSON.parse(
Handlebars.compile(JSON.stringify(userContractConfig))({
...contracts,
})
),
storageLayout,
compilerOutput,
cre
)

parsedVariables[referenceName] = parsedContractVariables
parsedVariables[referenceName] = parsedContractVariables
}
}

return parsedVariables
Expand Down
1 change: 0 additions & 1 deletion packages/demo/chugsplash/hello-chugsplash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const config: UserChugSplashConfig = {
contracts: {
MyFirstContract: {
contract: 'HelloChugSplash',
unsafeAllowEmptyPush: true,
variables: {
number: 1,
stored: true,
Expand Down

0 comments on commit f1cf9ac

Please sign in to comment.