Skip to content

Commit aa77ca1

Browse files
committed
test: add test for verify attestation
1 parent 29d0c93 commit aa77ca1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/test/QuantumGravityBridge.t.sol

+45
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "../lib/openzeppelin/contracts/utils/cryptography/ECDSA.sol";
66
import "../Constants.sol";
77
import "../DataRootTuple.sol";
88
import "../QuantumGravityBridge.sol";
9+
import "../lib/tree/binary/BinaryMerkleProof.sol";
910

1011
import "ds-test/test.sol";
1112

@@ -93,6 +94,50 @@ contract RelayerTest is DSTest {
9394
assertEq(bridge.state_dataRootTupleRoots(nonce), newTupleRoot);
9495
}
9596

97+
function testVerifyAttestation() public {
98+
uint256 initialVelsetNonce = 0;
99+
// data root tuple root nonce.
100+
uint256 nonce = 1;
101+
// commitment to a set of roots.
102+
bytes32 newTupleRoot = 0x82dc1607d84557d3579ce602a45f5872e821c36dbda7ec926dfa17ebc8d5c013;
103+
// a data root committed to by the above tuple root.
104+
bytes32 newTuple = 0x0101010101010101010101010101010101010101010101010101010101010101;
105+
// the height of the data root.
106+
uint256 height = 1;
107+
// the binary merkle proof of the data root to the data root tuple root.
108+
bytes32[] memory sideNodes = new bytes32[](2);
109+
sideNodes[0] = 0x98ce42deef51d40269d542f5314bef2c7468d401ad5d85168bfab4c0108f75f7;
110+
sideNodes[1] = 0x575664048c9e64260eca2304d177b11d1566d0c954f1417fc76a4f9f27350063;
111+
BinaryMerkleProof memory newTupleProof;
112+
newTupleProof.sideNodes = sideNodes;
113+
newTupleProof.key = 1;
114+
newTupleProof.numLeaves = 4;
115+
116+
bytes32 newDataRootTupleRoot = domainSeparateDataRootTupleRoot(nonce, newTupleRoot);
117+
118+
// Signature for the update.
119+
Signature[] memory sigs = new Signature[](1);
120+
bytes32 digest_eip191 = ECDSA.toEthSignedMessageHash(newDataRootTupleRoot);
121+
(uint8 v, bytes32 r, bytes32 s) = cheats.sign(testPriv1, digest_eip191);
122+
sigs[0] = Signature(v, r, s);
123+
124+
Validator[] memory valSet = new Validator[](1);
125+
valSet[0] = Validator(cheats.addr(testPriv1), votingPower);
126+
127+
bridge.submitDataRootTupleRoot(nonce, initialVelsetNonce, newTupleRoot, valSet, sigs);
128+
129+
assertEq(bridge.state_eventNonce(), nonce);
130+
assertEq(bridge.state_dataRootTupleRoots(nonce), newTupleRoot);
131+
132+
DataRootTuple memory t;
133+
t.height = height;
134+
t.dataRoot = newTuple;
135+
136+
// verify that the tuple was committed to
137+
bool committedTo = bridge.verifyAttestation(1, t, newTupleProof);
138+
assertTrue(committedTo);
139+
}
140+
96141
function computeValidatorSetHash(Validator[] memory _validators) private pure returns (bytes32) {
97142
return keccak256(abi.encode(_validators));
98143
}

0 commit comments

Comments
 (0)