Skip to content

Commit

Permalink
feat: initial commit and example of using tact
Browse files Browse the repository at this point in the history
  • Loading branch information
ex3ndr committed Dec 13, 2022
0 parents commit d436f4b
Show file tree
Hide file tree
Showing 16 changed files with 6,567 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ["/node_modules/","/dist/"],
maxWorkers: 1
};
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "tact-template",
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/ton-community/tact-template.git",
"author": "Steve Korshakov <[email protected]>",
"license": "MIT",
"scripts": {
"build": "tact --config ./tact.config.json"
},
"dependencies": {
"@types/jest": "^29.2.4",
"@types/node": "^18.11.14",
"jest": "^29.3.1",
"prando": "^6.0.1",
"ton": "^12.1.5",
"ton-contract-executor": "^0.6.0",
"ton-crypto": "^3.2.0",
"ton-nodejs": "^1.4.2",
"ton-tact": "^0.0.4",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
}
}
28 changes: 28 additions & 0 deletions sources/contract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { toNano } from 'ton';
import { createExecutorFromCode } from 'ton-nodejs';
import { SampleTactContract, SampleTactContract_init } from './output/sample_SampleTactContract';
import { randomAddress } from './utils/randomAddress';

describe('contract', () => {
it('should deploy correctly', async () => {

// Create stateinit
let owner = randomAddress(0, 'some-owner');
let nonOwner = randomAddress(0, 'some-non-owner');
let init = await SampleTactContract_init(owner);
let executor = await createExecutorFromCode(init);
let contract = new SampleTactContract(executor);

// Check counter
expect((await contract.getCounter()).toString()).toEqual('0');

// Increment counter
await contract.send({ amount: toNano(1), from: owner }, 'increment');

// Check counter
expect((await contract.getCounter()).toString()).toEqual('1');

// Non-owner
await expect(() => contract.send({ amount: toNano(1), from: nonOwner }, 'increment')).rejects.toThrowError('Exit code: 100');
});
});
36 changes: 36 additions & 0 deletions sources/contract.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
message Add {
amount: Int as uint32;
}

contract SampleTactContract {

owner: Address;
counter: Int as uint32;

init(owner: Address) {
self.owner = owner;
self.counter = 0;
}

fun add(v: Int) {

// Check sender
let ctx: Context = context();
require(100, ctx.sender == self.owner);

// Update counter
self.counter = (self.counter + v);
}

receive(msg: Add) {
self.add(msg.amount);
}

receive("increment") {
self.add(1);
}

get fun counter(): Int {
return self.counter;
}
}
Loading

0 comments on commit d436f4b

Please sign in to comment.