Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
run: npm install -g yarn
- name: Install dependencies
run: yarn
- name: Test
run: yarn test
- name: Build
run: yarn build
- name: Setup .yarnrc.yml
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: QA

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: the-ton-tech/toolchain/lint@v1.4.0
build:
name: Test & Build
needs: lint
runs-on: ubuntu-latest
steps:
- uses: the-ton-tech/toolchain/build@v1.4.0
21 changes: 21 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
const base = require('@ton/toolchain');
// eslint-disable-next-line @typescript-eslint/no-require-imports
const tsEslint = require('@ton/toolchain').tsEslint;

module.exports = [
...base,
{
plugins: {
'@typescript-eslint': tsEslint,
},
rules: {
'no-console': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-require-imports': 'warn',
'@typescript-eslint/no-namespace': 'warn',
'no-undef': 'warn',
'no-empty': 'warn',
},
},
];
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"@jest/globals": "^29.5.0",
"@ton/core": "^0.49.2",
"@ton/crypto": "^3.2.0",
"@ton/toolchain": "the-ton-tech/toolchain#v1.4.0",
"@types/chai": "^4.3.4",
"@types/jest": "^29.4.4",
"chai": "^4.3.7",
"eslint": "^9.28.0",
"jest": "^29.5.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
Expand All @@ -39,8 +41,12 @@
"dependencies": {
"node-inspect-extracted": "^2.0.0"
},
"prettier": "@ton/toolchain/prettier",
"scripts": {
"build": "rm -rf dist && jest && tsc"
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test": "jest",
"build": "rm -rf dist && tsc"
},
"packageManager": "yarn@3.6.1"
}
19 changes: 4 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,13 @@ export {
filterTransactions,
} from './test/transaction';

export {
contractsMeta,
ContractsMeta,
} from './utils/ContractsMeta';
export { contractsMeta, ContractsMeta } from './utils/ContractsMeta';

import './test/jest';
import './test/chai';

export {
prettifyTransaction,
PrettyTransaction
} from './utils/pretty-transaction';
export { prettifyTransaction, PrettyTransaction } from './utils/pretty-transaction';

export {
randomAddress,
} from './utils/randomAddress';
export { randomAddress } from './utils/randomAddress';

export {
executeTill,
executeFrom,
} from './utils/stepByStep';
export { executeTill, executeFrom } from './utils/stepByStep';
48 changes: 27 additions & 21 deletions src/test/chai.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import { Address, Cell, Slice } from "@ton/core";
import { compareAddressForTest, compareCellForTest, compareSliceForTest } from "./comparisons";
import { CompareResult } from "./interface";
import { compareTransactionForTest, FlatTransactionComparable } from "./transaction";
import { Address, Cell, Slice } from '@ton/core';

import { compareAddressForTest, compareCellForTest, compareSliceForTest } from './comparisons';
import { CompareResult } from './interface';
import { compareTransactionForTest, FlatTransactionComparable } from './transaction';

function wrapComparer<T>(comparer: (subject: any, cmp: T) => CompareResult) {
return function (this: any, cmp: T) {
const result = comparer(this._obj, cmp)
this.assert(result.pass, result.posMessage(), result.negMessage())
}
const result = comparer(this._obj, cmp);
this.assert(result.pass, result.posMessage(), result.negMessage());
};
}

try {
const chai = require("chai");
// eslint-disable-next-line @typescript-eslint/no-require-imports
const chai = require('chai');

if (chai) chai.use((chai: Chai.ChaiStatic) => {
const Assertion = chai.Assertion
Assertion.addMethod('transaction', wrapComparer(compareTransactionForTest))
Assertion.addMethod('equalCell', wrapComparer(compareCellForTest))
Assertion.addMethod('equalAddress', wrapComparer(compareAddressForTest))
Assertion.addMethod('equalSlice', wrapComparer(compareSliceForTest))
})
} catch (e) {}
if (chai)
// eslint-disable-next-line no-undef
chai.use((chai: Chai.ChaiStatic) => {
const Assertion = chai.Assertion;
Assertion.addMethod('transaction', wrapComparer(compareTransactionForTest));
Assertion.addMethod('equalCell', wrapComparer(compareCellForTest));
Assertion.addMethod('equalAddress', wrapComparer(compareAddressForTest));
Assertion.addMethod('equalSlice', wrapComparer(compareSliceForTest));
});
// eslint-disable-next-line no-empty
} catch (_) {}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Chai {
interface Assertion {
transaction(cmp: FlatTransactionComparable): void
equalCell(cell: Cell): void
equalAddress(address: Address): void
equalSlice(slice: Slice): void
transaction(cmp: FlatTransactionComparable): void;
equalCell(cell: Cell): void;
equalAddress(address: Address): void;
equalSlice(slice: Slice): void;
}
}
}
}
97 changes: 56 additions & 41 deletions src/test/comparisons.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Address, beginCell } from "@ton/core";
import { compareAddressForTest, compareCellForTest, compareSliceForTest } from "./comparisons";
import { Address, beginCell } from '@ton/core';

import { compareAddressForTest, compareCellForTest, compareSliceForTest } from './comparisons';

