-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNftCollection.spec.ts
More file actions
137 lines (122 loc) · 5.63 KB
/
Copy pathNftCollection.spec.ts
File metadata and controls
137 lines (122 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { Blockchain, SandboxContract, TreasuryContract } from '@ton/sandbox';
import { Address, Cell, toNano } from '@ton/core';
import { NftCollection } from '../wrappers/NftCollection';
import { buildCollectionContentCell, setItemContentCell } from '../scripts/nftContent/onChain';
import '@ton/test-utils';
import { compile } from '@ton/blueprint';
import { flattenTransaction } from '@ton/test-utils';
import * as dotenv from 'dotenv';
dotenv.config();
describe('NftCollection', () => {
let collectionCode: Cell;
let item: Cell;
let collectionContent: Cell;
let nftItemContent: Cell;
beforeAll(async () => {
collectionCode = await compile('NftCollection');
item = await compile('NftItem');
});
let blockchain: Blockchain;
let nftCollection: SandboxContract<NftCollection>;
let collectionOwner: SandboxContract<TreasuryContract>;
beforeEach(async () => {
blockchain = await Blockchain.create();
collectionOwner = await blockchain.treasury("ownerWallet");
collectionContent = buildCollectionContentCell({
name: process.env.COLLECTION_NAME!,
description: process.env.COLLECTION_DESCRIPTION!,
image: process.env.COLLECTION_IMAGE!
});
nftItemContent = setItemContentCell({
name: "OnChain",
description: "Holds onchain metadata",
image: "https://raw.githubusercontent.com/Cosmodude/Nexton/main/Nexton_Logo.jpg",
});
nftCollection = blockchain.openContract(NftCollection.createFromConfig({
ownerAddress: collectionOwner.address,
nextItemIndex: 0,
collectionContent: collectionContent,
nftItemCode: item,
royaltyParams: {
royaltyFactor: parseInt(process.env.COLLECTION_ROYALTY_PERCENT!), //Math.floor(Math.random() * 500),
royaltyBase: 100, //1000,
royaltyAddress: collectionOwner.getSender().address as Address
}
},collectionCode));
const deployer = await blockchain.treasury('deployer');
const deployResult = await nftCollection.sendDeploy(deployer.getSender(), toNano('0.05'));
expect(deployResult.transactions).toHaveTransaction({
from: deployer.address,
to: nftCollection.address,
deploy: true,
success: true,
});
});
it('should get collection data after collection has been deployed', async () => {
const collection_data = await nftCollection.getCollectionData();
// check next_item_index
expect(collection_data).toHaveProperty("nextItemId", BigInt(0));
// check collection content
expect(collection_data.collectionContent).toEqualCell(collectionContent);
// check owner address
expect(collection_data.ownerAddress.toString()).toBe(collectionOwner.address.toString());
});
it('should get roylty params after collection has been deployed', async () => {
const royalty_params = await nftCollection.getRoyaltyParams();
expect(royalty_params.royaltyFactor).toBe(BigInt(parseInt(process.env.COLLECTION_ROYALTY_PERCENT!)));
expect(royalty_params.royaltyBase).toBe(BigInt(100));
expect(royalty_params.royaltyAddress.toString()).toBe(collectionOwner.address.toString());
});
it ('should mint NFT item if requested by collection owner', async () => {
const nftOwner = await blockchain.treasury('NewNFTOwner');
const mintResult = await nftCollection.sendMintNft(collectionOwner.getSender(), {
value: toNano("0.02"),
queryId: Math.floor(Math.random() * 10000),
amount: toNano("0.014"),
itemIndex: 0,
itemOwnerAddress: nftOwner.getSender().address!!,
itemContent: nftItemContent
});
// const arr = mintResult.transactions.map(tx => flattenTransaction(tx));
// console.log(arr);
// check that tx to the collection address is successful
expect(mintResult.transactions).toHaveTransaction({
to: nftCollection.address,
op: 1,
value: toNano("0.02"),
success: true
})
// check that getItemAddressByIndex() returns nft item address
const nftItemAddr = await nftCollection.getItemAddressByIndex({ type: 'int', value: BigInt(0) });
// check that tx to the nft item address is successful
expect(mintResult.transactions).toHaveTransaction({
from: nftCollection.address,
to: nftItemAddr,
value: toNano("0.014"),
success: true
})
// check that next item index has been incremented
const collection_data = await nftCollection.getCollectionData();
expect(collection_data.nextItemId).toBe(BigInt(1));
});
it ('should return 401 error if mint item was requested by non-owner', async () => {
const nonOwnerWallet = await blockchain.treasury("non-owner");
const nftOwner = await blockchain.treasury('NewNFTOwner');
const result = await nftCollection.sendMintNft(nonOwnerWallet.getSender(), {
value: toNano("0.02"),
queryId: Math.floor(Math.random() * 10000),
amount: toNano("0.014"),
itemIndex: 0,
itemOwnerAddress: nftOwner.getSender().address!!,
itemContent: nftItemContent
});
// check that tx failed with 401 exit code
expect(result.transactions).toHaveTransaction({
to: nftCollection.address,
value: toNano("0.02"),
exitCode: 401,
op: 1,
success: false
});
})
});