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 storeAttestation and mapping to AttestationCollector #75

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/contracts/contracts/AttestationCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ contract AttestationCollector is AuthManager, OwnableUpgradeable {
// [homeDomain => [updater => isUpdater]]
mapping(uint32 => mapping(address => bool)) public isUpdater;

// [nonce => attestation]
mapping(uint32 => bytes29) public attestations;

/*╔══════════════════════════════════════════════════════════════════════╗*\
▏*║ UPGRADE GAP ║*▕
\*╚══════════════════════════════════════════════════════════════════════╝*/
Expand Down Expand Up @@ -65,7 +68,7 @@ contract AttestationCollector is AuthManager, OwnableUpgradeable {

function submitAttestation(address _updater, bytes memory _attestation) external {
bytes29 _view = _checkUpdaterAuth(_updater, _attestation);
_storeAttestation(_view);
_storeAttestation(_view, _attestation);
emit AttestationSubmitted(_updater, _attestation);
}

Expand Down Expand Up @@ -98,7 +101,9 @@ contract AttestationCollector is AuthManager, OwnableUpgradeable {
}
}

function _storeAttestation(bytes29 _view) internal {
// TODO: implement storing logic for easy retrieval
function _storeAttestation(bytes29 _view, bytes memory _attestation) internal {
uint32 nonce = _view.attestationNonce();
require(attestations[nonce] == bytes29(""), "attestation already exists at nonce");
attestations[nonce] = bytes29(_attestation);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since Attestations is of type bytes29 from using Attestation for bytes29, is this conversion okay from bytes to bytes29?

}
}
18 changes: 18 additions & 0 deletions packages/contracts/test/AttestationCollector.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,22 @@ contract AttestationCollectorTest is SynapseTest {
vm.expectRevert("Signer is not an updater");
collector.submitAttestation(updater, attestation);
}

function test_storeAttestation() public {
test_addUpdater();
(bytes memory attestation, ) = signHomeAttestation(updaterPK, nonce, root);
collector.submitAttestation(updater, attestation);
assert(collector.attestations(nonce) == bytes29(attestation));
(bytes memory attestation_two, ) = signHomeAttestation(updaterPK, nonce + 1, "newroot");
collector.submitAttestation(updater, attestation_two);
assert(collector.attestations(nonce + 1) == bytes29(attestation_two));
}

function test_storeAttestation_repeatedNonce() public {
test_addUpdater();
(bytes memory attestation, ) = signHomeAttestation(updaterPK, nonce, root);
collector.submitAttestation(updater, attestation);
vm.expectRevert("attestation already exists at nonce");
collector.submitAttestation(updater, attestation);
}
}