Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-carbon-offset-to-claim-and-tests #153

Merged
merged 5 commits into from
Nov 12, 2024
Merged

Conversation

sBaki92
Copy link
Contributor

@sBaki92 sBaki92 commented Nov 8, 2024

On Ainur's advice, I modified the claim function and split it into two parts: the first is confirm_for_merkle_tree, which confirms the offset on the Merkle tree side by validating the proof provided by the user; the second is confirm_offset, which handles business logic checks (e.g., ensuring the claim hasn't already been made, verifying that there is sufficient pending retirement, etc.), calls confirm_for_merkle_tree for Merkle tree checks, and performs the offset action with _offset_carbon_credit.

Consequently, the tests for the claim function in test_merkle_tree.cairo have been converted to tests for the confirm_for_merkle_tree function.

I added tests for the confirm_claim function in test_offseter.cairo.

I also added two getters, get_allocation_id and get_retirement, in the offsetter code as they were needed for my tests.

Remarks:

I considered checking the vintage status in the confirm_offset function, but since this is already done in retire_carbon_credits, I concluded it was unnecessary.

Since the claim_for_merkle_tree function is internal to confirm_offset, we needed to determine how to call it. It is not callable by the user (or anyone other than the contract itself). Therefore, I added a from parameter representing the claimer's address to avoid issues related to calling the function, ensuring it is only invoked by the contract.

We realized when attempting to call _offset_carbon_credit that there is no mapping from allocation_id to allocation. This will need to be addressed in a future PR: adding the token_id field to the allocation struct (which will involve modifying aspects of the Merkle tree, especially the intermediate_hash in the confirm_for_merkle_tree method).

For now, in this PR, we assume that only vintages with token_id = 1 are offset, which is why we set self._offset_carbon_credit(claimee, 1, amount.into()) in confirm_offset.

-> In the confirm_offset tests, we perform the deposit and the entire process with token_id set to 1.

In confirm_offset, in the [Mark as claimed] section, would it be better to use a getter for the allocation instead of recreating one (with the exact same fields) each time?

@sBaki92 sBaki92 requested a review from tekkac November 8, 2024 10:12
Copy link
Contributor

@tekkac tekkac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look good to me, minor changes requested.

src/components/offsetter/interface.cairo Show resolved Hide resolved
src/components/offsetter/offset_handler.cairo Show resolved Hide resolved
src/components/offsetter/offset_handler.cairo Outdated Show resolved Hide resolved
tests/test_offsetter.cairo Outdated Show resolved Hide resolved
tests/test_merkle_tree.cairo Outdated Show resolved Hide resolved
@tekkac
Copy link
Contributor

tekkac commented Nov 8, 2024

In confirm_offset, in the [Mark as claimed] section, would it be better to use a getter for the allocation instead of recreating one (with the exact same fields) each time?

Yes, and probably you just need to add a claimed: bool field in Allocation

@sBaki92
Copy link
Contributor Author

sBaki92 commented Nov 11, 2024

In confirm_offset, in the [Mark as claimed] section, would it be better to use a getter for the allocation instead of recreating one (with the exact same fields) each time?

Yes, and probably you just need to add a claimed: bool field in Allocation

Could we add this field in the next PR? Because, similar to the allocation_id --> allocation mapping issue, adding a field to the allocation struct will require changes to the Merkle tree and the intermediate hashes in the confirm_for_merkle_tree method.

@tekkac tekkac self-requested a review November 12, 2024 12:29
Copy link
Contributor

@tekkac tekkac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tekkac tekkac merged commit baad7e9 into main Nov 12, 2024
2 checks passed
@tekkac tekkac deleted the add-carbon-offset-to-claim branch November 12, 2024 12:29
@julienbrs
Copy link
Collaborator

code: @all-contributors please add @sBaki92 for his first great test PR 🔥

Copy link
Contributor

@julienbrs

I've put up a pull request to add @sBaki92! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants