Skip to content

Commit

Permalink
Added some tests and added them into CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgramCrafter committed Oct 7, 2023
1 parent feeeadb commit a6e751b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
run: yarn install
- name: Build project
run: yarn blueprint build
- name: Run tests
run: yarn blueprint test
- name: create zip file from build folder
run: zip -r -q build.zip build
- name: Set outputs
Expand Down
15 changes: 9 additions & 6 deletions scripts/deployMultitokenDex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { NetworkProvider } from '@ton-community/blueprint';
import { inspect } from 'util';

export async function run(provider: NetworkProvider) {
const multitokenDex = provider.open(await MultitokenDex.fromInit(BigInt(1), provider.sender().address!));


await sendDeploy(multitokenDex, provider, ["EQAMcImLBgZHazWmradz51pI0uHZwvxMONlMQy0QwQTQInD5", "kQAbDiNBKXDn5l3AE8cx-j7zZneFITRRFM-FH-HfBJqsrTLh"].map(elem => Address.parse(elem)))

const jettonMasters = [
"EQAMcImLBgZHazWmradz51pI0uHZwvxMONlMQy0QwQTQInD5",
"kQAbDiNBKXDn5l3AE8cx-j7zZneFITRRFM-FH-HfBJqsrTLh"
].map(elem => Address.parse(elem));
const multitokenDex = provider.open(
await MultitokenDex.fromInit(BigInt(1), provider.sender().address!, BigInt(jettonMasters.length))
);

await sendDeploy(multitokenDex, provider, jettonMasters)
await provider.waitForDeploy(multitokenDex.address);
// run methods on `multitokenDex`
}
62 changes: 45 additions & 17 deletions tests/MultitokenDex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import { Address, Dictionary, OpenedContract, TupleBuilder, toNano } from 'ton-core';
import { Blockchain, SandboxContract } from '@ton-community/sandbox';
import { toNano } from 'ton-core';
import { MultitokenDex } from '../wrappers/MultitokenDex';
import '@ton-community/test-utils';

describe('MultitokenDex', () => {
let blockchain: Blockchain;
let multitokenDex: SandboxContract<MultitokenDex>;
const jettonMasters = [
"EQAMcImLBgZHazWmradz51pI0uHZwvxMONlMQy0QwQTQInD5",
"kQAbDiNBKXDn5l3AE8cx-j7zZneFITRRFM-FH-HfBJqsrTLh"
].map(elem => Address.parse(elem));

beforeEach(async () => {
blockchain = await Blockchain.create();

multitokenDex = blockchain.openContract(await MultitokenDex.fromInit());


const deployer = await blockchain.treasury('deployer');

const deployResult = await multitokenDex.send(
deployer.getSender(),
{
value: toNano('0.05'),
},
{
$$type: 'Deploy',
queryId: 0n,
}
);
multitokenDex = blockchain.openContract(
await MultitokenDex.fromInit(1n, deployer.address, BigInt(jettonMasters.length)));

const deployResult = await multitokenDex.send(deployer.getSender(),
{ value: toNano('0.05'), },
{ $$type: 'Deploy', queryId: 0n, });
expect(deployResult.transactions).toHaveTransaction({
from: deployer.address,
to: multitokenDex.address,
Expand All @@ -33,8 +30,39 @@ describe('MultitokenDex', () => {
});
});

it('should deploy', async () => {
// the check is done inside beforeEach
// blockchain and multitokenDex are ready to use
it('should initialize', async () => {
// owner
const deployer = await blockchain.treasury('deployer');

// args to get_wallet_address get-method
let tuple = new TupleBuilder(); tuple.writeAddress(multitokenDex.address);
let dict: Dictionary<Address, Address> = Dictionary.empty();

// filling jetton wallets list
for (let item of jettonMasters) {
let get_result = blockchain.provider(item).get("get_wallet_address", tuple.build());
dict.set(item, get_result.stack.readAddress());
}

const initResult = await multitokenDex.send(deployer.getSender(),
{ value: toNano('0.2'), bounce: false, },
{ $$type: 'DexDeploy', query_id: 12n, jetton_wallets: dict, });
expect(initResult.transactions).toHaveTransaction({
from: deployer.address,
to: multitokenDex.address,
deploy: false,
success: true
});
});

it('should report zero balances', async () => {
const swapBase = await multitokenDex.getGetSwapBase();
expect(swapBase).toStrictEqual(0n);
});

it('should offer zero swap until funded', async () => {
const offeredJettons = await multitokenDex.getCalcSwapByMasterAddrs(
jettonMasters[0], jettonMasters[1], 1000000n);
expect(offeredJettons).toStrictEqual(0n);
});
});

0 comments on commit a6e751b

Please sign in to comment.