|
2 | 2 | pragma solidity 0.8.28; |
3 | 3 |
|
4 | 4 | import {Test, console} from "forge-std/Test.sol"; |
5 | | -import {AllowList} from "../src/AllowList.sol"; |
| 5 | +import {AllowList, RegisteredTEE} from "../src/AllowList.sol"; |
| 6 | +import {QuoteParser, WorkloadId} from "../src/utils/QuoteParser.sol"; |
| 7 | +import {MockAutomataDcapAttestationFee} from "./mocks/MockAutomataDcapAttestationFee.sol"; |
6 | 8 |
|
7 | 9 | contract AllowListTest is Test { |
8 | | - AllowList public registry; |
| 10 | + AllowList public allowlist; |
| 11 | + MockAutomataDcapAttestationFee public attestationContract; |
9 | 12 |
|
10 | 13 | function setUp() public { |
11 | | - registry = new AllowList(address(this)); |
| 14 | + // deploy a fresh set of test contracts before each test |
| 15 | + attestationContract = new MockAutomataDcapAttestationFee(); |
| 16 | + allowlist = new AllowList(address(attestationContract)); |
12 | 17 | } |
13 | 18 |
|
14 | | - function test_registerTEEService() public {} |
| 19 | + function test_succesful_registerTEEService() public { |
| 20 | + attestationContract.setSuccess(true); |
| 21 | + bytes memory output = vm.readFileBinary("test/raw_tdx_quotes/bf42a348f49c9f8ab2ef750ddaffd294c45d8adf947e4d1a72158dcdbd6997c2ca7decaa1ad42648efebdfefe79cbc1b63eb2499fe2374648162fd8f5245f446/output.bin"); |
| 22 | + attestationContract.setOutput(output); |
15 | 23 |
|
16 | | - function testFuzz_registerTEEService(bytes memory _quote) public {} |
| 24 | + address expectedAddress = 0xf200f222043C5bC6c70AA6e35f5C5FDe079F3a03; |
| 25 | + uint64 expectedRegisteredAt = uint64(block.timestamp); |
| 26 | + // note: this is taken directly from the output of QuoteParser.extractWorkloadId, so it's not |
| 27 | + // a good test of the QuoteParser.extractWorkloadId function, but it's a good regression test |
| 28 | + WorkloadId expectedWorkloadId = WorkloadId.wrap(0x3db2a20cfbe18050a9996d00a94ad82346bc340a438906d04c5a1f960f31a416); |
| 29 | + |
| 30 | + bytes memory quote = vm.readFileBinary("test/raw_tdx_quotes/bf42a348f49c9f8ab2ef750ddaffd294c45d8adf947e4d1a72158dcdbd6997c2ca7decaa1ad42648efebdfefe79cbc1b63eb2499fe2374648162fd8f5245f446/quote.bin"); |
| 31 | + vm.expectEmit(address(allowlist)); |
| 32 | + emit AllowList.TEEServiceRegistered(expectedAddress, expectedWorkloadId, quote, false); |
| 33 | + allowlist.registerTEEService(quote); |
| 34 | + |
| 35 | + (uint64 registeredAt, WorkloadId workloadId, bytes memory rawQuote) = |
| 36 | + allowlist.registeredTEEs(expectedAddress); |
| 37 | + vm.assertEq(registeredAt, expectedRegisteredAt, "Registered at mismatch"); |
| 38 | + vm.assertEq(WorkloadId.unwrap(workloadId), WorkloadId.unwrap(expectedWorkloadId), "Workload ID mismatch"); |
| 39 | + vm.assertEq(rawQuote, quote, "Raw quote mismatch"); |
| 40 | + } |
| 41 | + |
| 42 | + function test_reverts_with_invalid_quote_registerTEEService() public { |
| 43 | + attestationContract.setSuccess(false); |
| 44 | + // don't bother setting the output, since it should revert before it's used |
| 45 | + |
| 46 | + vm.expectPartialRevert(AllowList.InvalidQuote.selector); // the "partial" just means we don't care about the bytes argument to InvalidQuote(bytes) |
| 47 | + bytes memory quote = vm.readFileBinary("test/raw_tdx_quotes/bf42a348f49c9f8ab2ef750ddaffd294c45d8adf947e4d1a72158dcdbd6997c2ca7decaa1ad42648efebdfefe79cbc1b63eb2499fe2374648162fd8f5245f446/quote.bin"); |
| 48 | + allowlist.registerTEEService(quote); |
| 49 | + } |
| 50 | + |
| 51 | + function testFuzz_registerTEEService(bytes memory _quote) public { /** TODO: fuzz things that are fuzzable **/} |
17 | 52 | } |
0 commit comments