Skip to content

Commit

Permalink
feat: verifying fork resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Oct 19, 2024
1 parent ab208ee commit ea3b6df
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 18 deletions.
10 changes: 3 additions & 7 deletions src/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct BlockStatus {
// memory
pub registration_timestamp: u64,
pub prev_block_digest: Digest,
pub challenged_cpow: u128,
pub pow: u128,
}

Expand All @@ -19,12 +18,7 @@ pub impl BlockStatusImpl of BlockStatusTrait {
}

fn new(prev_block_digest: Digest, pow: u128) -> BlockStatus {
BlockStatus {
prev_block_digest,
registration_timestamp: get_block_timestamp(),
challenged_cpow: 0,
pow,
}
BlockStatus { prev_block_digest, registration_timestamp: get_block_timestamp(), pow, }
}
}

Expand Down Expand Up @@ -52,4 +46,6 @@ pub trait IUtuRelay<TContractState> {
) -> bool;

fn get_status(self: @TContractState, block_hash: Digest) -> BlockStatus;

fn get_block(self: @TContractState, height: u64) -> Digest;
}
9 changes: 1 addition & 8 deletions src/tests/blocks_registration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ fn test_single_block_registration() {
prev_block_digest: hex_to_hash_rev(
"000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55"
),
challenged_cpow: 0,
pow: 4295032833,
},
'unexpected final status'
Expand Down Expand Up @@ -102,7 +101,6 @@ fn test_two_blocks_registration() {
prev_block_digest: hex_to_hash_rev(
"000000002a22cfee1f2c846adbd12b3e183d4f97683f85dad08a79780a84bd55"
),
challenged_cpow: 0,
pow: 4295032833,
},
'unexpected status for block 170'
Expand All @@ -112,10 +110,7 @@ fn test_two_blocks_registration() {
let status_171 = utu.get_status(block_171_hash);
assert(
status_171 == BlockStatus {
registration_timestamp: 1234567890,
prev_block_digest: block_170_hash,
challenged_cpow: 0,
pow: 4295032833,
registration_timestamp: 1234567890, prev_block_digest: block_170_hash, pow: 4295032833,
},
'unexpected status for block 171'
);
Expand Down Expand Up @@ -175,7 +170,6 @@ fn test_same_height_registration() {
prev_block_digest: hex_to_hash_rev(
"000000000000000000012bc4e973e18e17b9980ba5b6fe545a5f05e0e222828c"
),
challenged_cpow: 0,
pow: 395356030850084270690399,
},
'unexpected status for block 1'
Expand All @@ -189,7 +183,6 @@ fn test_same_height_registration() {
prev_block_digest: hex_to_hash_rev(
"000000000000000000012bc4e973e18e17b9980ba5b6fe545a5f05e0e222828c"
),
challenged_cpow: 0,
pow: 395356030850084270690399,
},
'unexpected status for block 2'
Expand Down
Loading

0 comments on commit ea3b6df

Please sign in to comment.