git.delta.rocks / unique-network / refs/commits / 474b3ae27ec2

difftreelog

Confirm sponsorship tests in progress

Greg Zaitsev2020-12-23parent: #96967bb.patch.diff
in: master

4 files changed

addedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/createMultipleItems.test.tsdiffbeforeafterboth
1111
12const idCollection = 12;12const idCollection = 12;
1313
14describe('integration test: ext. createMultipleItems():', () => {14describe.skip('integration test: ext. createMultipleItems():', () => {
15 it('Create two NFT tokens in active NFT collection', async () => {15 it('Create two NFT tokens in active NFT collection', async () => {
16 await usingApi(async (api) => {16 await usingApi(async (api) => {
17 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);17 const AitemListIndex = await api.query.nft.itemListIndex(idCollection);
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
61 });61 });
62 });62 });
6363
64 it('(!negative test!) Add sponsor with a non-owner', async () => {
65 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
66 await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');
67 });
64 it('(!negative test!) Add sponsor to a collection that never existed', async () => {68 it('(!negative test!) Add sponsor to a collection that never existed', async () => {
65 // Find the collection that never existed69 // Find the collection that never existed
66 const collectionId = 0;70 const collectionId = 0;
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
134 return success;134 return success;
135}135}
136
137export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
138 await usingApi(async (api) => {
139
140 // Run the transaction
141 const alicePrivateKey = privateKey('//Alice');
142 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
143 const events = await submitTransactionAsync(alicePrivateKey, tx);
144 const result = getGenericResult(events);
145
146 // Get the collection
147 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
148
149 // What to expect
150 expect(result.success).to.be.true;
151 expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());
152 expect(collection.SponsorConfirmed).to.be.false;
153 });
154}
155136
156export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {137export async function destroyCollectionExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
157 await usingApi(async (api) => {138 await usingApi(async (api) => {
184 });165 });
185}166}
167
168export async function setCollectionSponsorExpectSuccess(collectionId: number, sponsor: string) {
169 await usingApi(async (api) => {
170
171 // Run the transaction
172 const alicePrivateKey = privateKey('//Alice');
173 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
174 const events = await submitTransactionAsync(alicePrivateKey, tx);
175 const result = getGenericResult(events);
176
177 // Get the collection
178 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
179
180 // What to expect
181 expect(result.success).to.be.true;
182 expect(collection.Sponsor.toString()).to.be.equal(sponsor.toString());
183 expect(collection.SponsorConfirmed).to.be.false;
184 });
185}
186186
187export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string) {187export async function setCollectionSponsorExpectFailure(collectionId: number, sponsor: string, senderSeed: string = '//Alice') {
188 await usingApi(async (api) => {188 await usingApi(async (api) => {
189189
190 // Run the transaction190 // Run the transaction
191 const alicePrivateKey = privateKey('//Alice');191 const alicePrivateKey = privateKey(senderSeed);
192 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);192 const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor);
193 const events = await submitTransactionAsync(alicePrivateKey, tx);193 const events = await submitTransactionAsync(alicePrivateKey, tx);
194 const result = getGenericResult(events);194 const result = getGenericResult(events);
198 });198 });
199}199}
200
201export async function confirmSponsorshipExpectSuccess(collectionId: number, senderSeed: string = '//Alice') {
202 await usingApi(async (api) => {
203
204 // Run the transaction
205 const sender = privateKey(senderSeed);
206 const tx = api.tx.nft.confirmSponsorship(collectionId);
207 const events = await submitTransactionAsync(sender, tx);
208 const result = getGenericResult(events);
209
210 // Get the collection
211 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
212
213 // What to expect
214 expect(result.success).to.be.true;
215 expect(collection.Sponsor).to.be.equal(sender.address);
216 expect(collection.SponsorConfirmed).to.be.true;
217 });
218}
219
220export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
221 await usingApi(async (api) => {
222
223 // Run the transaction
224 const sender = privateKey(senderSeed);
225 const tx = api.tx.nft.confirmSponsorship(collectionId);
226 const events = await submitTransactionAsync(sender, tx);
227 const result = getGenericResult(events);
228
229 // What to expect
230 expect(result.success).to.be.false;
231 });
232}
200233
234