From fe21accc75ebd15fc70f02a6c3fb4f38c251b0f9 Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Tue, 06 Dec 2022 12:07:24 +0000 Subject: [PATCH] Add setCollectionProperties negative test --- --- a/tests/src/eth/collectionProperties.test.ts +++ b/tests/src/eth/collectionProperties.test.ts @@ -32,7 +32,8 @@ }); // Soft-deprecated: setCollectionProperty - [{method: 'setCollectionProperties', methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]}, + [ + {method: 'setCollectionProperties', methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]}, {method: 'setCollectionProperty', methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]}, ].map(testCase => itEth(`Collection properties can be set: ${testCase.method}`, async({helper}) => { @@ -49,9 +50,26 @@ expect(raw.properties).to.deep.equal(testCase.expectedProps); })); + itEth('Cannot set invalid properties', async({helper}) => { + const caller = await helper.eth.createAccountWithBalance(donor); + const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []}); + await collection.addAdmin(alice, {Ethereum: caller}); + + const address = helper.ethAddress.fromCollectionId(collection.collectionId); + const contract = helper.ethNativeContract.collection(address, 'nft', caller); + + await expect(contract.methods.setCollectionProperties([{key: '', value: Buffer.from('val1')}]).send({from: caller})).to.be.rejected; + await expect(contract.methods.setCollectionProperties([{key: 'déjà vu', value: Buffer.from('hmm...')}]).send({from: caller})).to.be.rejected; + await expect(contract.methods.setCollectionProperties([{key: 'a'.repeat(257), value: Buffer.from('val3')}]).send({from: caller})).to.be.rejected; + // TODO add more expects + const raw = (await collection.getData())?.raw; + expect(raw.properties).to.deep.equal([]); + }); + // Soft-deprecated: deleteCollectionProperty - [{method: 'deleteCollectionProperties', methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]}, + [ + {method: 'deleteCollectionProperties', methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]}, {method: 'deleteCollectionProperty', methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]}, ].map(testCase => itEth(`Collection properties can be deleted: ${testCase.method}`, async({helper}) => { @@ -74,6 +92,8 @@ expect(raw.properties.length).to.equal(testCase.expectedProps.length); expect(raw.properties).to.deep.equal(testCase.expectedProps); })); + + // TODO cannot delete non-existing props and props of non-owned collections itEth('Can be read', async({helper}) => { const caller = helper.eth.createAccount(); -- gitstuff