Skip to content

Commit

Permalink
Added typeGeneration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchPierias committed Apr 19, 2019
1 parent 4a7566a commit 8935d6e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
55 changes: 41 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
47 changes: 47 additions & 0 deletions src/contracts/typeGenerator.test.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>');
});

xit(`should handle vector types`, () => {
assert.equal(mapParameterType('vector<string>'), 'Array<string>');
});
});
});
});

0 comments on commit 8935d6e

Please sign in to comment.