git.delta.rocks / unique-network / refs/commits / d22ad5ff0f4f

difftreelog

splitted test into multiple test cases

Grigoriy Simonov2022-06-23parent: #f8da043.patch.diff
in: master

1 file changed

modifiedtests/src/refungible.test.tsdiffbeforeafterboth
47 });47 });
48 });48 });
49
50 it('Create refungible collection and token. Token pieces transfer.', async () => {
51 const createMode = 'ReFungible';
52 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
53 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
54
55 let aliceBalance = BigInt(0);
56 await usingApi(async api => {
57 aliceBalance = await getBalance(api, collectionId, alice.address, tokenId);
58 });
59 const transferAmount = BigInt(60);
60 await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible');
61 aliceBalance = aliceBalance - transferAmount;
62 await transferExpectFailure(collectionId, tokenId, alice, bob, aliceBalance + BigInt(1));
63 });
64
65 it('Create multiple tokens', async () => {
66 const createMode = 'ReFungible';
67 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
68 const args = [
69 {ReFungible: {pieces: 1}},
70 {ReFungible: {pieces: 2}},
71 {ReFungible: {pieces: 100}},
72 ];
73 await createMultipleItemsExpectSuccess(alice, collectionId, args);
74
75 let tokenId = 0;
76 await usingApi(async api => {
77 tokenId = await getLastTokenId(api, collectionId);
78 expect(tokenId).to.be.equal(3);
79 });
80
81 const transferAmount = BigInt(60);
82 await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible');
83 });
84
85 it('Burn some pieces', async () => {
86 const createMode = 'ReFungible';
87 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
88 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
89
90 let aliceBalance = BigInt(0);
91 await usingApi(async api => {
92 aliceBalance = await getBalance(api, collectionId, alice.address, tokenId);
93 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
94 });
95 await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance - BigInt(1));
96 await usingApi(async api => {
97 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
98 });
99 });
100
101 it('Burn all pieces', async () => {
102 const createMode = 'ReFungible';
103 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
104 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
105
106 let aliceBalance = BigInt(0);
107 await usingApi(async api => {
108 aliceBalance = await getBalance(api, collectionId, alice.address, tokenId);
109 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
110 });
111 await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance);
112 await usingApi(async api => {
113 expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
114 });
115 });
49116
50 it('Create refungible collection and token. Token pieces transfer. Token repartition.', async () => {117 it('Set allowance for token', async () => {
51 const createMode = 'ReFungible';118 const createMode = 'ReFungible';
52 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});119 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
53 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);120 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
54
55 const args = [
56 {ReFungible: {pieces: 1}},
57 {ReFungible: {pieces: 2}},
58 {ReFungible: {pieces: 3}},
59 ];
60 await createMultipleItemsExpectSuccess(alice, collectionId, args);
61121
62 let aliceBalance = BigInt(0);122 let aliceBalance = BigInt(0);
63 await usingApi(async api => {123 await usingApi(async api => {
64 expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
65
66 const itemsListIndexAfter = await getLastTokenId(api, collectionId);
67 expect(itemsListIndexAfter).to.be.equal(4);
68
69 aliceBalance = await getBalance(api, collectionId, alice.address, tokenId);124 aliceBalance = await getBalance(api, collectionId, alice.address, tokenId);
70 });125 });
71 const transferAmount = BigInt(60);126 const allowedAmount = BigInt(60);
72 await transferExpectSuccess(collectionId, tokenId, alice, bob, transferAmount, 'ReFungible');
73 aliceBalance = aliceBalance - transferAmount;
74 await transferExpectFailure(collectionId, tokenId, alice, bob, aliceBalance + BigInt(1));
75 await burnItemExpectSuccess(alice, collectionId, tokenId, aliceBalance - BigInt(1));
76 await approveExpectSuccess(collectionId, tokenId, bob, alice.address, transferAmount);127 await approveExpectSuccess(collectionId, tokenId, alice, bob.address, allowedAmount);
77 const bobBalance = transferAmount;
78 const allowedAmount = BigInt(60);128 const transferAmount = BigInt(20);
79 await transferFromExpectSuccess(collectionId, tokenId, alice, bob, alice, 40, 'ReFungible');129 await transferFromExpectSuccess(collectionId, tokenId, bob, alice, bob, transferAmount, 'ReFungible');
80130
81 await usingApi(async api => {131 await usingApi(async api => {
82 expect(await getAllowance(api, collectionId, bob.address, alice.address, 0)).to.equal(bobBalance - allowedAmount);132 expect(await getAllowance(api, collectionId, alice.address, bob.address, tokenId)).to.equal(allowedAmount - transferAmount);
83 });133 });
84 134
85 });135 });