create-ton 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +80 -0
- package/dist/template/.prettierrc +7 -0
- package/dist/template/LICENSE +21 -0
- package/dist/template/README.md +82 -0
- package/dist/template/jest.config.js +4 -0
- package/dist/template/package.json +23 -0
- package/dist/template/tsconfig.json +12 -0
- package/dist/template/variants/counter/contracts/counter.fc +71 -0
- package/dist/template/variants/counter/contracts/imports/stdlib.fc +624 -0
- package/dist/template/variants/counter/scripts/deployCounter.ts +19 -0
- package/dist/template/variants/counter/tests/Counter.spec.ts +93 -0
- package/dist/template/variants/counter/wrappers/Counter.compile.ts +5 -0
- package/dist/template/variants/counter/wrappers/Counter.ts +66 -0
- package/dist/template/variants/empty/contracts/imports/stdlib.fc +624 -0
- package/dist/template/variants/empty/contracts/my_contract.fc +5 -0
- package/dist/template/variants/empty/scripts/deployMyContract.ts +13 -0
- package/dist/template/variants/empty/tests/MyContract.spec.ts +29 -0
- package/dist/template/variants/empty/wrappers/MyContract.compile.ts +5 -0
- package/dist/template/variants/empty/wrappers/MyContract.ts +36 -0
- package/package.json +31 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Blockchain } from '@ton-community/sandbox';
|
|
2
|
+
import { Cell, toNano } from 'ton-core';
|
|
3
|
+
import { Counter } from '../wrappers/Counter';
|
|
4
|
+
import '@ton-community/test-utils';
|
|
5
|
+
import { compile } from '@ton-community/blueprint';
|
|
6
|
+
|
|
7
|
+
describe('Counter', () => {
|
|
8
|
+
let code: Cell;
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
code = await compile('Counter');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should deploy', async () => {
|
|
15
|
+
const blockchain = await Blockchain.create();
|
|
16
|
+
|
|
17
|
+
const counter = blockchain.openContract(
|
|
18
|
+
await Counter.createFromConfig(
|
|
19
|
+
{
|
|
20
|
+
id: 0,
|
|
21
|
+
counter: 0,
|
|
22
|
+
},
|
|
23
|
+
code
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const deployer = await blockchain.treasury('deployer');
|
|
28
|
+
|
|
29
|
+
const deployResult = await counter.sendDeploy(deployer.getSender(), toNano('0.05'));
|
|
30
|
+
|
|
31
|
+
expect(deployResult.transactions).toHaveTransaction({
|
|
32
|
+
from: deployer.address,
|
|
33
|
+
to: counter.address,
|
|
34
|
+
deploy: true,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should increase counter', async () => {
|
|
39
|
+
const blockchain = await Blockchain.create();
|
|
40
|
+
|
|
41
|
+
const counter = blockchain.openContract(
|
|
42
|
+
await Counter.createFromConfig(
|
|
43
|
+
{
|
|
44
|
+
id: 0,
|
|
45
|
+
counter: 0,
|
|
46
|
+
},
|
|
47
|
+
code
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const deployer = await blockchain.treasury('deployer');
|
|
52
|
+
|
|
53
|
+
const deployResult = await counter.sendDeploy(deployer.getSender(), toNano('0.05'));
|
|
54
|
+
|
|
55
|
+
expect(deployResult.transactions).toHaveTransaction({
|
|
56
|
+
from: deployer.address,
|
|
57
|
+
to: counter.address,
|
|
58
|
+
deploy: true,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const increaseTimes = 3;
|
|
62
|
+
for (let i = 0; i < increaseTimes; i++) {
|
|
63
|
+
console.log(`increase ${i + 1}/${increaseTimes}`);
|
|
64
|
+
|
|
65
|
+
const increaser = await blockchain.treasury('increaser' + i);
|
|
66
|
+
|
|
67
|
+
const counterBefore = await counter.getCounter();
|
|
68
|
+
|
|
69
|
+
console.log('counter before increasing', counterBefore);
|
|
70
|
+
|
|
71
|
+
const increaseBy = Math.floor(Math.random() * 100);
|
|
72
|
+
|
|
73
|
+
console.log('increasing by', increaseBy);
|
|
74
|
+
|
|
75
|
+
const increaseResult = await counter.sendIncrease(increaser.getSender(), {
|
|
76
|
+
increaseBy,
|
|
77
|
+
value: toNano('0.05'),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(increaseResult.transactions).toHaveTransaction({
|
|
81
|
+
from: increaser.address,
|
|
82
|
+
to: counter.address,
|
|
83
|
+
success: true,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const counterAfter = await counter.getCounter();
|
|
87
|
+
|
|
88
|
+
console.log('counter after increasing', counterAfter);
|
|
89
|
+
|
|
90
|
+
expect(counterAfter).toBe(counterBefore + increaseBy);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from 'ton-core';
|
|
2
|
+
|
|
3
|
+
export type CounterConfig = {
|
|
4
|
+
id: number;
|
|
5
|
+
counter: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function counterConfigToCell(config: CounterConfig): Cell {
|
|
9
|
+
return beginCell().storeUint(config.id, 32).storeUint(config.counter, 32).endCell();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Opcodes = {
|
|
13
|
+
increase: 0x7e8764ef,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class Counter implements Contract {
|
|
17
|
+
constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {}
|
|
18
|
+
|
|
19
|
+
static createFromAddress(address: Address) {
|
|
20
|
+
return new Counter(address);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static createFromConfig(config: CounterConfig, code: Cell, workchain = 0) {
|
|
24
|
+
const data = counterConfigToCell(config);
|
|
25
|
+
const init = { code, data };
|
|
26
|
+
return new Counter(contractAddress(workchain, init), init);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async sendDeploy(provider: ContractProvider, via: Sender, value: bigint) {
|
|
30
|
+
await provider.internal(via, {
|
|
31
|
+
value,
|
|
32
|
+
sendMode: SendMode.PAY_GAS_SEPARATLY,
|
|
33
|
+
body: beginCell().endCell(),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async sendIncrease(
|
|
38
|
+
provider: ContractProvider,
|
|
39
|
+
via: Sender,
|
|
40
|
+
opts: {
|
|
41
|
+
increaseBy: number;
|
|
42
|
+
value: bigint;
|
|
43
|
+
queryID?: number;
|
|
44
|
+
}
|
|
45
|
+
) {
|
|
46
|
+
await provider.internal(via, {
|
|
47
|
+
value: opts.value,
|
|
48
|
+
sendMode: SendMode.PAY_GAS_SEPARATLY,
|
|
49
|
+
body: beginCell()
|
|
50
|
+
.storeUint(Opcodes.increase, 32)
|
|
51
|
+
.storeUint(opts.queryID ?? 0, 64)
|
|
52
|
+
.storeUint(opts.increaseBy, 32)
|
|
53
|
+
.endCell(),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async getCounter(provider: ContractProvider) {
|
|
58
|
+
const result = await provider.get('get_counter', []);
|
|
59
|
+
return result.stack.readNumber();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getID(provider: ContractProvider) {
|
|
63
|
+
const result = await provider.get('get_id', []);
|
|
64
|
+
return result.stack.readNumber();
|
|
65
|
+
}
|
|
66
|
+
}
|