Spaces:
Sleeping
Sleeping
File size: 5,663 Bytes
86deab0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | #!/usr/bin/env node
// scripts/validate-deployment.js
// Validate deployed contracts on each testnet
const { ethers } = require("hardhat");
// Testnet configurations
const TESTNETS = [
{
name: "sepolia",
displayName: "Ethereum Sepolia",
chainId: 11155111,
explorer: "https://sepolia.etherscan.io"
},
{
name: "polygonAmoy",
displayName: "Polygon Amoy",
chainId: 80002,
explorer: "https://amoy.polygonscan.com"
},
{
name: "bscTestnet",
displayName: "BSC Testnet",
chainId: 97,
explorer: "https://testnet.bscscan.com"
},
{
name: "avalancheFuji",
displayName: "Avalanche Fuji",
chainId: 43113,
explorer: "https://testnet.snowtrace.io"
},
{
name: "fantomTestnet",
displayName: "Fantom Testnet",
chainId: 4002,
explorer: "https://testnet.ftmscan.com"
}
];
// Minimal Oracle ABI for validation
const ORACLE_ABI = [
"function requestCounter() view returns (uint256)",
"function owner() view returns (address)",
"function oracleNode() view returns (address)",
"function fee() view returns (uint256)",
"function COMMIT_REVEAL_DELAY() view returns (uint256)",
"function getBalance() view returns (uint256)"
];
async function validateContract(networkName, contractAddress) {
const networkConfig = TESTNETS.find(n => n.name === networkName);
if (!networkConfig) {
throw new Error(`Unknown network: ${networkName}`);
}
console.log(`\n========================================`);
console.log(`Validating ${networkConfig.displayName}`);
console.log(`========================================`);
console.log("Contract:", contractAddress);
console.log("Explorer:", `${networkConfig.explorer}/address/${contractAddress}`);
// Connect to contract
const contract = new ethers.Contract(contractAddress, ORACLE_ABI, ethers.provider);
// Validate contract functions
console.log("\nChecking contract functions...");
try {
const [requestCounter, owner, oracleNode, fee, delay, balance] = await Promise.all([
contract.requestCounter(),
contract.owner(),
contract.oracleNode(),
contract.fee(),
contract.COMMIT_REVEAL_DELAY(),
contract.getBalance()
]);
console.log("✓ Contract is responsive");
console.log("\nContract State:");
console.log(` Request Counter: ${requestCounter.toString()}`);
console.log(` Owner: ${owner}`);
console.log(` Oracle Node: ${oracleNode}`);
console.log(` Fee: ${ethers.utils.formatEther(fee)} ETH`);
console.log(` Commit-Reveal Delay: ${delay.toString()} blocks`);
console.log(` Contract Balance: ${ethers.utils.formatEther(balance)} ETH`);
// Validate expected values
const validations = [
{ name: "Owner address", check: owner !== ethers.constants.AddressZero, expected: "non-zero address" },
{ name: "Oracle node address", check: oracleNode !== ethers.constants.AddressZero, expected: "non-zero address" },
{ name: "Commit-reveal delay", check: delay.toString() === "2", expected: "2 blocks" },
{ name: "Fee", check: fee.gt(0), expected: "> 0 ETH" }
];
console.log("\nValidations:");
let allPassed = true;
validations.forEach(v => {
const status = v.check ? "✓" : "✗";
console.log(` ${status} ${v.name}: ${v.check ? "PASS" : "FAIL"} (expected: ${v.expected})`);
if (!v.check) allPassed = false;
});
return allPassed;
} catch (error) {
console.log("✗ Contract validation failed:", error.message);
return false;
}
}
async function main() {
console.log("==============================================");
console.log("QuantumRandomnessOracle Deployment Validation");
console.log("==============================================\n");
// Load deployment summary
const fs = require("fs");
const path = require("path");
const summaryPath = path.join(__dirname, "../deployments/deployment-summary.json");
if (!fs.existsSync(summaryPath)) {
console.log("No deployment summary found. Run deploy-all-testnets.js first.");
return;
}
const summary = JSON.parse(fs.readFileSync(summaryPath, "utf8"));
console.log(`Loaded ${summary.deployments.length} deployments from ${summary.deploymentDate}\n`);
const results = [];
// Validate each deployment
for (const deployment of summary.deployments) {
try {
await hre.network.change(deployment.network);
const isValid = await validateContract(
deployment.network,
deployment.contractAddress
);
results.push({
network: deployment.network,
displayName: deployment.displayName,
valid: isValid
});
} catch (error) {
console.log(`\n✗ Validation failed for ${deployment.network}:`, error.message);
results.push({
network: deployment.network,
displayName: deployment.displayName,
valid: false,
error: error.message
});
}
}
// Summary
console.log("\n==============================================");
console.log("Validation Summary");
console.log("==============================================");
const validCount = results.filter(r => r.valid).length;
console.log(`Valid: ${validCount}/${results.length}`);
console.log(`Invalid: ${results.length - validCount}/${results.length}`);
if (validCount === results.length) {
console.log("\n✓ All contracts validated successfully!");
} else {
console.log("\n⚠ Some contracts failed validation. Check the logs above.");
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("Fatal error:", error);
process.exit(1);
});
|