Skip to content

Commit b4f2c63

Browse files
committed
Improve constructor argument handling in interaction_existing_contract.ts by adding error handling and trimming quotes. Update sandbox workflow to ensure constructor arguments are saved with double quotes in .env file.
1 parent 98ff352 commit b4f2c63

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.github/workflows/sandbox.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176
fi
177177
178178
if [ -n "$CONSTRUCTOR_ARGS" ]; then
179-
echo "CONTRACT_CONSTRUCTOR_ARGS='$CONSTRUCTOR_ARGS'" >> .env
179+
echo "CONTRACT_CONSTRUCTOR_ARGS=\"$CONSTRUCTOR_ARGS\"" >> .env
180180
echo "📋 Saved constructor args to .env file"
181181
fi
182182

scripts/interaction_existing_contract.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ async function main() {
5050
logger.info("📦 Reconstructing contract instance from environment variables...");
5151

5252
// Parse constructor args
53-
const constructorArgs = JSON.parse(constructorArgsJson).map((arg: string) => AztecAddress.fromString(arg));
53+
let constructorArgs;
54+
try {
55+
// Remove any surrounding quotes that might have been added
56+
const cleanedJson = constructorArgsJson.trim().replace(/^['"]|['"]$/g, '');
57+
logger.info(`Parsing constructor args: ${cleanedJson}`);
58+
constructorArgs = JSON.parse(cleanedJson).map((arg: string) => AztecAddress.fromString(arg));
59+
} catch (error) {
60+
logger.error(`Failed to parse constructor args: ${constructorArgsJson}`);
61+
logger.error(`Error: ${error}`);
62+
throw error;
63+
}
5464

5565
// Reconstruct contract instance
5666
const votingContractAddress = AztecAddress.fromString(contractAddress);

0 commit comments

Comments
 (0)