-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCrudGenerator.js
More file actions
63 lines (53 loc) · 2.26 KB
/
testCrudGenerator.js
File metadata and controls
63 lines (53 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { expect } from 'chai';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
import { generateAppSolidity } from '@tokenhost/generator';
import { lintThs, validateThsStructural } from '@tokenhost/schema';
const require = createRequire(import.meta.url);
const solc = require('solc');
function compileSolidity(sourcePath, contents, contractName) {
const input = {
language: 'Solidity',
sources: {
[sourcePath]: { content: contents }
},
settings: {
optimizer: { enabled: true, runs: 200 },
outputSelection: {
'*': {
'*': ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object']
}
}
}
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
const errors = (output.errors || []).filter((e) => e.severity === 'error');
return { output, errors };
}
describe('Spec-aligned CRUD generator', function () {
this.timeout(15000);
it('generates Solidity that compiles (job-board example)', function () {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const schemaPath = path.join(__dirname, '..', 'apps', 'example', 'job-board.schema.json');
const raw = JSON.parse(fs.readFileSync(schemaPath, 'utf-8'));
const structural = validateThsStructural(raw);
expect(structural.ok).to.equal(true);
const schema = structural.data;
const lintIssues = lintThs(schema);
const lintErrors = lintIssues.filter((i) => i.severity === 'error');
expect(lintErrors).to.have.length(0);
const appSol = generateAppSolidity(schema);
expect(appSol.contents).to.include('pragma solidity ^0.8.24;');
expect(appSol.contents).to.include('contract App');
expect(appSol.contents).to.include('event RecordCreated');
expect(appSol.contents).to.include('function createCandidate');
expect(appSol.contents).to.include('function createJobPosting');
expect(appSol.contents).to.include('function _recordHashCandidate');
expect(appSol.contents).to.include('function _recordHashJobPosting');
const { errors } = compileSolidity(appSol.path, appSol.contents, 'App');
expect(errors.map((e) => e.formattedMessage || e.message).join('\n')).to.equal('');
});
});