diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-07-12 17:53:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-12 17:53:21 +0800 |
commit | 34a903516439ec64073cfcb10cee87a9c4db902e (patch) | |
tree | 44f8a25ecfd3d860ffb9dc05f7494593744b1a0e /packages/abi-gen/test/utils_test.ts | |
parent | b82fdd59e70e92ef139f5eeed8ed383a89866c7d (diff) | |
parent | 4b60a3cbab3a97125499cb89d9c253deebfb7d2d (diff) | |
download | dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.gz dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.bz2 dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.lz dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.xz dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.tar.zst dexon-sol-tools-34a903516439ec64073cfcb10cee87a9c4db902e.zip |
Merge pull request #788 from feuGeneA/abi-gen-ignore-unchanged
Using timestamps, skip generation of already-up-to-date contract wrappers
Diffstat (limited to 'packages/abi-gen/test/utils_test.ts')
-rw-r--r-- | packages/abi-gen/test/utils_test.ts | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/packages/abi-gen/test/utils_test.ts b/packages/abi-gen/test/utils_test.ts new file mode 100644 index 000000000..c6147df38 --- /dev/null +++ b/packages/abi-gen/test/utils_test.ts @@ -0,0 +1,86 @@ +import * as chai from 'chai'; +import * as dirtyChai from 'dirty-chai'; +import * as fs from 'fs'; +import 'mocha'; +import * as sleep from 'sleep'; +import * as tmp from 'tmp'; + +import { utils } from '../src/utils'; + +tmp.setGracefulCleanup(); // remove tmp files even if there are failures + +chai.use(dirtyChai); + +const expect = chai.expect; + +const SLEEP_MS = 10; // time to wait before re-timestamping a file + +describe('makeOutputFileName()', () => { + it('should handle Metacoin usage', () => { + expect(utils.makeOutputFileName('Metacoin')).to.equal('metacoin'); + }); + it('should handle special zrx_token case', () => { + expect(utils.makeOutputFileName('ZRXToken')).to.equal('zrx_token'); + }); + it('should handle special erc_token case', () => { + expect(utils.makeOutputFileName('ERC20Token')).to.equal('erc20_token'); + }); +}); + +describe('writeOutputFile()', () => { + let tempFilePath: string; + before(() => { + tempFilePath = tmp.fileSync( + { discardDescriptor: true }, // close file (so we can update it) + ).name; + }); + it('should write content to output file', () => { + const content = 'hello world'; + + utils.writeOutputFile(tempFilePath, content); + + expect(fs.readFileSync(tempFilePath).toString()).to.equal(content); + }); +}); + +describe('isOutputFileUpToDate()', () => { + it('should throw ENOENT when there is no abi file', () => { + expect(utils.isOutputFileUpToDate.bind('nonexistant1', 'nonexistant2')).to.throw('ENOENT'); + }); + + describe('when the abi input file exists', () => { + let abiFile: string; + before(() => { + abiFile = tmp.fileSync( + { discardDescriptor: true }, // close file (set timestamp) + ).name; + }); + + describe('without an existing output file', () => { + it('should return false', () => { + expect(utils.isOutputFileUpToDate(abiFile, 'nonexistant_file')).to.be.false(); + }); + }); + + describe('with an existing output file', () => { + let outputFile: string; + before(() => { + sleep.msleep(SLEEP_MS); // to ensure different timestamp + outputFile = tmp.fileSync( + { discardDescriptor: true }, // close file (set timestamp) + ).name; + }); + + it('should return true when output file and is newer than abi file', async () => { + expect(utils.isOutputFileUpToDate(abiFile, outputFile)).to.be.true(); + }); + + it('should return false when output file exists but is older than abi file', () => { + sleep.msleep(SLEEP_MS); // to ensure different timestamp + fs.closeSync(fs.openSync(abiFile, 'w')); // touch abi file + + expect(utils.isOutputFileUpToDate(abiFile, outputFile)).to.be.false(); + }); + }); + }); +}); |