compare-layout.js 878 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env node
  2. const fs = require('fs');
  3. const { getStorageUpgradeReport } = require('@openzeppelin/upgrades-core/dist/storage');
  4. const { hideBin } = require('yargs/helpers');
  5. const { argv } = require('yargs/yargs')(hideBin(process.argv))
  6. .env('')
  7. .options({
  8. ref: { type: 'string', required: true },
  9. head: { type: 'string', required: true },
  10. });
  11. const oldLayout = JSON.parse(fs.readFileSync(argv.ref));
  12. const newLayout = JSON.parse(fs.readFileSync(argv.head));
  13. for (const name in oldLayout) {
  14. if (name in newLayout) {
  15. const report = getStorageUpgradeReport(oldLayout[name], newLayout[name], {});
  16. if (!report.ok) {
  17. console.log(`Storage layout incompatibility found in ${name}:`);
  18. console.log(report.explain());
  19. process.exitCode = 1;
  20. }
  21. } else {
  22. console.log(`WARNING: ${name} is missing from the current branch`);
  23. }
  24. }