git.delta.rocks / unique-network / refs/commits / 0066f8178098

difftreelog

Missing tests added

str-mv2021-08-13parent: #a395e0a.patch.diff
in: master

6 files changed

modifiedtests/src/addToWhiteList.test.tsdiffbeforeafterboth
17 enableWhiteListExpectSuccess,17 enableWhiteListExpectSuccess,
18 normalizeAccountId,18 normalizeAccountId,
19 addCollectionAdminExpectSuccess,19 addCollectionAdminExpectSuccess,
20 addToWhiteListExpectFail,
20} from './util/helpers';21} from './util/helpers';
2122
22chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
98 });99 });
99 });100 });
101
102 it('Add to the white list by regular user', async () => {
103 const collectionId = await createCollectionExpectSuccess();
104 await addToWhiteListExpectFail(Bob, collectionId, Charlie.address);
105 });
100106
101 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {107 it('Execute the extrinsic with parameters: Collection ID and address to add to the white list', async () => {
102 const collectionId = await createCollectionExpectSuccess();108 const collectionId = await createCollectionExpectSuccess();
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
37 });37 });
38 });38 });
39
40 it('Remove collection admin by admin.', async () => {
41 await usingApi(async (api: ApiPromise) => {
42 const collectionId = await createCollectionExpectSuccess();
43 const Alice = privateKey('//Alice');
44 const Bob = privateKey('//Bob');
45 const Charlie = privateKey('//Charlie');
46 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();
47 expect(collection.Owner).to.be.deep.eq(Alice.address);
48 // first - add collection admin Bob
49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
50 await submitTransactionAsync(Alice, addAdminTx);
51
52 const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(Charlie.address));
53 await submitTransactionAsync(Alice, addAdminTx2);
54
55 const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON();
56 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(Bob.address));
57
58 // then remove bob from admins of collection
59 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(Bob.address));
60 await submitTransactionAsync(Charlie, removeAdminTx);
61
62 const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId)).toJSON;
63 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(Bob.address));
64 });
65 });
3966
40 it('Remove admin from collection that has no admins', async () => {67 it('Remove admin from collection that has no admins', async () => {
41 await usingApi(async (api: ApiPromise) => {68 await usingApi(async (api: ApiPromise) => {
modifiedtests/src/removeCollectionSponsor.test.tsdiffbeforeafterboth
112 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');112 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
113 });113 });
114
115 it('(!negative test!) Remove sponsor for a collection by regular user', async () => {
116 const collectionId = await createCollectionExpectSuccess();
117 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
118 await removeCollectionSponsorExpectFailure(collectionId, '//Bob');
119 });
114120
115 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {121 it('(!negative test!) Remove sponsor in a destroyed collection', async () => {
116 const collectionId = await createCollectionExpectSuccess();122 const collectionId = await createCollectionExpectSuccess();
modifiedtests/src/removeFromWhiteList.test.tsdiffbeforeafterboth
125 });125 });
126 });126 });
127
128 it('Regular user can`t remove from whitelist', async () => {
129 await usingApi(async () => {
130 const collectionWithoutWhitelistId = await createCollectionExpectSuccess();
131 await enableWhiteListExpectSuccess(alice, collectionWithoutWhitelistId);
132 await addToWhiteListExpectSuccess(alice, collectionWithoutWhitelistId, charlie.address);
133 await removeFromWhiteListExpectFailure(bob, collectionWithoutWhitelistId, normalizeAccountId(charlie.address));
134 });
135 });
127});136});
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
2424
25let alice: IKeyringPair;25let alice: IKeyringPair;
26let bob: IKeyringPair;26let bob: IKeyringPair;
27let charlie: IKeyringPair;
27let collectionIdForTesting: number;28let collectionIdForTesting: number;
2829
29/*30/*
111 });112 });
112});113});
113114
114describe('setSchemaVersion negative', () => {115describe.only('setSchemaVersion negative', () => {
115 let tx;116 let tx;
116 before(async () => {117 before(async () => {
117 await usingApi(async () => {118 await usingApi(async () => {
118 const keyring = new Keyring({ type: 'sr25519' });119 const keyring = new Keyring({ type: 'sr25519' });
119 alice = keyring.addFromUri('//Alice');120 alice = keyring.addFromUri('//Alice');
121 charlie = keyring.addFromUri('//Charlie');
120 });122 });
121 });123 });
122 it('execute setSchemaVersion for not exists collection', async () => {124 it('execute setSchemaVersion for not exists collection', async () => {
151 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;151 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
152 });152 });
153 });153 });
154 it('Regular user can`t execute setSchemaVersion with image url and unique ', async () => {
155 await usingApi(async (api: ApiPromise) => {
156 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');
157 await expect(submitTransactionAsync(charlie, tx)).to.be.rejected;
158 });
159 });
154});160});
155161
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
1088 });1088 });
1089}1089}
1090
1091export async function addToWhiteListExpectFail(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
1092 await usingApi(async (api) => {
1093 // Run the transaction
1094 const tx = api.tx.nft.addToWhiteList(collectionId, normalizeAccountId(address));
1095 const events = await expect(submitTransactionAsync(sender, tx)).to.be.rejected;
1096 const result = getGenericResult(events);
1097
1098 // What to expect
1099 // tslint:disable-next-line:no-unused-expression
1100 expect(result.success).to.be.false;
1101 });
1102}
10901103
1091export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {1104export async function removeFromWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: CrossAccountId) {
1092 await usingApi(async (api) => {1105 await usingApi(async (api) => {