describe('Cell comparison', () => {
it('should work', () => {
const cell = beginCell().storeUint(1, 32).storeRef(beginCell().storeUint(2, 32)).endCell()
const same = beginCell().storeSlice(cell.beginParse()).endCell()
const notSame = beginCell().storeUint(3, 32).endCell()
const cell = beginCell().storeUint(1, 32).storeRef(beginCell().storeUint(2, 32)).endCell();
const same = beginCell().storeSlice(cell.beginParse()).endCell();
const notSame = beginCell().storeUint(3, 32).endCell();

const passed = compareCellForTest(cell, same)
expect(passed.pass).toBeTruthy()
const passed = compareCellForTest(cell, same);
expect(passed.pass).toBeTruthy();
expect(passed.posMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
x{00000002}
to equal
x{00000001}
x{00000002}"
`)
`);
expect(passed.negMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
Expand All @@ -25,60 +26,74 @@ NOT to equal
x{00000001}
x{00000002}
but it does"
`)
const failed = compareCellForTest(cell, notSame)
expect(failed.pass).toBeFalsy()
`);
const failed = compareCellForTest(cell, notSame);
expect(failed.pass).toBeFalsy();
expect(failed.posMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
x{00000002}
to equal
x{00000003}"
`)
`);
expect(failed.negMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
x{00000002}
NOT to equal
x{00000003}
but it does"
`)
})
})
`);
});
});

describe('Address comparison', () => {
it('should work', () => {
const addr = new Address(0, Buffer.from('40148c1cc823bf3c192da81e92d75d75b425f92052226c7eba2855bc7803ef14', 'hex'))
const same = new Address(addr.workChain, addr.hash)
const notSame = new Address(-1, Buffer.from('366c52da74350a23470952bd07ef8642d34f5fc5138194f17ab193fe522a6aae', 'hex'))
const addr = new Address(
0,
Buffer.from('40148c1cc823bf3c192da81e92d75d75b425f92052226c7eba2855bc7803ef14', 'hex'),
);
const same = new Address(addr.workChain, addr.hash);
const notSame = new Address(
-1,
Buffer.from('366c52da74350a23470952bd07ef8642d34f5fc5138194f17ab193fe522a6aae', 'hex'),
);

const passed = compareAddressForTest(addr, same)
expect(passed.pass).toBeTruthy()
expect(passed.posMessage()).toMatchInlineSnapshot(`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq to equal EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq"`)
expect(passed.negMessage()).toMatchInlineSnapshot(`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq NOT to equal EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq, but it does"`)
const failed = compareAddressForTest(addr, notSame)
expect(failed.pass).toBeFalsy()
expect(failed.posMessage()).toMatchInlineSnapshot(`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq to equal Ef82bFLadDUKI0cJUr0H74ZC009fxROBlPF6sZP-Uipqrn1J"`)
expect(failed.negMessage()).toMatchInlineSnapshot(`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq NOT to equal Ef82bFLadDUKI0cJUr0H74ZC009fxROBlPF6sZP-Uipqrn1J, but it does"`)
})
})
const passed = compareAddressForTest(addr, same);
expect(passed.pass).toBeTruthy();
expect(passed.posMessage()).toMatchInlineSnapshot(
`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq to equal EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq"`,
);
expect(passed.negMessage()).toMatchInlineSnapshot(
`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq NOT to equal EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq, but it does"`,
);
const failed = compareAddressForTest(addr, notSame);
expect(failed.pass).toBeFalsy();
expect(failed.posMessage()).toMatchInlineSnapshot(
`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq to equal Ef82bFLadDUKI0cJUr0H74ZC009fxROBlPF6sZP-Uipqrn1J"`,
);
expect(failed.negMessage()).toMatchInlineSnapshot(
`"Expected EQBAFIwcyCO_PBktqB6S1111tCX5IFIibH66KFW8eAPvFBHq NOT to equal Ef82bFLadDUKI0cJUr0H74ZC009fxROBlPF6sZP-Uipqrn1J, but it does"`,
);
});
});

describe('Slice comparison', () => {
it('should work', () => {
const slice = beginCell().storeUint(1, 32).storeRef(beginCell().storeUint(2, 32)).endCell().beginParse()
const same = beginCell().storeSlice(slice).endCell().beginParse()
const notSame = beginCell().storeUint(3, 32).endCell().beginParse()
const slice = beginCell().storeUint(1, 32).storeRef(beginCell().storeUint(2, 32)).endCell().beginParse();
const same = beginCell().storeSlice(slice).endCell().beginParse();
const notSame = beginCell().storeUint(3, 32).endCell().beginParse();

const passed = compareSliceForTest(slice, same)
expect(passed.pass).toBeTruthy()
const passed = compareSliceForTest(slice, same);
expect(passed.pass).toBeTruthy();
expect(passed.posMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
x{00000002}
to equal
x{00000001}
x{00000002}"
`)
`);
expect(passed.negMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
Expand All @@ -87,23 +102,23 @@ NOT to equal
x{00000001}
x{00000002}
but it does"
`)
const failed = compareSliceForTest(slice, notSame)
expect(failed.pass).toBeFalsy()
`);
const failed = compareSliceForTest(slice, notSame);
expect(failed.pass).toBeFalsy();
expect(failed.posMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
x{00000002}
to equal
x{00000003}"
`)
`);
expect(failed.negMessage()).toMatchInlineSnapshot(`
"Expected
x{00000001}
x{00000002}
NOT to equal
x{00000003}
but it does"
`)
})
})
`);
});
});
Loading