Skip to content

Commit

Permalink
Added unit test for validating metadata after cancel update is called
Browse files Browse the repository at this point in the history
  • Loading branch information
djordjekovac committed Mar 19, 2024
1 parent 14e62a5 commit b9d4c9c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contracts/v1/assets/ContentAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions test/v1/unit/ContentAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
'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 () => {
Expand Down

0 comments on commit b9d4c9c

Please sign in to comment.