From 8935d6efb3daf6b7ae4c56538ad9b2901027235e Mon Sep 17 00:00:00 2001 From: Mitch Pierias Date: Fri, 19 Apr 2019 12:22:27 +1000 Subject: [PATCH] Added typeGeneration testing --- package-lock.json | 55 +++++++++++++++++++++-------- package.json | 4 ++- src/contracts/typeGenerator.test.ts | 47 ++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 src/contracts/typeGenerator.test.ts diff --git a/package-lock.json b/package-lock.json index ef45755..69c7265 100644 --- a/package-lock.json +++ b/package-lock.json @@ -124,6 +124,12 @@ "color-convert": "^1.9.0" } }, + "arg": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.0.tgz", + "integrity": "sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==", + "dev": true + }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1148,9 +1154,9 @@ "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, "source-map-support": { - "version": "0.5.11", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.11.tgz", - "integrity": "sha512-//sajEx/fGL3iw6fltKMdPvy8kL3kJ2O3iuYlRoT3k9Kb4BjOoZ+BZzaNHeuaruSt+Kf3Zk9tnfAQg9/AJqUVQ==", + "version": "0.5.12", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", + "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -1215,21 +1221,41 @@ "requires": { "ts-node": "7.0.1", "tsconfig-paths": "^3.5.0" + }, + "dependencies": { + "ts-node": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", + "integrity": "sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==", + "requires": { + "arrify": "^1.0.0", + "buffer-from": "^1.1.0", + "diff": "^3.1.0", + "make-error": "^1.1.1", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "source-map-support": "^0.5.6", + "yn": "^2.0.0" + } + }, + "yn": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", + "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=" + } } }, "ts-node": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", - "integrity": "sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.1.0.tgz", + "integrity": "sha512-34jpuOrxDuf+O6iW1JpgTRDFynUZ1iEqtYruBqh35gICNjN8x+LpVcPAcwzLPi9VU6mdA3ym+x233nZmZp445A==", + "dev": true, "requires": { - "arrify": "^1.0.0", - "buffer-from": "^1.1.0", + "arg": "^4.1.0", "diff": "^3.1.0", "make-error": "^1.1.1", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", "source-map-support": "^0.5.6", - "yn": "^2.0.0" + "yn": "^3.0.0" } }, "tsconfig-paths": { @@ -1443,9 +1469,10 @@ } }, "yn": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.0.tgz", + "integrity": "sha512-kKfnnYkbTfrAdd0xICNFw7Atm8nKpLcLv9AZGEt+kczL/WQVai4e2V6ZN8U/O+iI6WrNuJjNNOyu4zfhl9D3Hg==", + "dev": true } } } diff --git a/package.json b/package.json index f679fcd..501c728 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", "prepublishOnly": "npm test", "prepare": "npm run build", - "test": "jest --config jestconfig.json" + "test": "jest --config jestconfig.json", + "test:mocha": "mocha --require ts-node/register test/**/*.ts" }, "repository": { "type": "git", @@ -45,6 +46,7 @@ "@types/text-encoding": "0.0.35", "eosjs": "20.0.0", "eosjs-ecc": "4.0.4", + "ts-node": "^8.1.0", "typescript": "3.4.3" }, "dependencies": { diff --git a/src/contracts/typeGenerator.test.ts b/src/contracts/typeGenerator.test.ts new file mode 100644 index 0000000..0bf6954 --- /dev/null +++ b/src/contracts/typeGenerator.test.ts @@ -0,0 +1,47 @@ +import { assert } from 'chai'; +import { + mapParameterType +} from './typeGenerator'; + +const validTypes = ['string','bool','name'] + +const numberTypes = ['uint8','uint16','uint32','uint64','uint128','uint256']; + +describe("type generator", () => { + + context('map paramater types', () => { + + it(`should map 'string' to 'string'`, () => { + assert.equal(mapParameterType('string'), 'string', `'string' types should map to 'string'`) + }); + + it(`should map 'bool' to 'boolean'`, () => { + assert.equal(mapParameterType('bool'), 'boolean'); + }); + + context('eos types', () => { + it(`should map 'name' to 'string|number'`, () => { + assert.equal(mapParameterType('name'), 'string|number', `'name' type should map to 'string' or 'number'`) + }); + }); + + context('big numbers', () => { + numberTypes.forEach(type => { + it(`should map '${type}' to 'number'`, () => { + assert.equal(mapParameterType(type), 'number', `Integer type '${type}' should map to 'number'`); + }); + }); + }); + + context('complex types', () => { + + it(`should handle array types`, () => { + assert.equal(mapParameterType('bool[]'), 'Array'); + }); + + xit(`should handle vector types`, () => { + assert.equal(mapParameterType('vector'), 'Array'); + }); + }); + }); +}); \ No newline at end of file