migrate-imports.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. const path = require('path');
  2. const {
  3. promises: fs,
  4. constants: { F_OK },
  5. } = require('fs');
  6. const { expect } = require('chai');
  7. const { pathUpdates, updateImportPaths, getUpgradeablePath } = require('../scripts/migrate-imports.js');
  8. describe('migrate-imports.js', function () {
  9. it('every new path exists', async function () {
  10. for (const p of Object.values(pathUpdates)) {
  11. try {
  12. await fs.access(path.join('contracts', p), F_OK);
  13. } catch (e) {
  14. if (p.startsWith('proxy/')) continue; // excluded from transpilation of upgradeable contracts
  15. await fs.access(path.join('contracts', getUpgradeablePath(p)), F_OK);
  16. }
  17. }
  18. });
  19. it('replaces import paths in a file', async function () {
  20. const source = `
  21. import '@openzeppelin/contracts/math/Math.sol';
  22. import '@openzeppelin/contracts-upgradeable/math/MathUpgradeable.sol';
  23. `;
  24. const expected = `
  25. import '@openzeppelin/contracts/utils/math/Math.sol';
  26. import '@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol';
  27. `;
  28. expect(updateImportPaths(source)).to.equal(expected);
  29. });
  30. });