From a6e751ba2783f31e58413454b0e717bcbfef2009 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 7 Oct 2023 23:40:25 +0500 Subject: [PATCH] Added some tests and added them into CI --- .github/workflows/output.yaml | 2 ++ scripts/deployMultitokenDex.ts | 15 ++++---- tests/MultitokenDex.spec.ts | 62 ++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/.github/workflows/output.yaml b/.github/workflows/output.yaml index 63707e7..4ffab70 100644 --- a/.github/workflows/output.yaml +++ b/.github/workflows/output.yaml @@ -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 diff --git a/scripts/deployMultitokenDex.ts b/scripts/deployMultitokenDex.ts index ce2e873..c23ce81 100644 --- a/scripts/deployMultitokenDex.ts +++ b/scripts/deployMultitokenDex.ts @@ -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` } diff --git a/tests/MultitokenDex.spec.ts b/tests/MultitokenDex.spec.ts index 4cb6961..5370be4 100644 --- a/tests/MultitokenDex.spec.ts +++ b/tests/MultitokenDex.spec.ts @@ -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; + 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, @@ -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 = 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); }); });