Skip to content

Commit

Permalink
test(compiler): compare with exact aci
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jun 23, 2023
1 parent 009cce2 commit 7fb2759
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
7 changes: 3 additions & 4 deletions test/integration/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { readFile } from 'fs/promises';
import { compilerUrl, ignoreVersion } from '.';
import inclAci from './contracts/Includes.json';
import {
CompilerBase, CompilerHttpNode, CompilerCli, CompilerError, getFileSystem, Encoded,
} from '../../src';
Expand Down Expand Up @@ -30,15 +31,13 @@ function testCompiler(compiler: CompilerBase): void {
it('compiles and generates aci by path', async () => {
const { bytecode, aci } = await compiler.compile(inclSourceCodePath);
expect(bytecode).to.equal(inclBytecode);
expect(aci).to.have.length(6);
expect(aci[aci.length - 1]).to.have.property('contract');
expect(aci).to.eql(inclAci);
});

it('compiles and generates aci by source code', async () => {
const { bytecode, aci } = await compiler.compileBySourceCode(inclSourceCode, inclFileSystem);
expect(bytecode).to.equal(inclBytecode);
expect(aci).to.have.length(6);
expect(aci[aci.length - 1]).to.have.property('contract');
expect(aci).to.eql(inclAci);
});

it('throws clear exception if compile broken contract', async () => {
Expand Down
20 changes: 3 additions & 17 deletions test/integration/contract-aci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../utils';
import { Aci } from '../../src/contract/compiler/Base';
import { ContractCallObject } from '../../src/contract/Contract';
import includesAci from './contracts/Includes.json';

const identityContractSourceCode = `
contract Identity =
Expand Down Expand Up @@ -207,23 +208,8 @@ describe('Contract instance', () => {

it('compiles contract by sourceCodePath', async () => {
const ctr = await aeSdk.initializeContract({
aci: [{
contract: {
functions: [{
arguments: [{ name: 'x', type: 'int' }],
name: 'increment',
payable: false,
returns: 'int',
stateful: false,
},
],
kind: 'contract_main',
name: 'Increment',
payable: false,
typedefs: [],
},
}],
sourceCodePath: './test/integration/contracts/Increment.aes',
aci: includesAci,
sourceCodePath: './test/integration/contracts/Includes.aes',
});
expect(ctr.$options.bytecode).to.equal(undefined);
expect(await ctr.$compile()).to.satisfy((b: string) => b.startsWith('cb_'));
Expand Down
31 changes: 31 additions & 0 deletions test/integration/contracts/Includes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[{
"namespace": { "name": "ListInternal", "typedefs": [] }
}, {
"namespace": { "name": "List", "typedefs": [] }
}, {
"namespace": { "name": "String", "typedefs": [] }
}, {
"namespace": { "name": "Sublibrary", "typedefs": [] }
}, {
"namespace": { "name": "Library", "typedefs": [] }
}, {
"contract": {
"functions": [{
"arguments": [{ "name": "x", "type": "int" }],
"name": "test",
"payable": false,
"returns": "int",
"stateful": false
}, {
"arguments": [{ "name": "x", "type": "string" }],
"name": "getLength",
"payable": false,
"returns": "int",
"stateful": false
}],
"kind": "contract_main",
"name": "Includes",
"payable": false,
"typedefs": []
}
}]
1 change: 1 addition & 0 deletions tsconfig.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"resolveJsonModule": true,
"noEmit": true
},
"include": [
Expand Down

0 comments on commit 7fb2759

Please sign in to comment.