Skip to content

Commit

Permalink
Create post
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Nov 14, 2023
1 parent c44108d commit 502dc25
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
4 changes: 4 additions & 0 deletions contracts/contracts/d_social_network_account.tact
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ contract DSocialNetworkAccount with NftCollection, NftCollectionRoyaltyExtention
};
}

get fun get_next_item_index(): Int {
return self.next_item_index;
}

receive(msg: InitializeAccount) {
require(!self.is_initialized, "Account is already initialized");
self.requireOwner();
Expand Down
10 changes: 10 additions & 0 deletions contracts/contracts/d_social_network_post.tact
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@stdlib/deploy";
import "@stdlib/ownable";
import "./lib/trait_nft_item.tact";
import "./messages_d.tact";

contract DSocialNetworkPost with NftItem {
collection_address: Address;
Expand All @@ -24,5 +25,14 @@ contract DSocialNetworkPost with NftItem {
self.is_initialized = false;
}

get fun get_post_info(): PostInfo {
return PostInfo{
account: self.collection_address,
id: self.item_index,
owner: self.owner,
nft_content: self.individual_content
};
}


}
9 changes: 9 additions & 0 deletions contracts/contracts/messages_d.tact
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ struct AccountInfo {
collection_content: NftCollectionMetadata;
is_initialized: Bool;
}

// Post contract

struct PostInfo {
account: Address;
id: Int;
owner: Address;
nft_content: NftMetadata;
}
47 changes: 45 additions & 2 deletions contracts/tests/DSocialNetworkAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Blockchain, SandboxContract } from '@ton-community/sandbox'
import { toNano } from 'ton-core'
import { toNano, Dictionary } from 'ton-core'
import { DSocialNetworkMaster } from '../wrappers/DSocialNetworkMaster'
import { DSocialNetworkAccount } from '../wrappers/DSocialNetworkAccount'
import {
DSocialNetworkAccount,
NftMetadataAttribute
} from '../wrappers/DSocialNetworkAccount'
import '@ton-community/test-utils'
import { DSocialNetworkPost } from '../wrappers/DSocialNetworkPost'

describe('DSocialNetworkMaster', () => {
let blockchain: Blockchain
Expand Down Expand Up @@ -63,4 +67,43 @@ describe('DSocialNetworkMaster', () => {

expect(owner.toRawString()).toEqual(deployer.address.toRawString())
})

it('should create post', async () => {
const attributes = Dictionary.empty<bigint, NftMetadataAttribute>()
attributes.set(0n, {
$$type: 'NftMetadataAttribute',
trait_type: 'content',
value: 'This is my first post'
})
const registerResult = await dAccount.send(
deployer.getSender(),
{ value: toNano('0.5') },
{
$$type: 'MintNft',
query_id: 0n,
individual_content: {
$$type: 'NftMetadata',
name: 'Test post',
description: 'Test post description',
image: 'https://test.com/image.png',
content_url: 'https://test.com/content.txt',
attributes
}
}
)

const postAddress = await dAccount.getGetNftAddressByIndex(0n)

expect(postAddress).not.toBeNull()

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

expect(await dAccount.getGetNextItemIndex()).toBe(1n)

blockchain.openContract(DSocialNetworkPost.fromAddress(postAddress!))
})
})

0 comments on commit 502dc25

Please sign in to comment.