Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3f7947b7
Unverified
Commit
3f7947b7
authored
Oct 17, 2023
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(ctb): Add GetSigners diff test
parent
c5b6f888
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
GetSigners.t.sol
packages/contracts-bedrock/test/GetSigners.t.sol
+45
-0
No files found.
packages/contracts-bedrock/test/GetSigners.t.sol
0 → 100644
View file @
3f7947b7
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { Test } from "forge-std/Test.sol";
import { Safe } from "safe-contracts/Safe.sol";
import { GetSigners } from "src/Safe/GetSigners.sol";
import "test/safe-tools/SafeTestTools.sol";
import { SignatureDecoder } from "safe-contracts/common/SignatureDecoder.sol";
contract GetSigners_Test is Test, SafeTestTools, GetSigners {
/// @dev Test that for a given set of signatures:
/// 1. safe.checkNSignatures() succeeds
/// 2. the getSigners() method returns the expected signers
/// 3. the expected signers are all owners of the safe.
/// Demonstrating these three properties is sufficient to prove that the getSigners() method
/// returns the same signatures as those recovered by safe.checkNSignatures().
/// todo(maurelian): include tests for EIP1271 signatures, and contract signatures.
function testDiff_getSignaturesVsCheckSignatures_succeeds(uint256 _numSigs, bytes32 _digest) external {
uint256 numSigs = bound(_numSigs, 1, 100);
(, uint256[] memory keys) = makeAddrsAndKeys(numSigs);
SafeInstance memory safeInstance = SafeTestTools._setupSafe(keys, numSigs, 0);
bytes memory signatures;
for (uint256 i; i < numSigs; i++) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(keys[i], _digest);
// Safe signatures are encoded as r, s, v, not v, r, s.
signatures = bytes.concat(signatures, abi.encodePacked(r, s, v));
}
// Signature checking on the Safe should succeed.
safeInstance.safe.checkNSignatures(_digest, hex"", signatures, numSigs);
// Recover the signatures using the getSigners() method.
address[] memory gotSigners = _getNSigners(_digest, signatures);
// Compare the recovered signers to the expected signers.
assertEq(gotSigners.length, numSigs);
assertEq(gotSigners.length, safeInstance.owners.length);
for (uint256 i; i < numSigs; i++) {
assertEq(safeInstance.owners[i], gotSigners[i]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment