Skip to content

Commit

Permalink
Additional mapping and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchPierias committed Apr 19, 2019
1 parent 9f91608 commit 92ea89c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/contracts/typeGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ import {
mapParameterType
} from './typeGenerator';

const validTypes = ['string','bool','name']
/**
* Big Number Types
* @desc Javascript only supports number, so CPP integer types need to be mapped accordingly
*/
const numberTypes = [
'int8','int16','int32','int64','int128','int256',
'uint8','uint16','uint32','uint64','uint128','uint256',
'uint8_t','uint16_t','uint32_t','uint64_t','uint128_t','uint256_t'
];

const numberTypes = ['uint8','uint16','uint32','uint64','uint128','uint256'];
/**
* EOS Name Types
* @desc Name types are typically a string or uint64_t and typically represent an identity on the EOS blockchain
*/
const stringNumberTypes = ['name','action_name','scope_name','account_name','permission_name','table_name'];

describe("type generator", () => {

Expand All @@ -20,8 +32,14 @@ describe("type generator", () => {
});

context('eos types', () => {
it(`should map 'name' to 'string|number'`, () => {
assert.equal(mapParameterType('name'), 'string|number', `'name' type should map to 'string' or 'number'`)

it(`should map name types to 'string|number'`, () => {
stringNumberTypes.map(type =>
assert.equal(mapParameterType(type), 'string|number', `'${type}' type should map to 'string' or 'number'`))
});

it(`should map 'checksum' to 'string'`, () => {
assert.equal(mapParameterType('checksum'), 'string', `'checksum' type should map to 'string'`)
});
});

Expand Down
7 changes: 7 additions & 0 deletions src/contracts/typeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const types:TypeMapping = {
'string':'string',
'bool':'boolean',
'name':'string|number',
'action_name':'string|number',
'scope_name':'string|number',
'account_name':'string|number',
'permission_name':'string|number',
'table_name':'string|number',
'checksum':'string',
'checksum256':'string',
'int8':'number',
'int16':'number',
'int32':'number',
Expand Down

0 comments on commit 92ea89c

Please sign in to comment.