From b9d4c9ce332f12daee2307c18666808020134cfb Mon Sep 17 00:00:00 2001 From: Djordje Kovacevic Date: Tue, 19 Mar 2024 12:52:06 +0100 Subject: [PATCH] Added unit test for validating metadata after cancel update is called --- contracts/v1/assets/ContentAsset.sol | 6 +++--- test/v1/unit/ContentAsset.test.ts | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/contracts/v1/assets/ContentAsset.sol b/contracts/v1/assets/ContentAsset.sol index 312cb6fa..22a5f9e5 100644 --- a/contracts/v1/assets/ContentAsset.sol +++ b/contracts/v1/assets/ContentAsset.sol @@ -238,11 +238,11 @@ contract ContentAsset is Named, Versioned, HubDependent, Initializable { uint16 currentEpoch = uint16((block.timestamp - startTime) / epochLength); bytes32 epochStateId = keccak256(abi.encodePacked(agreementId, currentEpoch, unfinalizedStateIndex)); - if (sasProxy.getCommitsCount(epochStateId) != NULL) { + if (sasProxy.getCommitsCount(epochStateId) != 0) { sasProxy.deleteCommitsCount(epochStateId); } - if (sasProxy.getV1U1AgreementEpochSubmissionHead(agreementId, currentEpoch, unfinalizedStateIndex) != NULL) { - sasProxy.setV1U1AgreementEpochSubmissionHead(agreementId, currentEpoch, unfinalizedStateIndex, NULL); + if (sasProxy.getV1U1AgreementEpochSubmissionHead(agreementId, currentEpoch, unfinalizedStateIndex) != 0) { + sasProxy.setV1U1AgreementEpochSubmissionHead(agreementId, currentEpoch, unfinalizedStateIndex, 0); } emit AssetStateUpdated(contentAssetStorageAddress, tokenId, unfinalizedStateIndex, updateTokenAmount); diff --git a/test/v1/unit/ContentAsset.test.ts b/test/v1/unit/ContentAsset.test.ts index cbd04e26..879f15a5 100644 --- a/test/v1/unit/ContentAsset.test.ts +++ b/test/v1/unit/ContentAsset.test.ts @@ -313,11 +313,34 @@ describe('@v1 @unit ContentAsset contract', function () { it('Cancel asset state update after failed update commit phase, expect previous state to be active', async () => { const tokenId = await createAsset(); await updateAsset(tokenId); + + const keyword = hre.ethers.utils.solidityPack( + ['address', 'bytes32'], + [ContentAssetStorage.address, assetInputStruct.assertionId], + ); + + const agreementId = hre.ethers.utils.soliditySha256( + ['address', 'uint256', 'bytes'], + [ContentAssetStorage.address, tokenId, keyword], + ); + const epochStateId = hre.ethers.utils.solidityKeccak256(['bytes32', 'uint16', 'uint256'], [agreementId, 0, 1]); + const ServiceAgreementStorageProxy = await hre.ethers.getContract( + 'ServiceAgreementStorageProxy', + ); + + await ServiceAgreementStorageProxy.incrementCommitsCount(epochStateId); + await time.increase(await ParametersStorage.updateCommitWindowDuration()); await expect(ContentAsset.cancelAssetStateUpdate(tokenId)) .to.emit(ContentAsset, 'AssetStateUpdateCanceled') .withArgs(ContentAssetStorage.address, tokenId, 1, assetUpdateArgs.tokenAmount); + const commitCount = await ServiceAgreementStorageProxy.getCommitsCount(epochStateId); + const stateId = hre.ethers.utils.soliditySha256(['bytes32', 'uint256'], [agreementId, 1]); + const updateCommitDeadline = await ServiceAgreementStorageProxy.getUpdateCommitsDeadline(stateId); + + await expect(commitCount).to.be.equal(0); + await expect(updateCommitDeadline.toNumber()).to.be.equal(0); }); it('Cancel asset state update using non-owner account, expect to be reverted', async () => {