Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/core/src/config/validate-contract-graph.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type { ContractConfig } from "./config.schema.js";
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { resolveDeployOrder } from "../contracts/resolve-deploy-order.js";
import { CONTRACT_ID_PLACEHOLDER_PATTERN } from "../contracts/placeholder-engine.js";

const CONTRACT_ID_PLACEHOLDER = /^\$\{contracts\.([A-Za-z0-9_-]+)\.contractId\}$/;
// #158: same grammar as the resolver, anchored so a value must be exactly a
// single placeholder.
const CONTRACT_ID_PLACEHOLDER = new RegExp(`^${CONTRACT_ID_PLACEHOLDER_PATTERN}$`);

function parseContractIdPlaceholder(value: string): string | undefined {
return value.match(CONTRACT_ID_PLACEHOLDER)?.[1];
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/contracts/placeholder-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ export type PlaceholderContext = {
sourceAddress?: string;
};

const CONTRACT_ID_REGEX = /\$\{contracts\.([A-Za-z0-9_-]+)\.contractId\}/g;
/**
* Grammar of a `${contracts.<name>.contractId}` placeholder (#158). Exported as
* a source string so the anchored validation-time check and the global
* resolve-time replacement share one definition and can't drift.
*/
export const CONTRACT_ID_PLACEHOLDER_PATTERN = String.raw`\$\{contracts\.([A-Za-z0-9_-]+)\.contractId\}`;

const CONTRACT_ID_REGEX = new RegExp(CONTRACT_ID_PLACEHOLDER_PATTERN, "g");
const SOURCE_ADDRESS_REGEX = /\$\{source\.address\}/g;

export function resolvePlaceholders(text: string, context: PlaceholderContext): string {
Expand Down
15 changes: 4 additions & 11 deletions packages/core/src/contracts/verify-expect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CaatingaError, CaatingaErrorCode } from "../errors/CaatingaError.js";
import { ExpectMatcherSchema } from "../config/config.schema.js";
import type { ExpectMatcher, ExpectSpec } from "../config/config.schema.js";

export type VerifyExpectResult = {
Expand All @@ -14,17 +15,9 @@ export type VerifyExpectFailure = {

export type VerifyExpectOutcome = VerifyExpectResult | VerifyExpectFailure;

const EXPECT_MATCHERS: ReadonlySet<ExpectMatcher> = new Set([
"equals",
"reachable",
"isNull",
"isArray",
"minLength",
"maxLength",
"contains",
"matches",
"jsonEquals",
]);
// #158: derive the allowed matchers from the canonical Zod enum so the list
// can't drift from the schema and a new matcher only needs adding in one place.
const EXPECT_MATCHERS: ReadonlySet<ExpectMatcher> = new Set(ExpectMatcherSchema.options);

function describeExpectSpec(spec: ExpectSpec): string {
if (typeof spec === "string") {
Expand Down