Skip to content

Commit

Permalink
Updated updateService function
Browse files Browse the repository at this point in the history
  • Loading branch information
quent043 committed Dec 1, 2023
1 parent 0de07fc commit be86269
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions contracts/TalentLayerService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ contract TalentLayerService is Initializable, ERC2771RecipientUpgradeable, UUPSU
* @notice Emit when data is updated for a Service
* @param id The service ID
* @param dataUri New service Data URI
* @param rateToken token address to be used for the service's payments
* @param referralAmount New referral amount
*/
event ServiceUpdated(uint256 id, string dataUri, uint256 referralAmount);
event ServiceUpdated(uint256 id, string dataUri, address rateToken, uint256 referralAmount);

/**
* @notice Emitted after a new proposal is created
Expand Down Expand Up @@ -353,25 +354,29 @@ contract TalentLayerService is Initializable, ERC2771RecipientUpgradeable, UUPSU
* @notice Update Service URI data
* @param _profileId The TalentLayer ID of the user, owner of the service
* @param _serviceId, Service ID to update
* @param _rateToken token address to be used for the service's payments
* @param _referralAmount, New referral amount
* @param _dataUri New IPFS URI
*/
function updateService(
uint256 _profileId,
uint256 _serviceId,
address _rateToken,
uint256 _referralAmount,
string calldata _dataUri
) public onlyOwnerOrDelegate(_profileId) {
Service storage service = services[_serviceId];
require(service.ownerId == _profileId, "Not the owner");
require(service.status == Status.Opened, "status must be opened");
require(bytes(_dataUri).length == 46, "Invalid cid");
require(allowedTokenList[_rateToken].isWhitelisted, "Token not allowed");
require(_referralAmount >= service.referralAmount, "Can't reduce referral amount");

service.dataUri = _dataUri;
service.referralAmount = _referralAmount;
service.rateToken = _rateToken;

emit ServiceUpdated(_serviceId, _dataUri, _referralAmount);
emit ServiceUpdated(_serviceId, _dataUri, _rateToken, _referralAmount);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/batch/delegationSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('Delegation System', function () {
})

it('Dave can update service data on behalf of Alice', async function () {
const tx = await talentLayerService.connect(dave).updateService(aliceTlId, serviceId, 0, cid)
const tx = await talentLayerService.connect(dave).updateService(aliceTlId, serviceId, ethers.constants.AddressZero, referralAmount, cid)
await expect(tx).to.not.be.reverted
})

Expand Down
15 changes: 10 additions & 5 deletions test/batch/fullWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ describe('TalentLayer protocol global testing', function () {
expect(service1Data.dataUri).to.be.equal(cid)
expect(service1Data.platformId).to.be.equal(1)
expect(service1Data.referralAmount).to.be.equal(0)
expect(service1Data.rateToken).to.be.equal(token.address)
expect(tx)
.to.emit(talentLayerService, 'ServiceCreated')
.withArgs(5, aliceTlId, alicePlatformId, cid, token.address, 0)
Expand Down Expand Up @@ -930,25 +931,29 @@ describe('TalentLayer protocol global testing', function () {
})

it('Alice can update her service data', async function () {
await talentLayerService.connect(alice).updateService(aliceTlId, 1, referralAmount, cid2)
await talentLayerService.connect(alice).updateService(aliceTlId, 1, ethers.constants.AddressZero, referralAmount, cid2)
const serviceData = await talentLayerService.services(1)
expect(serviceData.dataUri).to.be.equal(cid2)
expect(serviceData.rateToken).to.be.equal(ethers.constants.AddressZero)
// Revert update
await talentLayerService.connect(alice).updateService(aliceTlId, 1, token.address, referralAmount, cid2)


const newReferralAmount = 40000
const tx = await talentLayerService
.connect(alice)
.updateService(aliceTlId, 6, newReferralAmount, cid2)
.updateService(aliceTlId, 6, ethers.constants.AddressZero, newReferralAmount, cid2)
const service6Data = await talentLayerService.services(6)

expect(tx)
.to.emit(talentLayerService, 'ServiceUpdated')
.withArgs(6, cid2, newReferralAmount, ethers.constants.AddressZero)
.withArgs(6, cid2, ethers.constants.AddressZero, newReferralAmount)
expect(service6Data.referralAmount).to.be.equal(newReferralAmount)
})

it('Alice cannot update her service with an inferior referral amount', async function () {
await expect(
talentLayerService.connect(alice).updateService(aliceTlId, 1, referralAmount - 1, cid2),
talentLayerService.connect(alice).updateService(aliceTlId, 1, token.address, referralAmount - 1, cid2),
).to.be.revertedWith("Can't reduce referral amount")
})

Expand Down Expand Up @@ -1536,7 +1541,7 @@ describe('TalentLayer protocol global testing', function () {
it('Alice cannot update her service data after it is confirmed', async function () {
const tx = talentLayerService
.connect(alice)
.updateService(aliceTlId, serviceId, referralAmount, cid2)
.updateService(aliceTlId, serviceId, ethers.constants.AddressZero, referralAmount, cid2)
await expect(tx).to.be.revertedWith('status must be opened')
})

Expand Down

0 comments on commit be86269

Please sign in to comment.