diff --git a/Cargo.lock b/Cargo.lock index 577249c5a16..5836f54d7b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5024,7 +5024,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "token-history-contract" -version = "1.6.2" +version = "1.8.0" dependencies = [ "platform-value", "platform-version", diff --git a/packages/search-contract/Cargo.toml b/packages/search-contract/Cargo.toml index 3625f97a47e..224c3542b75 100644 --- a/packages/search-contract/Cargo.toml +++ b/packages/search-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "token-history-contract" -description = "Token history data contract schema and tools" -version = "1.6.2" +name = "search-contract" +description = "Search data contract schema and tools. Search contract is using to find other contracts and tokens" +version = "1.8.0" edition = "2021" rust-version.workspace = true license = "MIT" diff --git a/packages/token-history-contract/Cargo.toml b/packages/token-history-contract/Cargo.toml index 3625f97a47e..6168fe0c924 100644 --- a/packages/token-history-contract/Cargo.toml +++ b/packages/token-history-contract/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "token-history-contract" description = "Token history data contract schema and tools" -version = "1.6.2" +version = "1.8.0" edition = "2021" rust-version.workspace = true license = "MIT" diff --git a/packages/token-history-contract/test/unit/tokenHistoryContract.spec.js b/packages/token-history-contract/test/unit/tokenHistoryContract.spec.js index 3900303dd1d..126bf84fa5a 100644 --- a/packages/token-history-contract/test/unit/tokenHistoryContract.spec.js +++ b/packages/token-history-contract/test/unit/tokenHistoryContract.spec.js @@ -9,16 +9,10 @@ const tokenHistoryContractDocumentsSchema = require('../../schema/v1/token-histo const expectJsonSchemaError = (validationResult, errorCount = 1) => { const errors = validationResult.getErrors(); - expect(errors) - .to - .have - .length(errorCount); + expect(errors).to.have.length(errorCount); const error = validationResult.getErrors()[0]; - expect(error) - .to - .be - .instanceof(JsonSchemaError); + expect(error).to.be.instanceof(JsonSchemaError); return error; }; @@ -31,14 +25,21 @@ describe('Token History Contract', () => { beforeEach(async () => { dpp = new DashPlatformProtocol({ generate: () => crypto.randomBytes(32) }); identityId = await generateRandomIdentifier(); - dataContract = dpp.dataContract.create(identityId, BigInt(1), tokenHistoryContractDocumentsSchema); + dataContract = dpp.dataContract.create( + identityId, + BigInt(1), + tokenHistoryContractDocumentsSchema, + ); }); it('should have a valid contract definition', async () => { - expect(() => dpp.dataContract.create(identityId, BigInt(1), tokenHistoryContractDocumentsSchema)) - .to - .not - .throw(); + const createContract = () => dpp.dataContract.create( + identityId, + BigInt(1), + tokenHistoryContractDocumentsSchema, + ); + + expect(createContract).to.not.throw(); }); describe('documents', () => { @@ -50,8 +51,6 @@ describe('Token History Contract', () => { tokenId: crypto.randomBytes(32), amount: 100, note: 'Burning tokens', - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 42, }; }); @@ -64,15 +63,6 @@ describe('Token History Contract', () => { expect(error.keyword).to.equal('required'); expect(error.params.missingProperty).to.equal('tokenId'); }); - - it('should be 32 bytes', async () => { - rawBurnDocument.tokenId = crypto.randomBytes(31); - const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument); - const validationResult = document.validate(dpp.protocolVersion); - const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('minItems'); - expect(error.instancePath).to.equal('/tokenId'); - }); }); describe('amount', () => { @@ -94,24 +84,16 @@ describe('Token History Contract', () => { }); }); - describe('$createdAt / $createdAtBlockHeight', () => { - it('should be defined', async () => { - delete rawBurnDocument.$createdAt; - const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument); - const validationResult = document.validate(dpp.protocolVersion); - const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('required'); - expect(error.params.missingProperty).to.equal('$createdAt'); - }); - }); - it('should not have additional properties', async () => { rawBurnDocument.extraProp = 123; const document = dpp.document.create(dataContract, identityId, 'burn', rawBurnDocument); const validationResult = document.validate(dpp.protocolVersion); const error = expectJsonSchemaError(validationResult); + expect(error.keyword).to.equal('additionalProperties'); - expect(error.params.additionalProperties).to.deep.equal(['extraProp']); + expect(error.params.additionalProperties).to.deep.equal([ + 'extraProp', + ]); }); it('should be valid', async () => { @@ -130,19 +112,17 @@ describe('Token History Contract', () => { recipientId: crypto.randomBytes(32), amount: 1000, note: 'Minting tokens', - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 50, }; }); describe('tokenId', () => { - it('should be 32 bytes', async () => { - rawMintDocument.tokenId = crypto.randomBytes(31); + it('should be defined', async () => { + delete rawMintDocument.tokenId; const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument); const validationResult = document.validate(dpp.protocolVersion); const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('minItems'); - expect(error.instancePath).to.equal('/tokenId'); + expect(error.keyword).to.equal('required'); + expect(error.params.missingProperty).to.equal('tokenId'); }); }); @@ -155,15 +135,6 @@ describe('Token History Contract', () => { expect(error.keyword).to.equal('required'); expect(error.params.missingProperty).to.equal('recipientId'); }); - - it('should be 32 bytes', async () => { - rawMintDocument.recipientId = crypto.randomBytes(31); - const document = dpp.document.create(dataContract, identityId, 'mint', rawMintDocument); - const validationResult = document.validate(dpp.protocolVersion); - const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('minItems'); - expect(error.instancePath).to.equal('/recipientId'); - }); }); describe('amount', () => { @@ -207,19 +178,17 @@ describe('Token History Contract', () => { recipientKeyIndex: 1, rootEncryptionKeyIndex: 2, derivationEncryptionKeyIndex: 3, - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 100, }; }); describe('tokenId', () => { - it('should be 32 bytes', async () => { - rawTransferDocument.tokenId = crypto.randomBytes(31); + it('should be defined', async () => { + delete rawTransferDocument.tokenId; const document = dpp.document.create(dataContract, identityId, 'transfer', rawTransferDocument); const validationResult = document.validate(dpp.protocolVersion); const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('minItems'); - expect(error.instancePath).to.equal('/tokenId'); + expect(error.keyword).to.equal('required'); + expect(error.params.missingProperty).to.equal('tokenId'); }); }); @@ -267,8 +236,6 @@ describe('Token History Contract', () => { rawFreezeDocument = { tokenId: crypto.randomBytes(32), frozenIdentityId: crypto.randomBytes(32), - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 123, }; }); @@ -284,13 +251,13 @@ describe('Token History Contract', () => { }); describe('frozenIdentityId', () => { - it('should be 32 bytes', async () => { - rawFreezeDocument.frozenIdentityId = crypto.randomBytes(31); + it('should be defined', async () => { + delete rawFreezeDocument.frozenIdentityId; const document = dpp.document.create(dataContract, identityId, 'freeze', rawFreezeDocument); const validationResult = document.validate(dpp.protocolVersion); const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('minItems'); - expect(error.instancePath).to.equal('/frozenIdentityId'); + expect(error.keyword).to.equal('required'); + expect(error.params.missingProperty).to.equal('frozenIdentityId'); }); }); @@ -317,8 +284,6 @@ describe('Token History Contract', () => { rawUnfreezeDocument = { tokenId: crypto.randomBytes(32), frozenIdentityId: crypto.randomBytes(32), - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 150, }; }); @@ -356,26 +321,24 @@ describe('Token History Contract', () => { rawDestroyFrozenFundsDocument = { tokenId: crypto.randomBytes(32), frozenIdentityId: crypto.randomBytes(32), - amount: 500, - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 222, + destroyedAmount: 500, }; }); describe('frozenIdentityId', () => { - it('should be 32 bytes', async () => { - rawDestroyFrozenFundsDocument.frozenIdentityId = crypto.randomBytes(31); + it('should be defined', async () => { + delete rawDestroyFrozenFundsDocument.frozenIdentityId; const document = dpp.document.create(dataContract, identityId, 'destroyFrozenFunds', rawDestroyFrozenFundsDocument); const validationResult = document.validate(dpp.protocolVersion); const error = expectJsonSchemaError(validationResult); - expect(error.keyword).to.equal('minItems'); - expect(error.instancePath).to.equal('/frozenIdentityId'); + expect(error.keyword).to.equal('required'); + expect(error.params.missingProperty).to.equal('frozenIdentityId'); }); }); - describe('amount', () => { + describe('destroyedAmount', () => { it('should be non-negative', async () => { - rawDestroyFrozenFundsDocument.amount = -1; + rawDestroyFrozenFundsDocument.destroyedAmount = -1; const document = dpp.document.create(dataContract, identityId, 'destroyFrozenFunds', rawDestroyFrozenFundsDocument); const validationResult = document.validate(dpp.protocolVersion); const error = expectJsonSchemaError(validationResult); @@ -406,8 +369,6 @@ describe('Token History Contract', () => { rawEmergencyActionDocument = { tokenId: crypto.randomBytes(32), action: 1, - $createdAt: Math.ceil(Date.now() / 1000), - $createdAtBlockHeight: 300, }; }); @@ -448,4 +409,4 @@ describe('Token History Contract', () => { }); }); }); -}); \ No newline at end of file +});