118 lines
4.8 KiB
JavaScript
118 lines
4.8 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
const { ethers } = require("ethers");
|
|
|
|
const ROOT = path.resolve(__dirname, "..");
|
|
const runtimePath = path.resolve(ROOT, "deploy/runtime-addresses.base-sepolia.json");
|
|
const membershipPath = path.resolve(ROOT, "deploy/membership-deploy.sepolia.json");
|
|
const entitlementPath = path.resolve(ROOT, "deploy/entitlement-deploy.sepolia.json");
|
|
|
|
function readJSON(filePath) {
|
|
if (!fs.existsSync(filePath)) {
|
|
throw new Error(`missing file: ${filePath}`);
|
|
}
|
|
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
}
|
|
|
|
function assert(cond, message) {
|
|
if (!cond) {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
function normalizedAddress(value) {
|
|
return String(value || "").trim().toLowerCase();
|
|
}
|
|
|
|
function requireAddress(label, value, { allowZero = false } = {}) {
|
|
assert(ethers.utils.isAddress(value), `invalid ${label}: ${value}`);
|
|
if (!allowZero) {
|
|
assert(
|
|
normalizedAddress(value) !== ethers.constants.AddressZero.toLowerCase(),
|
|
`zero address not allowed for ${label}`
|
|
);
|
|
}
|
|
}
|
|
|
|
function requireUintString(label, value) {
|
|
const raw = String(value || "").trim();
|
|
assert(/^[0-9]+$/.test(raw), `invalid uint string for ${label}: ${value}`);
|
|
}
|
|
|
|
function main() {
|
|
const runtime = readJSON(runtimePath);
|
|
const membership = readJSON(membershipPath);
|
|
const entitlement = readJSON(entitlementPath);
|
|
|
|
assert(String(runtime.network) === "base-sepolia", `runtime network mismatch: ${runtime.network}`);
|
|
assert(Number(runtime.chain_id) === 84532, `runtime chain_id mismatch: ${runtime.chain_id}`);
|
|
requireAddress("runtime.membership_contract", runtime.membership_contract);
|
|
requireAddress("runtime.entitlement_contract", runtime.entitlement_contract);
|
|
requireAddress("runtime.offer_registry_contract", runtime.offer_registry_contract);
|
|
requireAddress("runtime.treasury_wallet", runtime.treasury_wallet);
|
|
assert(
|
|
normalizedAddress(runtime.entitlement_contract) === normalizedAddress(runtime.offer_registry_contract),
|
|
"runtime entitlement_contract must equal offer_registry_contract"
|
|
);
|
|
assert(
|
|
runtime.mint_currency_mode === "ETH_TEST" || runtime.mint_currency_mode === "USDC",
|
|
`runtime mint_currency_mode invalid: ${runtime.mint_currency_mode}`
|
|
);
|
|
requireUintString("runtime.mint_amount_atomic", runtime.mint_amount_atomic);
|
|
|
|
assert(Number(membership.chainId) === 84532, `membership chainId mismatch: ${membership.chainId}`);
|
|
requireAddress("membership.membershipContract", membership.membershipContract);
|
|
requireAddress("membership.treasury", membership.treasury);
|
|
requireUintString("membership.mintAmountAtomic", membership.mintAmountAtomic);
|
|
|
|
assert(Number(entitlement.chainId) === 84532, `entitlement chainId mismatch: ${entitlement.chainId}`);
|
|
requireAddress("entitlement.entitlementContract", entitlement.entitlementContract);
|
|
requireAddress("entitlement.membershipContract", entitlement.membershipContract);
|
|
requireAddress("entitlement.treasury", entitlement.treasury);
|
|
requireUintString("entitlement.offerPriceAtomic", entitlement.offerPriceAtomic);
|
|
|
|
assert(
|
|
normalizedAddress(runtime.membership_contract) === normalizedAddress(membership.membershipContract),
|
|
"runtime membership_contract mismatch with membership deploy artifact"
|
|
);
|
|
assert(
|
|
normalizedAddress(runtime.membership_contract) === normalizedAddress(entitlement.membershipContract),
|
|
"runtime membership_contract mismatch with entitlement deploy artifact"
|
|
);
|
|
assert(
|
|
normalizedAddress(runtime.entitlement_contract) === normalizedAddress(entitlement.entitlementContract),
|
|
"runtime entitlement_contract mismatch with entitlement deploy artifact"
|
|
);
|
|
assert(
|
|
normalizedAddress(runtime.treasury_wallet) === normalizedAddress(membership.treasury),
|
|
"runtime treasury_wallet mismatch with membership deploy artifact"
|
|
);
|
|
assert(
|
|
normalizedAddress(runtime.treasury_wallet) === normalizedAddress(entitlement.treasury),
|
|
"runtime treasury_wallet mismatch with entitlement deploy artifact"
|
|
);
|
|
|
|
if (runtime.mint_currency_mode === "ETH_TEST") {
|
|
assert(
|
|
normalizedAddress(membership.mintCurrency) === ethers.constants.AddressZero.toLowerCase(),
|
|
`ETH_TEST mode requires membership mintCurrency zero address, got ${membership.mintCurrency}`
|
|
);
|
|
assert(
|
|
normalizedAddress(entitlement.paymentToken) === ethers.constants.AddressZero.toLowerCase(),
|
|
`ETH_TEST mode requires entitlement paymentToken zero address, got ${entitlement.paymentToken}`
|
|
);
|
|
}
|
|
|
|
console.log("PASS: runtime address artifacts are structurally valid and internally aligned");
|
|
console.log(` membership_contract=${runtime.membership_contract}`);
|
|
console.log(` entitlement_contract=${runtime.entitlement_contract}`);
|
|
console.log(` treasury_wallet=${runtime.treasury_wallet}`);
|
|
}
|
|
|
|
try {
|
|
main();
|
|
} catch (err) {
|
|
console.error(`FAIL: ${err.message || err}`);
|
|
process.exit(1);
|
|
}
|