Skip to content

Commit a6e751b

Browse files
Added some tests and added them into CI
1 parent feeeadb commit a6e751b

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

.github/workflows/output.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
run: yarn install
1616
- name: Build project
1717
run: yarn blueprint build
18+
- name: Run tests
19+
run: yarn blueprint test
1820
- name: create zip file from build folder
1921
run: zip -r -q build.zip build
2022
- name: Set outputs

scripts/deployMultitokenDex.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { NetworkProvider } from '@ton-community/blueprint';
44
import { inspect } from 'util';
55

66
export async function run(provider: NetworkProvider) {
7-
const multitokenDex = provider.open(await MultitokenDex.fromInit(BigInt(1), provider.sender().address!));
8-
9-
10-
await sendDeploy(multitokenDex, provider, ["EQAMcImLBgZHazWmradz51pI0uHZwvxMONlMQy0QwQTQInD5", "kQAbDiNBKXDn5l3AE8cx-j7zZneFITRRFM-FH-HfBJqsrTLh"].map(elem => Address.parse(elem)))
11-
7+
const jettonMasters = [
8+
"EQAMcImLBgZHazWmradz51pI0uHZwvxMONlMQy0QwQTQInD5",
9+
"kQAbDiNBKXDn5l3AE8cx-j7zZneFITRRFM-FH-HfBJqsrTLh"
10+
].map(elem => Address.parse(elem));
11+
const multitokenDex = provider.open(
12+
await MultitokenDex.fromInit(BigInt(1), provider.sender().address!, BigInt(jettonMasters.length))
13+
);
14+
15+
await sendDeploy(multitokenDex, provider, jettonMasters)
1216
await provider.waitForDeploy(multitokenDex.address);
13-
// run methods on `multitokenDex`
1417
}

tests/MultitokenDex.spec.ts

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1+
import { Address, Dictionary, OpenedContract, TupleBuilder, toNano } from 'ton-core';
12
import { Blockchain, SandboxContract } from '@ton-community/sandbox';
2-
import { toNano } from 'ton-core';
33
import { MultitokenDex } from '../wrappers/MultitokenDex';
44
import '@ton-community/test-utils';
55

66
describe('MultitokenDex', () => {
77
let blockchain: Blockchain;
88
let multitokenDex: SandboxContract<MultitokenDex>;
9+
const jettonMasters = [
10+
"EQAMcImLBgZHazWmradz51pI0uHZwvxMONlMQy0QwQTQInD5",
11+
"kQAbDiNBKXDn5l3AE8cx-j7zZneFITRRFM-FH-HfBJqsrTLh"
12+
].map(elem => Address.parse(elem));
913

1014
beforeEach(async () => {
1115
blockchain = await Blockchain.create();
12-
13-
multitokenDex = blockchain.openContract(await MultitokenDex.fromInit());
14-
16+
1517
const deployer = await blockchain.treasury('deployer');
1618

17-
const deployResult = await multitokenDex.send(
18-
deployer.getSender(),
19-
{
20-
value: toNano('0.05'),
21-
},
22-
{
23-
$$type: 'Deploy',
24-
queryId: 0n,
25-
}
26-
);
19+
multitokenDex = blockchain.openContract(
20+
await MultitokenDex.fromInit(1n, deployer.address, BigInt(jettonMasters.length)));
2721

22+
const deployResult = await multitokenDex.send(deployer.getSender(),
23+
{ value: toNano('0.05'), },
24+
{ $$type: 'Deploy', queryId: 0n, });
2825
expect(deployResult.transactions).toHaveTransaction({
2926
from: deployer.address,
3027
to: multitokenDex.address,
@@ -33,8 +30,39 @@ describe('MultitokenDex', () => {
3330
});
3431
});
3532

36-
it('should deploy', async () => {
37-
// the check is done inside beforeEach
38-
// blockchain and multitokenDex are ready to use
33+
it('should initialize', async () => {
34+
// owner
35+
const deployer = await blockchain.treasury('deployer');
36+
37+
// args to get_wallet_address get-method
38+
let tuple = new TupleBuilder(); tuple.writeAddress(multitokenDex.address);
39+
let dict: Dictionary<Address, Address> = Dictionary.empty();
40+
41+
// filling jetton wallets list
42+
for (let item of jettonMasters) {
43+
let get_result = blockchain.provider(item).get("get_wallet_address", tuple.build());
44+
dict.set(item, get_result.stack.readAddress());
45+
}
46+
47+
const initResult = await multitokenDex.send(deployer.getSender(),
48+
{ value: toNano('0.2'), bounce: false, },
49+
{ $$type: 'DexDeploy', query_id: 12n, jetton_wallets: dict, });
50+
expect(initResult.transactions).toHaveTransaction({
51+
from: deployer.address,
52+
to: multitokenDex.address,
53+
deploy: false,
54+
success: true
55+
});
56+
});
57+
58+
it('should report zero balances', async () => {
59+
const swapBase = await multitokenDex.getGetSwapBase();
60+
expect(swapBase).toStrictEqual(0n);
61+
});
62+
63+
it('should offer zero swap until funded', async () => {
64+
const offeredJettons = await multitokenDex.getCalcSwapByMasterAddrs(
65+
jettonMasters[0], jettonMasters[1], 1000000n);
66+
expect(offeredJettons).toStrictEqual(0n);
3967
});
4068
});

0 commit comments

Comments
 (0)