rename contentId to postId
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s Details

This commit is contained in:
Ladd Hoffman 2024-04-28 18:05:45 -05:00
parent 9702626e0e
commit fe0326bf2c
10 changed files with 49 additions and 49 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)],

View File

@ -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
);
}
}

View File

@ -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)],

View File

@ -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(

View File

@ -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);

View File

@ -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 () => {

View File

@ -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 () => {

View File

@ -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);
};