Skip to content

Commit

Permalink
Update Collection added (#344)
Browse files Browse the repository at this point in the history
* UpdateCollection added

* lint fix
  • Loading branch information
0xcuriousapple authored Aug 20, 2021
1 parent 708ae87 commit 3074bb7
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
54 changes: 51 additions & 3 deletions contracts/Core/AssetManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ contract AssetManager is ACL, AssetStorage, Constants {
string name
);

event CollectionUpdated(uint8 id, uint32 epoch, uint8[] updatedJobIDs, uint256 timestamp, string name);
event CollectionUpdated(
uint8 id,
uint32 epoch,
uint32 aggregationMethod,
int8 power,
uint8[] updatedJobIDs,
uint256 timestamp,
string name
);

event CollectionActivityStatus(bool active, uint8 id, uint32 epoch, uint256 timestamp);

Expand Down Expand Up @@ -172,7 +180,15 @@ contract AssetManager is ACL, AssetStorage, Constants {

collections[collectionID].jobIDExist[jobID] = true;

emit CollectionUpdated(collectionID, epoch, collections[collectionID].jobIDs, block.timestamp, collections[collectionID].name);
emit CollectionUpdated(
collectionID,
epoch,
collections[collectionID].aggregationMethod,
collections[collectionID].power,
collections[collectionID].jobIDs,
block.timestamp,
collections[collectionID].name
);
}

function removeJobFromCollection(uint8 collectionID, uint8 jobIDIndex) external onlyRole(ASSET_MODIFIER_ROLE) {
Expand All @@ -187,7 +203,39 @@ contract AssetManager is ACL, AssetStorage, Constants {
}
collections[collectionID].jobIDs.pop();

emit CollectionUpdated(collectionID, epoch, collections[collectionID].jobIDs, block.timestamp, collections[collectionID].name);
emit CollectionUpdated(
collectionID,
epoch,
collections[collectionID].aggregationMethod,
collections[collectionID].power,
collections[collectionID].jobIDs,
block.timestamp,
collections[collectionID].name
);
}

function updateCollection(
uint8 collectionID,
uint32 aggregationMethod,
int8 power
) external onlyRole(ASSET_MODIFIER_ROLE) {
require(collections[collectionID].assetType == uint8(assetTypes.Collection), "Collection ID not present");
require(collections[collectionID].active, "Collection is inactive");

uint32 epoch = parameters.getEpoch();

collections[collectionID].power = power;
collections[collectionID].aggregationMethod = aggregationMethod;

emit CollectionUpdated(
collectionID,
epoch,
collections[collectionID].aggregationMethod,
collections[collectionID].power,
collections[collectionID].jobIDs,
block.timestamp,
collections[collectionID].name
);
}

// function getResult(uint8 id) external view returns (uint32 result) {
Expand Down
30 changes: 30 additions & 0 deletions test/ACL.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,36 @@ describe('Access Control Test', async () => {
await assertRevert(assetManager.removeJobFromCollection(3, 1), expectedRevertMessage);
});

it('updateCollection() should not be accessable by anyone besides AssetModifier', async () => {
// Checking if Anyone can access it
await assertRevert(assetManager.updateCollection(3, 2, -2), expectedRevertMessage);

// Checking if BlockConfirmer can access it
await assetManager.grantRole(BLOCK_CONFIRMER_ROLE, signers[0].address);
await assertRevert(assetManager.updateCollection(3, 2, -2), expectedRevertMessage);

// Checking if StakeModifier can access it
await assetManager.grantRole(STAKE_MODIFIER_ROLE, signers[0].address);
await assertRevert(assetManager.updateCollection(3, 2, -2), expectedRevertMessage);

// Checking if StakerActivityUpdater can access it
await assetManager.grantRole(STAKER_ACTIVITY_UPDATER_ROLE, signers[0].address);
await assertRevert(assetManager.updateCollection(3, 2, -2), expectedRevertMessage);
});

it('updateCollection() should be accessable by only AssetModifier', async () => {
const assetModifierHash = ASSET_MODIFIER_ROLE;
await assetManager.grantRole(assetModifierHash, signers[0].address);

await assetManager.createJob(true, 0, 'http://testurl.com/1', 'selector/1', 'test1');
await assetManager.createJob(true, 0, 'http://testurl.com/2', 'selector/2', 'test2');
await assetManager.createCollection([1, 2], 1, 0, 'test');

await assetManager.updateCollection(3, 2, -2);
await assetManager.revokeRole(assetModifierHash, signers[0].address);
await assertRevert(assetManager.updateCollection(3, 2, -2), expectedRevertMessage);
});

it('Only Default Admin should able to update Block Reward', async () => {
await assertRevert(parameters.connect(signers[1]).setBlockReward(5500), expectedRevertMessage);
assert(await parameters.setBlockReward(5500), 'Admin not able to update BlockReward');
Expand Down
7 changes: 7 additions & 0 deletions test/AssetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ describe('AssetManager', function () {
assertBNEqual(collection.jobIDs[2], toBigNumber('4'));
});

it('should be able to update collection', async function () {
await assetManager.updateCollection(3, 2, 5);
const collection = await assetManager.getCollection(3);
assertBNEqual(collection.power, toBigNumber('5'));
assertBNEqual(collection.aggregationMethod, toBigNumber('2'));
});

it('should return the correct asset type when getAssetType is called', async function () {
const numAssets = await assetManager.getNumAssets();
for (let i = 1; i <= numAssets; i++) {
Expand Down

0 comments on commit 3074bb7

Please sign in to comment.