Skip to content

Commit c06bf66

Browse files
committed
test: add indent utility to store contracts in code
1 parent db78147 commit c06bf66

14 files changed

+327
-291
lines changed

test/integration/AeSdkMethods.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, before } from 'mocha';
22
import { expect } from 'chai';
33
import { getSdk } from '.';
4-
import { assertNotNull, ensureInstanceOf } from '../utils';
4+
import { assertNotNull, ensureInstanceOf, indent } from '../utils';
55
import { AeSdkMethods, AccountBase, MemoryAccount, Contract } from '../../src';
66

77
describe('AeSdkMethods', () => {
@@ -28,7 +28,9 @@ describe('AeSdkMethods', () => {
2828
it('created contract remains connected to sdk', async () => {
2929
const contract = await Contract.initialize({
3030
...aeSdkMethods.getContext(),
31-
sourceCode: '' + 'contract Identity =\n' + ' entrypoint getArg(x : int) = x',
31+
sourceCode: indent`
32+
contract Identity =
33+
entrypoint getArg(x : int) = x`,
3234
});
3335
expect(contract.$options.onAccount?.address).to.be.eql(accounts[0].address);
3436
[, aeSdkMethods._options.onAccount] = accounts;

test/integration/Middleware.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ describe('Middleware API', () => {
383383
blockHash: 'mh_zmcTZSgZcuQ9fL6h6iNNp3ftFvbQ2FjtgPHg9qEHgbwyqFFpi',
384384
localIdx: 0,
385385
callTxHash: 'th_2cNd6j4CtZYaY6F6AWNbYDXZGkaQbaAjjjtBiLATiaiXJ1P812',
386-
contractTxHash: 'th_giDXk5C5Fmvec2yBDEmSn74ZnKCMJv1Nso6uaSbfTup1xSx2Y',
386+
contractTxHash: 'th_2TzSqAuvAAEVFpucVgEALitxyJSJCBsR3RbxpSzPhbYbaasXBb',
387387
internalTx: {
388388
amount: 42,
389389
fee: 0,
@@ -422,7 +422,7 @@ describe('Middleware API', () => {
422422
blockTime: new Date(1721968249016),
423423
eventHash: 'KGBGHR0NTNENA10FD9MJS5P39C1LD4T9AUBIPIDL772714A57HH0====',
424424
callTxHash: 'th_2cNd6j4CtZYaY6F6AWNbYDXZGkaQbaAjjjtBiLATiaiXJ1P812',
425-
contractTxHash: 'th_giDXk5C5Fmvec2yBDEmSn74ZnKCMJv1Nso6uaSbfTup1xSx2Y',
425+
contractTxHash: 'th_2TzSqAuvAAEVFpucVgEALitxyJSJCBsR3RbxpSzPhbYbaasXBb',
426426
microIndex: 0,
427427
extCallerContractId: null,
428428
extCallerContractTxHash: null,
@@ -448,7 +448,7 @@ describe('Middleware API', () => {
448448
abi_version: 3,
449449
amount: 100,
450450
call_data: 'cb_KxFE1kQfP4oEp9E=',
451-
code: 'cb_+QEcRgOg8gEtln8gPwqlcH3Rv3q+KpWksD0m4iwiqY18jtURGonAuO+4wf5E1kQfADcANwAaDoI/AQM//mWl4A8CNwGHAjcBBzcCdwc3AAg9AAIERjYAAABiL1+fAYEFPg9NJAu8Y6cqlt/F0eAzEdVzQbFz6kWUaMkB2l2DOwABAz9GNgAAAEY2AgACYi4AnwGBpBcI7Bft3XUED2ptPhcjSwNWk6lXlyzJtTnEcJFFPGICAQM//pdbzNwANwFHADcADAOvggECASstdGVzdC1zdHJpbmdWAgMRZaXgDw8Cb4Imz2UNAFQBAz+oLwMRRNZEHxFpbml0EWWl4A8tQ2hhaW4uZXZlbnQRl1vM3BVzcGVuZIIvAIU4LjAuMABElFo5',
451+
code: 'cb_+QEcRgOgzPAt3CM1MXJqVKUexArUzQqzhuZqPx4w8pc2S1dcOHXAuO+4wf5E1kQfADcANwAaDoI/AQM//mWl4A8CNwGHAjcBBzcCdwc3AAg9AAIERjYAAABiL1+fAYEFPg9NJAu8Y6cqlt/F0eAzEdVzQbFz6kWUaMkB2l2DOwABAz9GNgAAAEY2AgACYi4AnwGBpBcI7Bft3XUED2ptPhcjSwNWk6lXlyzJtTnEcJFFPGICAQM//pdbzNwANwFHADcADAOvggECASstdGVzdC1zdHJpbmdWAgMRZaXgDw8Cb4Imz2UNAFQBAz+oLwMRRNZEHxFpbml0EWWl4A8tQ2hhaW4uZXZlbnQRl1vM3BVzcGVuZIIvAIU4LjAuMAAyWaKG',
452452
deposit: 0,
453453
fee: 82160000000000,
454454
gas: 76,
@@ -459,7 +459,7 @@ describe('Middleware API', () => {
459459
vm_version: 8,
460460
},
461461
aexnType: null,
462-
sourceTxHash: 'th_giDXk5C5Fmvec2yBDEmSn74ZnKCMJv1Nso6uaSbfTup1xSx2Y',
462+
sourceTxHash: 'th_2TzSqAuvAAEVFpucVgEALitxyJSJCBsR3RbxpSzPhbYbaasXBb',
463463
sourceTxType: 'ContractCreateTx',
464464
};
465465
copyFields(expectedRes, res, ['blockHash']);

test/integration/account-generalized.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import {
1515
Encoded,
1616
ArgumentError,
1717
} from '../../src';
18-
import { ensureEqual } from '../utils';
18+
import { ensureEqual, indent } from '../utils';
1919

20-
const sourceCode = `contract BlindAuth =
20+
const sourceCode = `
21+
contract BlindAuth =
2122
record state = { txHash: option(hash) }
2223
entrypoint init() : state = { txHash = None }
2324
@@ -172,14 +173,13 @@ describe('Generalized Account', () => {
172173
setState: (value: number) => void;
173174
}>({
174175
...aeSdk.getContext(),
175-
sourceCode:
176-
'' +
177-
'contract Stateful =\n' +
178-
' record state = { value: int }\n' +
179-
' entrypoint init(_value: int) : state = { value = _value }\n' +
180-
' entrypoint getState(): int = state.value\n' +
181-
' stateful entrypoint setState(_value: int): unit =\n' +
182-
' put(state{ value = _value })',
176+
sourceCode: indent`
177+
contract Stateful =
178+
record state = { value: int }
179+
entrypoint init(_value: int) : state = { value = _value }
180+
entrypoint getState(): int = state.value
181+
stateful entrypoint setState(_value: int): unit =
182+
put(state{ value = _value })`,
183183
});
184184
await contract.$deploy([42], { authData: { sourceCode, args: [genSalt()] } });
185185
expect((await contract.getState()).decodedResult).to.be.equal(42);

test/integration/aens.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, before } from 'mocha';
22
import { expect } from 'chai';
33
import { RestError } from '@azure/core-rest-pipeline';
44
import { getSdk, isLimitedCoins, timeoutBlock } from '.';
5-
import { assertNotNull, ensureEqual, randomName, randomString } from '../utils';
5+
import { assertNotNull, ensureEqual, indent, randomName, randomString } from '../utils';
66
import {
77
AeSdk,
88
Name,
@@ -218,7 +218,9 @@ describe('Aens', () => {
218218
});
219219

220220
it('calls contract using AENS name', async () => {
221-
const sourceCode = 'contract Identity =' + ' entrypoint getArg(x : int) = x';
221+
const sourceCode = indent`
222+
contract Identity =
223+
entrypoint getArg(x : int) = x`;
222224
interface ContractApi extends ContractMethodsBase {
223225
getArg: (x: number) => bigint;
224226
}

test/integration/chain.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai';
33
import { stub } from 'sinon';
44
import { getSdk, timeoutBlock } from '.';
55
import { AeSdk, Tag, MemoryAccount, Encoded, Node, Contract } from '../../src';
6-
import { assertNotNull, bindRequestCounter } from '../utils';
6+
import { assertNotNull, bindRequestCounter, indent } from '../utils';
77

88
describe('Node Chain', () => {
99
let aeSdk: AeSdk;
@@ -190,7 +190,9 @@ describe('Node Chain', () => {
190190
it('multiple contract dry-runs calls at one request', async () => {
191191
const contract = await Contract.initialize<{ foo: (x: number) => bigint }>({
192192
...aeSdk.getContext(),
193-
sourceCode: 'contract Test =\n' + ' entrypoint foo(x : int) = x * 100',
193+
sourceCode: indent`
194+
contract Test =
195+
entrypoint foo(x : int) = x * 100`,
194196
});
195197
await contract.$deploy([]);
196198
const { result } = await contract.foo(5);

test/integration/compiler.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getFileSystem,
1212
Encoded,
1313
} from '../../src';
14+
import { indent } from '../utils';
1415

1516
function testCompiler(compiler: CompilerBase): void {
1617
const inclSourceCodePath = './test/integration/contracts/Includes.aes';
@@ -94,36 +95,38 @@ function testCompiler(compiler: CompilerBase): void {
9495

9596
it('throws clear exception if compile broken contract', async () => {
9697
await expect(
97-
compiler.compileBySourceCode(
98-
'contract Foo =\n' +
99-
' entrypoint getArg(x : bar) = x\n' +
100-
' entrypoint getArg(x : int) = baz\n' +
101-
' entrypoint getArg1(x : int) = baz\n',
102-
),
98+
compiler.compileBySourceCode(indent`
99+
contract Foo =
100+
entrypoint getArg(x : bar) = x
101+
entrypoint getArg(x : int) = baz
102+
entrypoint getArg1(x : int) = baz`),
103103
).to.be.rejectedWith(
104104
CompilerError,
105105
compiler instanceof CompilerCli
106106
? /Command failed: escript .+[\\/]bin[\\/]aesophia_cli(_8)?( --create_json_aci)? .+\.aes( --no_warning all)?\nType error( in '.+\.aes')? at line 3, col 3:\nDuplicate definitions of `getArg` at\n {2}- line 2, column 3\n {2}- line 3, column 3\n\n/m
107-
: 'compile error:\n' +
108-
'type_error:3:3: Duplicate definitions of `getArg` at\n' +
109-
' - line 2, column 3\n' +
110-
' - line 3, column 3\n' +
111-
'type_error:3:32: Unbound variable `baz`\n' +
112-
'type_error:4:33: Unbound variable `baz`',
107+
: indent`
108+
compile error:
109+
type_error:3:3: Duplicate definitions of \`getArg\` at
110+
- line 2, column 3
111+
- line 3, column 3
112+
type_error:3:32: Unbound variable \`baz\`
113+
type_error:4:33: Unbound variable \`baz\``,
113114
);
114115
});
115116

116117
it('returns warnings', async () => {
117118
const { warnings } = await compiler.compileBySourceCode(
118-
'include "./lib/Library.aes"\n' +
119-
'\n' +
120-
'main contract Foo =\n' +
121-
' entrypoint getArg(x: int) =\n' +
122-
' let t = 42\n' +
123-
' x\n',
119+
indent`
120+
include "./lib/Library.aes"
121+
122+
main contract Foo =
123+
entrypoint getArg(x: int) =
124+
let t = 42
125+
x`,
124126
{
125-
'./lib/Library.aes':
126-
'' + 'contract Library =\n' + ' entrypoint getArg() =\n' + ' 1 / 0\n',
127+
'./lib/Library.aes': indent`
128+
contract Library =
129+
entrypoint getArg() = 1 / 0`,
127130
},
128131
);
129132
expect(warnings).to.eql([
@@ -133,7 +136,7 @@ function testCompiler(compiler: CompilerBase): void {
133136
},
134137
{
135138
message: 'Division by zero.',
136-
pos: { file: './lib/Library.aes', col: 5, line: 3 },
139+
pos: { file: './lib/Library.aes', col: 25, line: 2 },
137140
},
138141
]);
139142
});
@@ -183,11 +186,15 @@ describe('CompilerHttp', () => {
183186
it('reads file system', async () => {
184187
expect(await getFileSystem('./test/integration/contracts/Includes.aes')).to.be.eql({
185188
'./lib/Library.aes':
186-
'include"lib/Sublibrary.aes"\n\n' +
187-
'namespace Library =\n' +
188-
' function sum(x: int, y: int): int = Sublibrary.sum(x, y)\n',
189+
indent`
190+
include"lib/Sublibrary.aes"
191+
192+
namespace Library =
193+
function sum(x: int, y: int): int = Sublibrary.sum(x, y)` + '\n',
189194
'lib/Sublibrary.aes':
190-
'namespace Sublibrary =\n' + ' function sum(x: int, y: int): int = x + y\n',
195+
indent`
196+
namespace Sublibrary =
197+
function sum(x: int, y: int): int = x + y` + '\n',
191198
});
192199
});
193200
});

0 commit comments

Comments
 (0)