Skip to content

Commit

Permalink
Create tests specifically for the account
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Nov 14, 2023
1 parent ac319b0 commit 4bfeee9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
66 changes: 66 additions & 0 deletions contracts/tests/DSocialNetworkAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Blockchain, SandboxContract } from '@ton-community/sandbox'
import { toNano } from 'ton-core'
import { DSocialNetworkMaster } from '../wrappers/DSocialNetworkMaster'
import { DSocialNetworkAccount } from '../wrappers/DSocialNetworkAccount'
import '@ton-community/test-utils'

describe('DSocialNetworkMaster', () => {
let blockchain: Blockchain
let deployer: Awaited<ReturnType<typeof blockchain.treasury>>
let dMaster: SandboxContract<DSocialNetworkMaster>
let dAccount: SandboxContract<DSocialNetworkAccount>

beforeEach(async () => {
blockchain = await Blockchain.create()
dMaster = blockchain.openContract(await DSocialNetworkMaster.fromInit())
deployer = await blockchain.treasury('deployer')
const deployResult = await dMaster.send(
deployer.getSender(),
{ value: toNano('0.05') },
{
$$type: 'Deploy',
queryId: 0n
}
)

expect(deployResult.transactions).toHaveTransaction({
from: deployer.address,
to: dMaster.address,
deploy: true,
success: true
})

const registerResult = await dMaster.send(
deployer.getSender(),
{ value: toNano('0.5') },
{
$$type: 'RegisterAccount',
query_id: 0n,
account_name: 'name',
account_description: 'Account description'
}
)

const accountAddress = await dMaster.getGetAccountAddressByIndex(0n)

expect(accountAddress).not.toBeNull()

expect(registerResult.transactions).toHaveTransaction({
from: dMaster.address,
to: accountAddress!,
success: true
})

expect(await dMaster.getGetAccountsCount()).toBe(1n)

dAccount = blockchain.openContract(
DSocialNetworkAccount.fromAddress(accountAddress!)
)
})

it('deployer shoud be owner of the account', async () => {
const owner = await dAccount.getOwner()

expect(owner.toRawString()).toEqual(deployer.address.toRawString())
})
})
3 changes: 1 addition & 2 deletions contracts/tests/DSocialNetworkMaster.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ describe('DSocialNetworkMaster', () => {
$$type: 'RegisterAccount',
query_id: 0n,
account_name: 'd0rich',
account_description:
'This is my first account sadsadasdasdasdsadadasdsadsadsadsadasdasdadadasdasdsadasdsadadasdadasdasdasdasdasdasdasdasdadasdadasdadasdasdasdsadasdadadsdaddsadsadadd'
account_description: 'This is my first account'
}
)

Expand Down

0 comments on commit 4bfeee9

Please sign in to comment.