From fe0326bf2c5b20500eac9160aa7673c1d81fab9c Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sun, 28 Apr 2024 18:05:45 -0500 Subject: [PATCH] rename contentId to postId --- backend/src/api/import-from-matrix.js | 2 +- backend/src/api/import-from-ss.js | 2 +- ethereum/contracts/Onboarding.sol | 8 ++-- ethereum/contracts/RollableWorkContract.sol | 4 +- ethereum/contracts/WorkContract.sol | 16 +++---- ethereum/contracts/core/Forum.sol | 12 +++--- ethereum/scripts/automatic-staking.js | 8 ++-- ethereum/test/Forum.js | 42 +++++++++---------- ethereum/test/Work1.js | 2 +- .../work-contracts/WorkRequests.jsx | 2 +- 10 files changed, 49 insertions(+), 49 deletions(-) diff --git a/backend/src/api/import-from-matrix.js b/backend/src/api/import-from-matrix.js index 90c4944..c61aeeb 100644 --- a/backend/src/api/import-from-matrix.js +++ b/backend/src/api/import-from-matrix.js @@ -16,7 +16,7 @@ const addPostWithRetry = async (authors, hash, citations, retryDelay = 5000) => console.log('retry delay (sec):', retryDelay / 1000); await Promise.delay(retryDelay); return addPostWithRetry(authors, hash, citations, retryDelay * 2); - } if (e.reason === 'A post with this contentId already exists') { + } if (e.reason === 'A post with this postId already exists') { return { alreadyAdded: true }; } throw e; diff --git a/backend/src/api/import-from-ss.js b/backend/src/api/import-from-ss.js index 31c3c88..991568b 100644 --- a/backend/src/api/import-from-ss.js +++ b/backend/src/api/import-from-ss.js @@ -124,7 +124,7 @@ const addPostWithRetry = async (authors, hash, citations, retryDelay = 5000) => console.log('retry delay (sec):', retryDelay / 1000); await Promise.delay(retryDelay); return addPostWithRetry(authors, hash, citations, retryDelay * 2); - } if (e.reason === 'A post with this contentId already exists') { + } if (e.reason === 'A post with this postId already exists') { return { alreadyAdded: true }; } throw e; diff --git a/ethereum/contracts/Onboarding.sol b/ethereum/contracts/Onboarding.sol index e961cad..5fe2e21 100644 --- a/ethereum/contracts/Onboarding.sol +++ b/ethereum/contracts/Onboarding.sol @@ -29,13 +29,13 @@ contract Onboarding is WorkContract, IOnValidate { // Make work evidence post Author[] memory authors = new Author[](1); authors[0] = Author(1000000, stake.worker); - dao.addPost(authors, request.evidenceContentId, request.citations); + dao.addPost(authors, request.evidencePostId, request.citations); emit WorkApprovalSubmitted(requestIndex, approval); // Initiate validation pool uint poolIndex = dao.initiateValidationPool{ value: request.fee - request.fee / 10 }( - request.evidenceContentId, + request.evidencePostId, POOL_DURATION, [uint256(1), uint256(3)], [uint256(1), uint256(2)], @@ -76,9 +76,9 @@ contract Onboarding is WorkContract, IOnValidate { Citation[] memory emptyCitations; Author[] memory authors = new Author[](1); authors[0] = Author(1000000, request.customer); - dao.addPost(authors, request.requestContentId, emptyCitations); + dao.addPost(authors, request.requestPostId, emptyCitations); dao.initiateValidationPool{value: request.fee / 10}( - request.requestContentId, + request.requestPostId, POOL_DURATION, [uint256(1), uint256(3)], [uint256(1), uint256(2)], diff --git a/ethereum/contracts/RollableWorkContract.sol b/ethereum/contracts/RollableWorkContract.sol index f4995e7..da797e4 100644 --- a/ethereum/contracts/RollableWorkContract.sol +++ b/ethereum/contracts/RollableWorkContract.sol @@ -34,7 +34,7 @@ abstract contract RollableWorkContract is WorkContract { // Make work evidence post Author[] memory authors = new Author[](1); authors[0] = Author(1000000, stake.worker); - dao.addPost(authors, request.evidenceContentId, request.citations); + dao.addPost(authors, request.evidencePostId, request.citations); // send worker stakes and customer fee to rollup contract dao.forwardAllowance( @@ -45,7 +45,7 @@ abstract contract RollableWorkContract is WorkContract { rollupContract.addItem{value: request.fee}( stake.worker, stake.amount, - request.evidenceContentId + request.evidencePostId ); } } diff --git a/ethereum/contracts/WorkContract.sol b/ethereum/contracts/WorkContract.sol index 55837d4..38f68f5 100644 --- a/ethereum/contracts/WorkContract.sol +++ b/ethereum/contracts/WorkContract.sol @@ -20,8 +20,8 @@ abstract contract WorkContract is Availability, IOnProposalAccepted { uint256 fee; WorkStatus status; uint stakeIndex; - string requestContentId; - string evidenceContentId; + string requestPostId; + string evidencePostId; Citation[] citations; bool approval; } @@ -56,21 +56,21 @@ abstract contract WorkContract is Availability, IOnProposalAccepted { } /// Accept work request with fee - function requestWork(string calldata requestContentId) external payable { + function requestWork(string calldata requestPostId) external payable { require(msg.value >= price, "Insufficient fee"); uint requestIndex = requestCount++; WorkRequest storage request = requests[requestIndex]; request.customer = msg.sender; request.fee = msg.value; request.stakeIndex = assignWork(); - request.requestContentId = requestContentId; + request.requestPostId = requestPostId; emit WorkAssigned(requestIndex, request.stakeIndex); } /// Accept work evidence from worker function submitWorkEvidence( uint requestIndex, - string calldata evidenceContentId, + string calldata evidencePostId, Citation[] calldata citations ) external { WorkRequest storage request = requests[requestIndex]; @@ -84,7 +84,7 @@ abstract contract WorkContract is Availability, IOnProposalAccepted { "Worker can only submit evidence for work they are assigned" ); request.status = WorkStatus.EvidenceSubmitted; - request.evidenceContentId = evidenceContentId; + request.evidencePostId = evidencePostId; for (uint i = 0; i < citations.length; i++) { request.citations.push(citations[i]); } @@ -107,11 +107,11 @@ abstract contract WorkContract is Availability, IOnProposalAccepted { // Make work evidence post Author[] memory authors = new Author[](1); authors[0] = Author(1000000, stake.worker); - dao.addPost(authors, request.evidenceContentId, request.citations); + dao.addPost(authors, request.evidencePostId, request.citations); emit WorkApprovalSubmitted(requestIndex, approval); // Initiate validation pool uint poolIndex = dao.initiateValidationPool{value: request.fee}( - request.evidenceContentId, + request.evidencePostId, POOL_DURATION, [uint256(1), uint256(3)], [uint256(1), uint256(2)], diff --git a/ethereum/contracts/core/Forum.sol b/ethereum/contracts/core/Forum.sol index 41fe854..b23a4de 100644 --- a/ethereum/contracts/core/Forum.sol +++ b/ethereum/contracts/core/Forum.sol @@ -36,19 +36,19 @@ contract Forum is Reputation { function addPost( Author[] calldata authors, - string calldata contentId, + string calldata postId, Citation[] calldata citations ) external { require(authors.length > 0, "Post must include at least one author"); postCount++; - postIds.push(contentId); - Post storage post = posts[contentId]; + postIds.push(postId); + Post storage post = posts[postId]; require( post.authors.length == 0, - "A post with this contentId already exists" + "A post with this postId already exists" ); post.sender = msg.sender; - post.id = contentId; + post.id = postId; uint authorTotalWeightPercent; for (uint i = 0; i < authors.length; i++) { authorTotalWeightPercent += authors[i].weightPPM; @@ -84,7 +84,7 @@ contract Forum is Reputation { totalCitationWeightNeg >= -1000000, "Sum of negative citations must be >= -1000000" ); - emit PostAdded(contentId); + emit PostAdded(postId); } function getPostAuthors( diff --git a/ethereum/scripts/automatic-staking.js b/ethereum/scripts/automatic-staking.js index de1da3c..07612f8 100644 --- a/ethereum/scripts/automatic-staking.js +++ b/ethereum/scripts/automatic-staking.js @@ -37,14 +37,14 @@ const fetchReputation = async () => { const fetchPost = async (postIndex) => { const { - id, sender, author, contentId, + id, sender, author, postId, } = await dao.posts(postIndex); - const { content, embeddedData } = await readFromApi(contentId); + const { content, embeddedData } = await readFromApi(postId); const post = { id, sender, author, - contentId, + postId, content, embeddedData, }; @@ -120,7 +120,7 @@ const poolIsValidWorkContract = (pool) => { case getContractAddressByNetworkName(network, 'Work1'): { // If this is a valid work evidence // TODO: Can we decode from the post, a reference to the work request? - // The work request does have its own contentId, the work contract has that + // The work request does have its own postId, the work contract has that // under availabilityStakes const expectedContent = 'This is a work evidence post'; return pool.post.content.startsWith(expectedContent); diff --git a/ethereum/test/Forum.js b/ethereum/test/Forum.js index 7dcfe35..2a5eb56 100644 --- a/ethereum/test/Forum.js +++ b/ethereum/test/Forum.js @@ -39,10 +39,10 @@ describe('Forum', () => { { value: fee ?? POOL_FEE }, ); - const addPost = (author, contentId, citations) => dao.addPost([{ + const addPost = (author, postId, citations) => dao.addPost([{ weightPPM: 1000000, authorAddress: author, - }], contentId, citations); + }], postId, citations); describe('Post', () => { beforeEach(async () => { @@ -52,39 +52,39 @@ describe('Forum', () => { }); it('should be able to add a post', async () => { - const contentId = 'some-id'; - await expect(addPost(account1, contentId, [])).to.emit(dao, 'PostAdded').withArgs('some-id'); - const post = await dao.posts(contentId); + const postId = 'some-id'; + await expect(addPost(account1, postId, [])).to.emit(dao, 'PostAdded').withArgs('some-id'); + const post = await dao.posts(postId); expect(post.sender).to.equal(account1); - expect(post.id).to.equal(contentId); - const postAuthors = await dao.getPostAuthors(contentId); + expect(post.id).to.equal(postId); + const postAuthors = await dao.getPostAuthors(postId); expect(postAuthors).to.have.length(1); expect(postAuthors[0].weightPPM).to.equal(1000000); expect(postAuthors[0].authorAddress).to.equal(account1); }); it('should be able to add a post on behalf of another account', async () => { - const contentId = 'some-id'; - await addPost(account2, contentId, []); - const post = await dao.posts(contentId); + const postId = 'some-id'; + await addPost(account2, postId, []); + const post = await dao.posts(postId); expect(post.sender).to.equal(account1); - expect(post.id).to.equal(contentId); - const postAuthors = await dao.getPostAuthors(contentId); + expect(post.id).to.equal(postId); + const postAuthors = await dao.getPostAuthors(postId); expect(postAuthors).to.have.length(1); expect(postAuthors[0].weightPPM).to.equal(1000000); expect(postAuthors[0].authorAddress).to.equal(account2); }); it('should be able to add a post with multiple authors', async () => { - const contentId = 'some-id'; + const postId = 'some-id'; await expect(dao.addPost([ { weightPPM: 500000, authorAddress: account1 }, { weightPPM: 500000, authorAddress: account2 }, - ], contentId, [])).to.emit(dao, 'PostAdded').withArgs('some-id'); - const post = await dao.posts(contentId); + ], postId, [])).to.emit(dao, 'PostAdded').withArgs('some-id'); + const post = await dao.posts(postId); expect(post.sender).to.equal(account1); - expect(post.id).to.equal(contentId); - const postAuthors = await dao.getPostAuthors(contentId); + expect(post.id).to.equal(postId); + const postAuthors = await dao.getPostAuthors(postId); expect(postAuthors).to.have.length(2); expect(postAuthors[0].weightPPM).to.equal(500000); expect(postAuthors[0].authorAddress).to.equal(account1); @@ -98,19 +98,19 @@ describe('Forum', () => { }); it('should not be able to add a post with total author weight < 100%', async () => { - const contentId = 'some-id'; + const postId = 'some-id'; await expect(dao.addPost([ { weightPPM: 500000, authorAddress: account1 }, { weightPPM: 400000, authorAddress: account2 }, - ], contentId, [])).to.be.rejectedWith('Author weights must sum to 1000000'); + ], postId, [])).to.be.rejectedWith('Author weights must sum to 1000000'); }); it('should not be able to add a post with total author weight > 100%', async () => { - const contentId = 'some-id'; + const postId = 'some-id'; await expect(dao.addPost([ { weightPPM: 500000, authorAddress: account1 }, { weightPPM: 600000, authorAddress: account2 }, - ], contentId, [])).to.be.rejectedWith('Author weights must sum to 1000000'); + ], postId, [])).to.be.rejectedWith('Author weights must sum to 1000000'); }); it('should be able to donate reputation via citations', async () => { diff --git a/ethereum/test/Work1.js b/ethereum/test/Work1.js index 4bc3fee..a2a2137 100644 --- a/ethereum/test/Work1.js +++ b/ethereum/test/Work1.js @@ -125,7 +125,7 @@ describe('Work1', () => { expect(await work1.requestCount()).to.equal(1); const request = await work1.requests(0); expect(request.customer).to.equal(account2); - expect(request.requestContentId).to.equal('req-content-id'); + expect(request.requestPostId).to.equal('req-content-id'); }); it('should not be able to request work if there are no availability stakes', async () => { diff --git a/frontend/src/components/work-contracts/WorkRequests.jsx b/frontend/src/components/work-contracts/WorkRequests.jsx index f402ecf..24a394e 100644 --- a/frontend/src/components/work-contracts/WorkRequests.jsx +++ b/frontend/src/components/work-contracts/WorkRequests.jsx @@ -123,7 +123,7 @@ function WorkRequests({ }, [workContract, account, currentRequestId]); const handleShowViewRequestModal = async (request) => { - const post = await Post.read(request.requestContentId); + const post = await Post.read(request.requestPostId); setViewRequest(post); setShowViewRequestModal(true); };