Skip to content

Commit

Permalink
fix: bug with validators (#1589)
Browse files Browse the repository at this point in the history
* We have to wrap validators in a lambda
* Improve logger to use colorized timestamps
  • Loading branch information
ryscheng authored Jun 4, 2024
1 parent 73cf528 commit 74404a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
2 changes: 2 additions & 0 deletions ops/external-prs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DuckDB state
.tmp/
42 changes: 27 additions & 15 deletions ops/external-prs/src/ossd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async function runParameterizedQuery(
const queryPath = relativeDir("queries", `${name}.sql`);
const query = await renderMustacheFromFile(queryPath, params);
logger.info({
message: "running query",
message: `running query: ${query}`,
query: query,
});
const dbAll = util.promisify(db.all.bind(db));
Expand Down Expand Up @@ -359,7 +359,7 @@ class OSSDirectoryPullRequest {
const queryPath = relativeDir("queries", `${name}.sql`);
const query = await renderMustacheFromFile(queryPath, params);
logger.info({
message: "running query",
message: `running query: ${query}`,
query: query,
});
return this.dbAll(query);
Expand Down Expand Up @@ -387,7 +387,7 @@ class OSSDirectoryPullRequest {
const args = this.args;

logger.info({
message: "setting up the pull request for comparison",
message: `setting up the pull request for comparison`,
repo: args.repo,
sha: args.sha,
pr: args.pr,
Expand All @@ -412,7 +412,7 @@ class OSSDirectoryPullRequest {

if (args.duckdbMemoryLimit !== "") {
logger.info({
message: "setting memory limit",
message: `setting memory limit to ${args.duckdbMemoryLimit}`,
memoryLimit: args.duckdbMemoryLimit,
});
await this.dbAll(`
Expand All @@ -433,7 +433,7 @@ class OSSDirectoryPullRequest {
FROM read_json_auto('${dumpPath}');
`);
logger.info({
message: "created table",
message: `created table ${table}`,
tableName: table,
queryResponse: res,
});
Expand Down Expand Up @@ -639,6 +639,13 @@ class OSSDirectoryPullRequest {
results[name].errors.push(message);
};

const addressesToValidate =
this.changes.artifacts.toValidate.blockchain.map((b) => b.address);
logger.info({
message: `Starting validations for ${addressesToValidate}`,
addresses: addressesToValidate,
});

// Run on-chain validations
for (const item of this.changes.artifacts.toValidate.blockchain) {
const address = item.address;
Expand All @@ -658,16 +665,16 @@ class OSSDirectoryPullRequest {
Record<BlockchainTag, (name: string) => Promise<boolean>>
> => {
const mapping = {
eoa: validator.isEOA,
contract: validator.isContract,
deployer: validator.isDeployer,
eoa: (addr: string) => validator.isEOA(addr),
contract: (addr: string) => validator.isContract(addr),
deployer: (addr: string) => validator.isDeployer(addr),
};
return mapping;
};
const validatorMappings = createValidatorMapping(validator);

logger.info({
message: "validating address",
message: `validating address ${address} on ${network} for [${item.tags}]`,
address: address,
network: network,
tags: item.tags,
Expand All @@ -676,15 +683,20 @@ class OSSDirectoryPullRequest {
for (const [tag, validatorFn] of Object.entries(validatorMappings)) {
if (item.tags.includes(tag)) {
if (!validatorFn) {
logger.error(
`ERROR: missing validator for ${tag} on network=${network}`,
);
logger.error({
message: `ERROR: missing validator for ${tag} on network=${network}`,
tag,
network,
});
} else if (!(await validatorFn(address))) {
addErrorToResult(address, `is not a '${tag}' on ${network}`);
} else {
logger.debug(
`validation okay: ${address} is a ${tag} on ${network}`,
);
logger.debug({
message: `validation okay: ${address} is a ${tag} on ${network}`,
address,
tag,
network,
});
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion ops/external-prs/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import winston from "winston";

const logFormat = winston.format.printf(function (info) {
const date = new Date().toISOString();
return `[${info.level}] ${date}: ${JSON.stringify(info.message, null, 2)}`;
});

export const logger = winston.createLogger({
//level: "info",
level: "debug",
format: winston.format.json(),
defaultMeta: {},
transports: [
new winston.transports.Console({
format: winston.format.json(),
format: winston.format.combine(winston.format.colorize(), logFormat),
stderrLevels: ["debug", "info", "warn", "warning", "error"],
}),
//new winston.transports.File({ filename: "error.log", level: "error" }),
Expand Down

0 comments on commit 74404a0

Please sign in to comment.