-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial commit and example of using tact
- Loading branch information
0 parents
commit d436f4b
Showing
16 changed files
with
6,567 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.